/* ============================================================
   layout.css — Grid system, page flexboxes, sidebar structure
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-size: 14px;
}

img { max-width: 100%; display: block; }

/* ============ App Shell ============ */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

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

.page-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
}

/* ============ Sidebar ============ */
.sidebar {
  width: 92px;
  flex-shrink: 0;
  background: var(--grad-clay);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  overflow-y: auto;
}

.brand {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: var(--grad-indigo);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 14px;
  box-shadow: var(--shadow-indigo-outset);
  margin-bottom: 10px;
}

.nav-pill {
  width: 100%;
  padding: 12px 6px;
  border: none;
  background: transparent;
  border-radius: var(--r-md);
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--ease);
  text-decoration: none;
}

.nav-pill svg {
  width: 22px;
  height: 22px;
  stroke-width: 1.8;
}

.nav-pill:hover {
  color: var(--accent-indigo);
  transform: translateY(-1px);
}

.nav-pill.active {
  background: var(--grad-clay);
  color: var(--accent-indigo);
  box-shadow: var(--shadow-clay-inset);
}

.nav-pill.logout {
  margin-top: auto;
  color: var(--accent-red);
}

.nav-pill.logout:hover { color: var(--accent-red-deep); }

/* ============ Header ============ */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 22px;
  background: var(--grad-clay);
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
  box-shadow: 0 4px 14px rgba(166, 180, 200, 0.25);
  position: relative;
  z-index: 5;
}

.topbar-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.topbar-title small {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.topbar-spacer { flex: 1; }

.operator-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px 6px 6px;
  border-radius: var(--r-pill);
  background: var(--grad-clay);
  box-shadow: var(--shadow-clay-soft);
  font-size: 12px;
  font-weight: 600;
}

.operator-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--grad-indigo);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
}

/* ============ Cashier Split Layout ============ */
.cashier-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 35%;
  gap: 20px;
  max-width: 1680px;
  margin: 0 auto;
  width: 100%;
}

/* ============ Generic Panels ============ */
.panel {
  background: var(--grad-clay);
  border: var(--hairline);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-clay-outset);
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.panel--inset {
  background: var(--bg-base-2);
  border-color: rgba(148, 163, 184, 0.18);
  box-shadow: var(--shadow-clay-inset);
}

/* ============ Product Grid ============ */
.products-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

.search-wrap .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  pointer-events: none;
  width: 18px;
  height: 18px;
}

.category-chips {
  display: flex;
  gap: 8px;
  padding: 10px 18px 14px;
  flex-wrap: wrap;
}

.chip {
  padding: 7px 16px;
  border-radius: var(--r-pill);
  background: var(--grad-clay);
  border: var(--hairline);
  box-shadow: var(--shadow-clay-soft);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--ease);
  white-space: nowrap;
}

.chip:hover { transform: translateY(-1px); }

.chip.active {
  background: var(--grad-indigo);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.18);
  box-shadow: var(--shadow-indigo-outset);
}

.products-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 18px 20px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 18px;
  align-content: start;
}

/* ============ Cart Panel ============ */
.cart-panel {
  min-height: 0;
}

.cart-header {
  padding: 16px 18px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.cart-header h2 {
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.order-ref {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--grad-clay);
  padding: 4px 10px;
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-clay-soft);
}

.cart-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cart-empty {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--text-faint);
  text-align: center;
  font-size: 13px;
  gap: 8px;
}

.cart-footer {
  padding: 14px 18px 18px;
  border-top: 1px solid rgba(148, 163, 184, 0.12);
}

.totals-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  font-size: 13px;
  color: var(--text-muted);
}

.totals-row.grand {
  font-size: 20px;
  font-weight: 800;
  color: var(--accent-green-deep);
  padding: 10px 0 6px;
}

.discount-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

/* ============ Data Tables (Inventory / Reports) ============ */
.table-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.table-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  flex-wrap: wrap;
}

.table-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 18px 18px;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 8px;
  font-size: 13px;
}

.data-table thead th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  padding: 6px 14px;
  font-weight: 700;
}

.data-table tbody tr {
  background: var(--grad-clay);
  border: var(--hairline);
  box-shadow: var(--shadow-clay-soft);
  border-radius: var(--r-md);
  transition: var(--ease);
}

