/* Shell Architecture — Desktop Ledger Sidebar + Mobile Thumb-Zone Bottom Bar */
.app-shell {
  display: flex;
  min-height: 100dvh;
}

.sidebar {
  display: none;
}

.mobile-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-sidebar);
  color: var(--ink-on-dark);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-emblem {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: #fffdfa;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink-on-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub {
  display: block;
  font-size: 11px;
  color: var(--ink-on-dark-muted);
  font-weight: 500;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn-dark {
  width: 40px;
  height: 40px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  color: var(--ink-on-dark);
  background: rgba(255, 255, 255, 0.08);
}

.main-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.page-content {
  flex: 1;
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px 16px calc(var(--bottom-nav-h) + 28px);
}

/* Mobile Bottom Nav */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -6px 20px rgba(28, 31, 29, 0.06);
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 52px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-secondary);
  border-radius: 10px;
}

.bottom-nav-item.active {
  color: var(--brand);
  background: var(--brand-tint);
}

.bottom-nav-item.cta-center {
  color: var(--accent);
}

/* Page Header */
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 22px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.page-kicker {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 4px;
}

.page-title {
  font-size: clamp(24px, 3vw, 32px);
  font-weight: 700;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Ledger Summary Strip (Anti-3-Card Slop: unified horizontal ruled strip) */
.ledger-strip {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
  overflow: hidden;
}

.ledger-metric {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  min-width: 0;
}

.ledger-metric:nth-child(2n) {
  border-right: none;
}
.ledger-metric:nth-last-child(-n+2) {
  border-bottom: none;
}

.metric-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.metric-value {
  font-family: var(--font-mono);
  font-size: 21px;
  font-weight: 700;
  color: var(--ink-primary);
  font-variant-numeric: tabular-nums;
}

.metric-sub {
  font-size: 12px;
  color: var(--ink-secondary);
  margin-top: 2px;
}

/* Surface Panels */
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 18px;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}

.panel-title {
  font-size: 17px;
  font-weight: 700;
}

/* Filter Toolbar */
.filter-bar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.search-wrap {
  position: relative;
}

.search-wrap svg {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-muted);
  pointer-events: none;
}

.search-wrap .input {
  padding-left: 40px;
}

/* Product List — Mobile Cards, Desktop Ruled Ledger Table */
.product-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.product-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.product-card-top {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-width: 0;
}

.prod-thumb {
  width: 60px;
  height: 60px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.prod-thumb-placeholder {
  width: 60px;
  height: 60px;
  border-radius: 10px;
  background: var(--bg-subtle);
  border: 1px dashed var(--border-strong);
  color: var(--ink-muted);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.prod-meta {
  flex: 1;
  min-width: 0;
}

.prod-name {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  color: var(--ink-primary);
  overflow-wrap: anywhere;
  margin-bottom: 4px;
}

.prod-subline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--ink-secondary);
}

.cat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.price-grid-mobile {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-paper);
  border-radius: var(--radius-md);
}

.price-cell-label {
  font-size: 11px;
  color: var(--ink-muted);
  font-weight: 600;
  text-transform: uppercase;
}

.price-cell-val {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.product-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* Desktop Ledger Table */
.table-wrap {
  display: none;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow-x: auto;
}

.ledger-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.ledger-table th {
  text-align: left;
  padding: 12px 14px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  background: var(--bg-paper);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.ledger-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.ledger-table tr:last-child td {
  border-bottom: none;
}

.ledger-table tbody tr:hover {
  background: #faf7f0;
}

.num-col {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.table-thumb {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
}

.table-thumb-placeholder {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--bg-subtle);
  color: var(--ink-muted);
  display: grid;
  place-items: center;
}

/* Full-Page Product Form (No Modals!) */
.form-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.live-profit-box {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--bg-paper);
  border: 1px solid var(--border);
  margin-top: 6px;
}

.live-profit-box.is-loss {
  background: var(--loss-bg);
  border-color: rgba(179, 50, 39, 0.35);
}

.live-profit-box.is-warn {
  background: var(--warn-bg);
  border-color: rgba(154, 91, 19, 0.3);
}

.live-profit-box.is-good {
  background: var(--profit-bg);
  border-color: rgba(27, 111, 71, 0.25);
}

.upload-zone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 18px;
  background: var(--bg-paper);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
}

