/* =====================================================================
   SuperMart POS -- application styles
   Layered on Bootstrap 5.3. Tokens first, then layout, then components.
   ===================================================================== */

:root {
  --sm-sidebar-w: 250px;
  --sm-sidebar-w-collapsed: 68px;
  --sm-navbar-h: 58px;

  --sm-ink:        #10172a;
  --sm-ink-soft:   #475069;
  --sm-line:       #e3e8ef;
  --sm-surface:    #ffffff;
  --sm-canvas:     #f5f7fa;

  --sm-brand:      #1d4ed8;
  --sm-brand-dark: #1e3a8a;
  --sm-accent:     #0f766e;

  --sm-side-bg:    #0f1729;
  --sm-side-bg-2:  #16203a;
  --sm-side-ink:   #94a3b8;
  --sm-side-ink-2: #f1f5f9;

  --sm-radius:     10px;
  --sm-radius-sm:  7px;
  --sm-shadow:     0 1px 2px rgba(16,23,42,.06), 0 4px 16px rgba(16,23,42,.05);
  --sm-shadow-lg:  0 10px 40px rgba(16,23,42,.14);

  --bs-body-bg: var(--sm-canvas);
  --bs-body-color: var(--sm-ink);
  --bs-border-color: var(--sm-line);
}

* { -webkit-tap-highlight-color: transparent; }

body {
  background: var(--sm-canvas);
  color: var(--sm-ink);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: .9rem;
  -webkit-font-smoothing: antialiased;
}

::selection { background: #dbeafe; }

/* Numeric columns line up when digits are tabular */
.tnum, .table td.text-end, .table th.text-end, .money, .qty {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* ---------------------------------------------------------------- brand */
.brand-mark {
  width: 40px; height: 40px; flex: 0 0 40px;
  display: grid; place-items: center;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--sm-brand) 0%, var(--sm-accent) 100%);
  color: #fff; font-size: 1.15rem;
  box-shadow: 0 4px 12px rgba(29,78,216,.28);
}

/* ---------------------------------------------------------------- shell */
.app-shell { min-height: 100vh; }

.app-sidebar {
  position: fixed; inset: 0 auto 0 0;
  width: var(--sm-sidebar-w);
  background: var(--sm-side-bg);
  display: flex; flex-direction: column;
  z-index: 1040;
  transition: transform .22s ease, width .22s ease;
}
.app-sidebar__head {
  height: var(--sm-navbar-h);
  display: flex; align-items: center; gap: .625rem;
  padding: 0 1rem;
  border-bottom: 1px solid rgba(255,255,255,.07);
  color: #fff;
}
.app-sidebar__head .name { font-weight: 700; letter-spacing: -.01em; line-height: 1.1; }
.app-sidebar__head .sub  { font-size: .68rem; color: var(--sm-side-ink); }

.app-sidebar__body { flex: 1; overflow-y: auto; padding: .75rem .625rem 1.5rem; }
.app-sidebar__body::-webkit-scrollbar { width: 6px; }
.app-sidebar__body::-webkit-scrollbar-thumb { background: rgba(255,255,255,.14); border-radius: 3px; }

.nav-section {
  color: #64748b; font-size: .66rem; font-weight: 700;
  letter-spacing: .09em; text-transform: uppercase;
  padding: 1rem .75rem .375rem;
}
.nav-link-side {
  display: flex; align-items: center; gap: .7rem;
  padding: .5rem .75rem; margin-bottom: 1px;
  border-radius: var(--sm-radius-sm);
  color: var(--sm-side-ink); text-decoration: none;
  font-size: .845rem; font-weight: 500;
  transition: background .13s, color .13s;
}
.nav-link-side i { font-size: 1.02rem; width: 19px; text-align: center; flex: 0 0 19px; }
.nav-link-side:hover { background: rgba(255,255,255,.06); color: var(--sm-side-ink-2); }
.nav-link-side.active { background: var(--sm-brand); color: #fff; box-shadow: 0 2px 10px rgba(29,78,216,.35); }
.nav-link-side .badge { margin-left: auto; }

.app-main {
  margin-left: var(--sm-sidebar-w);
  min-height: 100vh;
  display: flex; flex-direction: column;
  transition: margin .22s ease;
}

.app-navbar {
  height: var(--sm-navbar-h);
  background: var(--sm-surface);
  border-bottom: 1px solid var(--sm-line);
  display: flex; align-items: center; gap: .75rem;
  padding: 0 1.25rem;
  position: sticky; top: 0; z-index: 1030;
}

.app-content { flex: 1; padding: 1.25rem; }

@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-100%); }
  .app-sidebar.show { transform: translateX(0); box-shadow: var(--sm-shadow-lg); }
  .app-main { margin-left: 0; }
  .sidebar-backdrop {
    position: fixed; inset: 0; background: rgba(15,23,41,.5); z-index: 1035;
  }
}

