:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --border: #2f3f56;
  --text: #e8edf4;
  --muted: #8fa3bc;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  background: linear-gradient(160deg, #0b1016 0%, #121a24 45%, #0f1419 100%);
  color: var(--text);
}

.layout-wrap {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding-inline: clamp(0.85rem, 3vw, 1.5rem);
}

.app-header {
  width: 100%;
  max-width: 100vw;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 20, 25, 0.9);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 1.25rem;
}

.brand {
  min-width: 0;
  flex: 1 1 220px;
}

.brand h1 {
  margin: 0;
  font-size: clamp(1rem, 2.5vw, 1.35rem);
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.subtitle {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.logout-btn {
  white-space: nowrap;
}

.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.login-shell {
  flex: 1;
  display: grid;
  place-items: center;
  width: min(100%, 420px);
  margin-inline: auto;
  padding: 1rem;
}

.login-footer {
  width: 100%;
  padding: 1rem 1.25rem 1.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
}

.login-footer p {
  margin: 0;
  line-height: 1.45;
}

.app-update-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  padding: 0.65rem 1rem;
  background: linear-gradient(180deg, #1a3a5c 0%, #152a42 100%);
  border-bottom: 1px solid rgba(74, 144, 226, 0.35);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.app-update-banner.hidden {
  display: none;
}

.app-update-banner-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
}

.app-update-msg {
  margin: 0;
  flex: 1 1 200px;
  font-size: 0.88rem;
  line-height: 1.35;
}

.app-update-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

body:has(.app-update-banner:not(.hidden)) {
  padding-top: 3.25rem;
}

.login-card {
  width: 100%;
  padding: 1.5rem;
}

.login-brand h1 {
  margin: 0;
  font-size: 1.45rem;
  line-height: 1.2;
}

.login-title-row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.login-logo {
  display: block;
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  object-fit: contain;
}

.login-form {
  margin-top: 1.25rem;
}

.login-fields-stage {
  position: relative;
  height: 9.35rem;
}

.login-fields-stage .login-panel-section {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  transition: opacity 0.15s ease;
}

.login-fields-stage .login-panel-section.is-inactive {
  visibility: hidden;
  pointer-events: none;
  opacity: 0;
}

.login-fields-stage .field {
  margin-bottom: 0.75rem;
}

.login-fields-stage .field:last-child {
  margin-bottom: 0;
}

.login-form .login-input {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.6rem 0.75rem;
  font-size: 0.95rem;
  line-height: 1.4;
  text-align: center;
}

.login-form .btn.large {
  margin-top: 1rem;
}

.login-mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 1rem;
}

.login-mode-option {
  min-width: 0;
}

.login-mode-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.login-mode-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.5rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  font-size: 0.88rem;
  cursor: pointer;
  text-align: center;
  user-select: none;
  touch-action: manipulation;
  transition: background 0.15s, border-color 0.15s;
}

.login-mode-input:checked + .login-mode-tab,
.login-mode-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.login-form .pin-input {
  letter-spacing: 0.35em;
}

.login-hint {
  margin: 0.65rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
}

.login-error {
  margin: 0.75rem 0 0;
  color: var(--danger);
  font-size: 0.88rem;
}

.hidden,
[hidden] {
  display: none !important;
}

.login-error.hidden {
  display: none;
}

.admin-password-card {
  margin-bottom: 1rem;
}

.admin-password-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
  gap: 0.75rem;
  align-items: end;
}

.admin-password-form .field {
  margin-bottom: 0;
}

.admin-password-action span {
  visibility: hidden;
  user-select: none;
}

.admin-password-form .admin-password-btn {
  width: 100%;
  padding: 0.55rem 0.9rem;
  font-size: 0.9rem;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.admin-view-banner {
  border-bottom: 1px solid rgba(59, 130, 246, 0.35);
  background: rgba(59, 130, 246, 0.12);
}

.admin-view-banner-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding-block: 0.55rem;
  font-size: 0.88rem;
  color: #bfdbfe;
}

.admin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 900px) {
  .admin-grid {
    grid-template-columns: 1fr;
  }
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  min-width: 0;
  max-width: 100%;
}

.tab {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.55rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s, border-color 0.15s;
}

.tab:hover {
  background: var(--surface-2);
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.app-main {
  width: 100%;
  max-width: 100vw;
  padding-block: 1.25rem 2rem;
  overflow-x: hidden;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
  min-width: 0;
  max-width: 100%;
}

.panel-title-block {
  min-width: 0;
}

.panel-head h2 {
  margin: 0;
  font-size: 1.2rem;
}

.period-label {
  margin: 0.2rem 0 0;
  font-size: 0.85rem;
}

.date-range-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-end;
}

.range-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.range-field span {
  font-size: 0.75rem;
  color: var(--muted);
}

.range-preset {
  min-width: 140px;
}

.range-field-spacer {
  font-size: 0.75rem;
  line-height: 1.2;
  visibility: hidden;
  user-select: none;
}

.range-field-action .btn {
  white-space: nowrap;
}

.reports-toolbar .range-field-action {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: flex-end;
}

.product-image-preview {
  display: block;
  margin-top: 0.5rem;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
}

.category-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}

.category-card {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.category-card-media {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  background: linear-gradient(145deg, var(--surface-2), var(--bg));
  border: 1px solid var(--border);
}

.category-card-media.is-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
}

.category-card-media.is-placeholder::after {
  content: "";
  width: 38%;
  height: 38%;
  border-radius: 50%;
  background: rgba(127, 127, 127, 0.12);
}