.upload-preview {
  width: 100%;
  max-width: 260px;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-surface);
}

.sticky-form-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 18px;
  margin-top: 18px;
  border-top: 1px solid var(--border);
}

/* Segmented Controls (for Bulk Update) */
.seg-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.seg-option {
  flex: 1 1 110px;
  position: relative;
}

.seg-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.seg-option span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap-min);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.seg-option input:checked + span {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--ink-on-dark);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 44px 20px;
  background: var(--bg-surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
}

.empty-state h3 {
  font-size: 19px;
  margin: 12px 0 6px;
}

.empty-state p {
  color: var(--ink-secondary);
  margin: 0 auto 18px;
  max-width: 42ch;
}

/* Login Page — Asymmetric Split */
.login-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1fr;
  background: var(--bg-paper);
}

.login-editorial {
  background: var(--bg-sidebar);
  color: var(--ink-on-dark);
  padding: 36px 24px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 28px;
}

.login-editorial h1 {
  color: var(--ink-on-dark);
  font-size: clamp(28px, 4vw, 44px);
  max-width: 16ch;
}

.login-editorial p {
  color: var(--ink-on-dark-muted);
  max-width: 44ch;
  margin: 12px 0 0;
}

.login-points {
  display: grid;
  gap: 10px;
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 13.5px;
  color: var(--ink-on-dark-muted);
}

.login-form-pane {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  box-shadow: var(--shadow-md);
}

/* Tablet (>= 768px) */
@media (min-width: 768px) {
  .page-content {
    padding: 24px 24px calc(var(--bottom-nav-h) + 28px);
  }

  .ledger-strip {
    grid-template-columns: repeat(4, 1fr);
  }

  .ledger-metric {
    border-bottom: none;
    border-right: 1px solid var(--border);
  }
  .ledger-metric:nth-child(2n) {
    border-right: 1px solid var(--border);
  }
  .ledger-metric:last-child {
    border-right: none;
  }

  .filter-bar {
    grid-template-columns: 2fr 1fr 1fr 1fr;
    align-items: end;
  }

  .form-grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }

  .product-cards {
    display: none;
  }

  .table-wrap {
    display: block;
  }

  .login-shell {
    grid-template-columns: 1.1fr 1fr;
  }

  .login-editorial {
    padding: 56px 48px;
  }
}

/* Desktop (>= 1024px) */
@media (min-width: 1024px) {
  .mobile-topbar,
  .bottom-nav {
    display: none;
  }

  .sidebar {
    position: sticky;
    top: 0;
    height: 100dvh;
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--bg-sidebar);
    color: var(--ink-on-dark);
    display: flex;
    flex-direction: column;
    padding: 22px 14px;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
  }

  .sidebar-brand {
    padding: 4px 10px 22px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 16px;
  }

  .sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
  }

  .sidebar-link {
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 44px;
    padding: 0 12px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    color: var(--ink-on-dark-muted);
    transition: background-color 0.15s ease, color 0.15s ease;
  }

  .sidebar-link:hover {
    background: var(--bg-sidebar-hover);
    color: var(--ink-on-dark);
  }

  .sidebar-link.active {
    background: var(--bg-sidebar-active);
    color: #fffdfa;
    font-weight: 600;
  }

  .sidebar-cta {
    margin: 12px 0 8px;
    background: var(--accent);
    color: #fffdfa;
    font-weight: 600;
  }

  .sidebar-cta:hover {
    background: var(--accent-hover);
    color: #fffdfa;
  }

  .sidebar-foot {
    padding-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .sidebar-user {
    padding: 6px 12px 10px;
    font-size: 12.5px;
    color: var(--ink-on-dark-muted);
  }

  .sidebar-user strong {
    display: block;
    color: var(--ink-on-dark);
    font-size: 13.5px;
  }

  .page-content {
    padding: 28px 34px 48px;
  }

  .form-layout {
    grid-template-columns: 1.5fr 0.9fr;
    align-items: start;
  }
}

/* Report Filter Grid */
.report-filters-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 640px) {
  .report-filters-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .report-filters-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.range-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* Always-visible table on reports/bulk preview even on mobile via horizontal container */
.table-wrap-always {
  display: block;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow-x: auto;
}