/* ---------------------------------------------------------------- page head */
.page-head {
  display: flex; flex-wrap: wrap; align-items: flex-start;
  justify-content: space-between; gap: .75rem; margin-bottom: 1.125rem;
}
.page-head h1 { font-size: 1.3rem; font-weight: 700; letter-spacing: -.02em; margin: 0; }
.page-head .subtitle { color: var(--sm-ink-soft); font-size: .82rem; margin: .15rem 0 0; }

/* ---------------------------------------------------------------- cards */
.card {
  border: 1px solid var(--sm-line);
  border-radius: var(--sm-radius);
  box-shadow: var(--sm-shadow);
  background: var(--sm-surface);
}
.card-header {
  background: var(--sm-surface);
  border-bottom: 1px solid var(--sm-line);
  font-weight: 600; font-size: .875rem;
  padding: .75rem 1rem;
  display: flex; align-items: center; gap: .5rem;
  border-radius: var(--sm-radius) var(--sm-radius) 0 0 !important;
}
.card-header .card-actions { margin-left: auto; display: flex; gap: .375rem; }

/* stat tiles ------------------------------------------------------- */
.stat-tile {
  background: var(--sm-surface);
  border: 1px solid var(--sm-line);
  border-radius: var(--sm-radius);
  padding: .95rem 1.05rem;
  box-shadow: var(--sm-shadow);
  height: 100%;
  position: relative;
  overflow: hidden;
}
.stat-tile__label {
  font-size: .7rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--sm-ink-soft); margin-bottom: .3rem;
}
.stat-tile__value {
  font-size: 1.45rem; font-weight: 700; letter-spacing: -.025em;
  line-height: 1.1; font-variant-numeric: tabular-nums;
}
.stat-tile__meta { font-size: .74rem; color: var(--sm-ink-soft); margin-top: .25rem; }
.stat-tile__icon {
  position: absolute; top: .85rem; right: .95rem;
  width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center; font-size: 1rem;
}