.category-card-media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.category-card-title {
  margin: 0;
  font-size: 1rem;
  line-height: 1.25;
}

.category-card-meta {
  margin: 0;
  font-size: 0.82rem;
}

.category-upload-btn {
  margin-top: auto;
  cursor: pointer;
  text-align: center;
}

.system-health-body {
  padding: 0.25rem 0 0.5rem;
  line-height: 1.6;
  font-size: 0.9rem;
}

.apk-update-hint {
  margin: 0 0 1rem;
  font-size: 0.88rem;
}

.apk-update-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.apk-update-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  align-items: end;
}

.apk-update-wide {
  grid-column: 1 / -1;
}

.apk-update-check {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.apk-update-check input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.system-health-body .warn {
  color: var(--warn);
  font-weight: 600;
}

.reports-toolbar {
  align-items: flex-end;
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  min-width: 0;
  max-width: 100%;
}

.products-toolbar {
  flex-wrap: nowrap;
  flex: 1 1 280px;
  max-width: 420px;
  justify-content: flex-end;
}

.products-toolbar input[type="search"] {
  flex: 1;
  min-width: 0;
  max-width: none;
}

.products-toolbar .btn {
  flex-shrink: 0;
  white-space: nowrap;
}

.daily-sales-toolbar {
  flex-wrap: nowrap;
  flex: 1 1 280px;
  max-width: 420px;
  justify-content: flex-end;
}

.daily-sales-toolbar input[type="search"] {
  flex: 1;
  min-width: 0;
  max-width: none;
}

.daily-sales-toolbar .date-input {
  flex-shrink: 0;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
  width: 100%;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 0.35rem;
}

.stat-value {
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.card-head h3 {
  margin: 0;
  font-size: 1rem;
}

.table-wrap {
  overflow-x: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  text-align: left;
  padding: 0.6rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tr:last-child td {
  border-bottom: none;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 1.25rem !important;
}

.low-stock {
  color: var(--warn);
  font-weight: 600;
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.88rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn:hover {
  background: #2d3d54;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn.secondary {
  background: transparent;
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
}

.btn.small {
  padding: 0.3rem 0.55rem;
  font-size: 0.78rem;
}

.btn.large {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
}

.btn.danger {
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.4);
}

.btn.danger-solid {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn.danger-solid:hover:not(:disabled) {
  background: #dc2626;
  border-color: #dc2626;
}

.btn.pdf-export {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn.pdf-export:hover {
  background: #dc2626;
  border-color: #dc2626;
}

input,
select,
textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font-size: 0.9rem;
}

input:focus {
  outline: 2px solid rgba(59, 130, 246, 0.45);
  outline-offset: 1px;
}

input[type="search"] {
  min-width: 0;
  width: 100%;
  max-width: 220px;
}

.full-width {
  width: 100%;
}

.date-input {
  min-width: 150px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.field span {
  font-size: 0.82rem;
  color: var(--muted);
}

.category-field select,
.category-field input[type="text"] {
  width: 100%;
}

.category-field select {
  margin-bottom: 0.45rem;
}

.field-hint {
  font-size: 0.76rem;
  color: var(--muted);
  line-height: 1.35;
}

.checkout-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.reports-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  width: 100%;
  min-width: 0;
}

@media (max-width: 1100px) {
  .checkout-grid,
  .reports-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .app-header-inner {
    align-items: stretch;
  }

  .tabs {
    width: 100%;
  }

  .tab {
    flex: 1 1 auto;
    text-align: center;
  }

  .panel-actions {
    width: 100%;
  }

  .products-toolbar,
  .daily-sales-toolbar {
    max-width: 100%;
    flex-wrap: wrap;
  }

  .panel-actions input,
  .panel-actions .btn,
  .panel-actions a.btn,
  .date-range-controls input,
  .date-range-controls select {
    width: 100%;
    max-width: 100%;
  }

  .date-range-controls {
    width: 100%;
  }

  .range-field {
    flex: 1 1 100%;
  }

  th,
  td {
    padding: 0.5rem 0.35rem;
    font-size: 0.82rem;
  }
}

.product-pick-list {
  margin-top: 0.75rem;
  max-height: 420px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.pick-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.pick-item .meta {
  flex: 1;
  min-width: 0;
}

.pick-item .name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pick-item .sub {
  font-size: 0.78rem;
  color: var(--muted);
}

.cart-items {
  min-height: 180px;
  margin-bottom: 0.75rem;
}

.cart-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.cart-row:last-child {
  border-bottom: none;
}

.qty-controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.qty-controls input {
  width: 52px;
  text-align: center;
  padding: 0.35rem;
}

.cart-footer {
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}

.daily-sales-hint {
  margin: 0 0 0.75rem;
}

.daily-sales-footer {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.daily-sales-table .qty-input {
  width: 72px;
  text-align: center;
  padding: 0.35rem;
}

.row-error td {
  background: rgba(239, 68, 68, 0.08);
}

.cart-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  font-size: 1.1rem;
}

.cart-total strong {
  font-size: 1.4rem;
}

.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  background: var(--surface);
  color: var(--text);
  width: min(520px, 92vw);
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.modal form {
  padding: 1rem 1.1rem 1.1rem;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 0.75rem;
}

@media (max-width: 520px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.muted {
  color: var(--muted);
  font-size: 0.88rem;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover td {
  background: rgba(59, 130, 246, 0.08);
}

.action-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 100;
  max-width: 360px;
}

.toast.success {
  border-color: rgba(34, 197, 94, 0.5);
}

.toast.error {
  border-color: rgba(239, 68, 68, 0.5);
}

.toast.hidden {
  display: none;
}