.data-table tbody tr:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-clay-outset);
}

.data-table td {
  padding: 12px 14px;
  vertical-align: middle;
}

.data-table tbody tr td:first-child {
  border-top-left-radius: var(--r-md);
  border-bottom-left-radius: var(--r-md);
}

.data-table tbody tr td:last-child {
  border-top-right-radius: var(--r-md);
  border-bottom-right-radius: var(--r-md);
}

/* ============ Metric Cards ============ */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.metric-card {
  padding: 18px 20px;
  border: var(--hairline);
  border-radius: var(--r-lg);
  background: var(--grad-clay);
  box-shadow: var(--shadow-clay-outset);
  transition: var(--ease);
}

.metric-card:hover { transform: translateY(-2px); }

.metric-card .metric-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.metric-card .metric-value {
  font-size: 28px;
  font-weight: 700;
  margin-top: 8px;
  letter-spacing: -0.02em;
}

.metric-card .metric-sub {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 4px;
}

/* ============ Split content stacks ============ */
.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  flex: 1;
}

.row-wrap {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

/* ============================================================
   Desktop: keep tall pages scrollable.
   Stack-based pages (reports, profile, tables) scroll internally
   so the topbar/sidebar stay fixed; the cashier grid hugs the
   full height so only the product grid and cart body scroll.
   ============================================================ */
@media (min-width: 769px) {
  .stack { overflow-y: auto; }
  .cashier-layout { grid-template-rows: minmax(0, 1fr); }
}

/* ============================================================
   Responsive — mobile-first refinements
   ============================================================ */

@media (max-width: 1200px) {
  .cashier-layout {
    grid-template-columns: 1fr 40%;
  }
}

@media (max-width: 980px) {
  .cashier-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }
  .cart-panel { max-height: 44vh; }
  .cart-panel .cart-body { min-height: 120px; }
}

@media (max-width: 768px) {
  body { overflow: auto; }
  .app-shell {
    height: auto;
    min-height: 100vh;
    flex-direction: column;
  }

  /* Sidebar becomes a fixed bottom tab bar */
  .sidebar {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 62px;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    border-top: var(--hairline);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -6px 18px rgba(30, 41, 59, 0.14);
    z-index: 60;
    overflow-x: auto;
  }
  .brand { display: none; }
  .nav-pill {
    padding: 6px 8px;
    gap: 3px;
    font-size: 9px;
    border-radius: 14px;
  }
  .nav-pill svg { width: 20px; height: 20px; }
  .nav-pill.logout { margin-top: 0; }

  .app-main { padding-bottom: 62px; }

  .topbar { padding: 12px 14px; gap: 10px; }
  .topbar-title { font-size: 16px; }
  .topbar-title small { display: none; }
  .operator-chip { padding: 4px 10px 4px 4px; }
  .operator-avatar { width: 28px; height: 28px; font-size: 11px; }

  .page-content { padding: 14px; }

  .cashier-layout {
    grid-template-rows: auto auto;
    gap: 14px;
  }
  .cart-panel { max-height: none; height: auto; }
  .cart-body { max-height: 46vh; }

  .products-toolbar { flex-wrap: wrap; padding: 12px; }
  .search-wrap { flex: 1 1 100%; }

  .products-grid {
    grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
    gap: 12px;
    padding: 8px 12px 14px;
  }

  .table-toolbar { padding: 12px; }
  .table-scroll { padding: 4px 12px 14px; }

  .action-grid { grid-template-columns: 1fr 1fr; }
  .action-grid .btn--green { grid-column: span 2; }

  .metrics-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
  .metric-card .metric-value { font-size: 22px; }
}

@media (max-width: 480px) {
  .products-grid { grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); }

  .modal { padding: 18px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }

  .data-table { min-width: 640px; }
  .table-scroll { overflow-x: auto; overflow-y: auto; }

  .reports-grid { grid-template-columns: 1fr !important; }
}

@media (max-width: 640px) {
  .table-panel .table-toolbar { flex-wrap: wrap; }
  .table-toolbar .grow { display: none; }
}