/* ---------------------------------------------------------------- tables */
.table { --bs-table-border-color: var(--sm-line); margin-bottom: 0; }
.table > thead > tr > th {
  background: #f8fafc;
  font-size: .69rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--sm-ink-soft);
  border-bottom: 1px solid var(--sm-line);
  padding: .625rem .75rem; white-space: nowrap;
}
.table > tbody > tr > td { padding: .625rem .75rem; vertical-align: middle; }
.table-hover > tbody > tr:hover > * { background: #f8fafc; }
.table-sticky thead th { position: sticky; top: 0; z-index: 2; }

.table-linked tbody tr { cursor: pointer; }

th a.sortable { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: .25rem; }
th a.sortable:hover { color: var(--sm-brand); }

/* empty / error states --------------------------------------------- */
.state-block { text-align: center; padding: 2.75rem 1rem; color: var(--sm-ink-soft); }
.state-block i { font-size: 2.25rem; opacity: .35; display: block; margin-bottom: .625rem; }
.state-block h6 { color: var(--sm-ink); font-weight: 600; margin-bottom: .25rem; }
.state-block p { font-size: .82rem; margin-bottom: .875rem; }

/* ---------------------------------------------------------------- forms */
.form-label { font-size: .78rem; font-weight: 600; color: var(--sm-ink-soft); margin-bottom: .3rem; }
.form-control, .form-select { border-color: #d5dce6; font-size: .875rem; }
.form-control:focus, .form-select:focus {
  border-color: #93b4fd; box-shadow: 0 0 0 .2rem rgba(29,78,216,.12);
}
.form-control[readonly] { background: #f8fafc; }
.required::after { content: " *"; color: var(--bs-danger); }
.input-group-text { background: #f8fafc; border-color: #d5dce6; font-size: .82rem; }

/* ---------------------------------------------------------------- badges */
.badge { font-weight: 600; font-size: .69rem; padding: .3em .6em; letter-spacing: .01em; }
.badge-soft-success { background: #dcfce7; color: #14532d; }
.badge-soft-danger  { background: #fee2e2; color: #7f1d1d; }
.badge-soft-warning { background: #fef3c7; color: #78350f; }
.badge-soft-info    { background: #dbeafe; color: #1e3a8a; }
.badge-soft-secondary { background: #e9edf3; color: #334155; }

/* =====================================================================
   POS  --  built for speed, large targets, keyboard-first
   ===================================================================== */
.pos-body { overflow: hidden; }

.pos-shell {
  height: 100vh; display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--sm-canvas);
}

.pos-topbar {
  grid-column: 1 / -1;
  height: 54px; background: var(--sm-side-bg); color: #fff;
  display: flex; align-items: center; gap: 1rem; padding: 0 1rem;
}
.pos-topbar .pos-meta { font-size: .74rem; color: #94a3b8; }
.pos-topbar .pos-meta strong { color: #fff; font-weight: 600; }

.pos-left  { display: flex; flex-direction: column; min-width: 0; padding: .75rem; gap: .625rem; }
.pos-right { display: flex; flex-direction: column; background: var(--sm-surface);
             border-left: 1px solid var(--sm-line); min-width: 0; }

.scan-bar {
  background: var(--sm-surface); border: 1px solid var(--sm-line);
  border-radius: var(--sm-radius); padding: .625rem; box-shadow: var(--sm-shadow);
}
#barcodeInput {
  font-size: 1.3rem; font-weight: 600; height: 56px;
  letter-spacing: .06em; font-variant-numeric: tabular-nums;
  border: 2px solid var(--sm-brand); border-radius: var(--sm-radius-sm);
}
#barcodeInput:focus { box-shadow: 0 0 0 .25rem rgba(29,78,216,.16); border-color: var(--sm-brand); }
#barcodeInput.scan-ok    { border-color: #16a34a; background: #f0fdf4; }
#barcodeInput.scan-error { border-color: #dc2626; background: #fef2f2; animation: shake .3s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-5px); } 75% { transform: translateX(5px); }
}

.cart-wrap {
  flex: 1; min-height: 0; background: var(--sm-surface);
  border: 1px solid var(--sm-line); border-radius: var(--sm-radius);
  box-shadow: var(--sm-shadow); display: flex; flex-direction: column; overflow: hidden;
}
.cart-scroll { flex: 1; overflow-y: auto; }
#cartTable { font-size: .875rem; }
#cartTable thead th {
  position: sticky; top: 0; z-index: 3;
  background: #eef2f7; font-size: .68rem;
}
#cartTable tbody tr.is-active { background: #eff6ff !important; box-shadow: inset 3px 0 0 var(--sm-brand); }
#cartTable tbody tr.row-flash { animation: flash 1s ease-out; }
@keyframes flash { from { background: #fef9c3; } to { background: transparent; } }
#cartTable td { padding: .45rem .5rem; }
#cartTable .qty-input {
  width: 76px; text-align: center; font-weight: 600;
  font-variant-numeric: tabular-nums; padding: .25rem .35rem;
}
#cartTable .item-name { font-weight: 600; line-height: 1.25; }
#cartTable .item-sub  { font-size: .715rem; color: var(--sm-ink-soft); }

.totals-panel { padding: .875rem 1rem; border-top: 1px solid var(--sm-line); background: #fbfcfe; }
.totals-row {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: .875rem; padding: .225rem 0; color: var(--sm-ink-soft);
}
.totals-row span:last-child { font-variant-numeric: tabular-nums; color: var(--sm-ink); font-weight: 600; }
.totals-row.grand {
  border-top: 2px solid var(--sm-ink); margin-top: .5rem; padding-top: .625rem;
  font-size: 1.05rem; font-weight: 700; color: var(--sm-ink);
}
.totals-row.grand span:last-child { font-size: 1.7rem; font-weight: 800; letter-spacing: -.03em; }

.pos-actions { padding: .75rem 1rem 1rem; border-top: 1px solid var(--sm-line); }
.pos-actions .btn { font-weight: 600; }
.btn-pay { height: 62px; font-size: 1.15rem; font-weight: 700; letter-spacing: -.01em; }

.kbd {
  display: inline-block; padding: .08rem .34rem; font-size: .66rem; font-weight: 700;
  line-height: 1.4; color: #334155; background: #f1f5f9;
  border: 1px solid #cbd5e1; border-bottom-width: 2px; border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.btn .kbd { background: rgba(255,255,255,.75); }

.pos-empty { display: grid; place-items: center; height: 100%; color: #94a3b8; text-align: center; }
.pos-empty i { font-size: 3rem; opacity: .3; }

/* payment modal ----------------------------------------------------- */
.pay-due { font-size: 2.4rem; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.tender-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }
.tender-grid .btn { font-weight: 700; font-variant-numeric: tabular-nums; }
.method-chip {
  border: 2px solid var(--sm-line); border-radius: var(--sm-radius-sm);
  padding: .6rem .5rem; text-align: center; cursor: pointer; background: #fff;
  font-size: .8rem; font-weight: 600; transition: all .12s;
}
.method-chip:hover { border-color: #93b4fd; }
.method-chip.active { border-color: var(--sm-brand); background: #eff6ff; color: var(--sm-brand-dark); }
.method-chip i { display: block; font-size: 1.25rem; margin-bottom: .15rem; }

.search-results { max-height: 60vh; overflow-y: auto; }
.search-results .list-group-item { cursor: pointer; }
.search-results .list-group-item.active-row { background: #eff6ff; }

@media (max-width: 1199.98px) {
  .pos-shell { grid-template-columns: minmax(0,1fr) 340px; }
}
@media (max-width: 900px) {
  .pos-shell { grid-template-columns: 1fr; grid-template-rows: auto minmax(0,1fr) auto; }
  .pos-right { border-left: 0; border-top: 1px solid var(--sm-line); max-height: 46vh; }
}

/* =====================================================================
   Receipts & labels (print)
   ===================================================================== */
.receipt {
  width: 80mm; margin: 0 auto; padding: 4mm;
  font-family: "Cascadia Mono", Consolas, "Courier New", monospace;
  font-size: 11.5px; line-height: 1.42; color: #000; background: #fff;
}
.receipt.w58 { width: 58mm; font-size: 10.5px; }
.receipt h1 { font-size: 15px; text-align: center; margin: 0 0 2px; font-weight: 700; }
.receipt .center { text-align: center; }
.receipt .rule { border-top: 1px dashed #000; margin: 4px 0; }
.receipt table { width: 100%; border-collapse: collapse; }
.receipt th, .receipt td { padding: 1px 0; font-size: 11px; vertical-align: top; }
.receipt .r { text-align: right; }
.receipt .grand { font-size: 14px; font-weight: 700; }
.receipt .small { font-size: 9.5px; }

.label-sheet { display: grid; gap: 3mm; }
.label-card {
  border: 1px dashed #cbd5e1; border-radius: 3px;
  padding: 2mm; text-align: center; break-inside: avoid;
  background: #fff;
}
.label-card .l-name { font-size: 10px; font-weight: 700; line-height: 1.15; margin-bottom: 1mm;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.label-card .l-sku { font-size: 8px; color: #475069; }
.label-card img { max-width: 100%; height: auto; display: block; margin: 0 auto; }
.label-card .l-price { font-size: 13px; font-weight: 800; margin-top: .5mm; }
.label-card .l-mrp { font-size: 8px; color: #475069; text-decoration: line-through; }

@media print {
  @page { margin: 6mm; }
  body { background: #fff !important; }
  .no-print, .app-sidebar, .app-navbar, .btn, .toast-container { display: none !important; }
  .app-main { margin-left: 0 !important; }
  .app-content { padding: 0 !important; }
  .card { border: 0 !important; box-shadow: none !important; }
  .receipt { width: auto; }
  .label-card { border: 1px solid #e2e8f0; }
  a[href]::after { content: none !important; }
}

/* =====================================================================
   Utilities
   ===================================================================== */
.cursor-pointer { cursor: pointer; }
.text-tiny { font-size: .715rem; }
.fw-650 { font-weight: 650; }
.min-w-0 { min-width: 0; }
.truncate-1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.divider-y > * + * { border-top: 1px solid var(--sm-line); }
.scroll-y { overflow-y: auto; }

.spinner-overlay {
  position: fixed; inset: 0; background: rgba(255,255,255,.6);
  display: grid; place-items: center; z-index: 2000; backdrop-filter: blur(1px);
}

.toast-container { z-index: 2100; }

.avatar-circle {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--sm-brand), var(--sm-accent));
  color: #fff; display: grid; place-items: center;
  font-size: .78rem; font-weight: 700; flex: 0 0 32px;
}

.filter-bar {
  background: var(--sm-surface); border: 1px solid var(--sm-line);
  border-radius: var(--sm-radius); padding: .75rem; margin-bottom: 1rem;
  box-shadow: var(--sm-shadow);
}

.chart-box { position: relative; height: 260px; }
.chart-box canvas { max-height: 100%; }
