/* ==========================================================================
   STEDCAD POS — application stylesheet
   Flat, enterprise, mobile-first. Royal Blue #4169E1 accent.
   No framework, no build step.
   ========================================================================== */

:root {
  --brand:        #4169E1;
  --brand-dark:   #2f4fc4;
  --brand-light:  #eaefff;
  --brand-tint:   #f4f7ff;

  --ink:          #16192b;
  --ink-2:        #3b415c;
  --muted:        #7b8199;
  --line:         #e4e8f2;
  --line-soft:    #eef1f8;
  --bg:           #f6f8fc;
  --surface:      #ffffff;

  --success:      #12a370;
  --success-bg:   #e6f7f0;
  --warning:      #d98600;
  --warning-bg:   #fff5e3;
  --danger:       #d93a4a;
  --danger-bg:    #fdeaec;
  --info:         #4169E1;
  --info-bg:      #eaefff;

  --r-sm: 8px;
  --r:    12px;
  --r-lg: 18px;
  --shadow:    0 1px 2px rgba(22,25,43,.05), 0 4px 16px rgba(22,25,43,.05);
  --shadow-lg: 0 8px 40px rgba(22,25,43,.14);

  --sidebar-w: 248px;
  --topbar-h:  64px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}

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

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.3rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p  { margin: 0 0 1em; }
a  { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted     { color: var(--muted); }
.small     { font-size: .82rem; }
.tiny      { font-size: .74rem; }
.strong    { font-weight: 650; }
.mono      { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num       { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.nowrap    { white-space: nowrap; }
.center    { text-align: center; }
.right     { text-align: right; }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger);  }
.text-warning { color: var(--warning); }
.text-brand   { color: var(--brand);   }
.hidden, [hidden] { display: none !important; }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 999;
  background: var(--brand); color: #fff; padding: 10px 16px; border-radius: 0 0 var(--r) 0;
}
.skip-link:focus { left: 0; }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }

.icon { flex: none; vertical-align: middle; }

/* ---------------------------------------------------------------- shell -- */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 60;
  width: var(--sidebar-w);
  display: flex; flex-direction: column;
  background: #fff; border-right: 1px solid var(--line);
  transform: translateX(-100%);
  transition: transform .22s ease;
}
.sidebar.is-open { transform: none; }

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  height: var(--topbar-h); padding: 0 16px;
  border-bottom: 1px solid var(--line-soft);
}
.brand-mark {
  width: 34px; height: 34px; flex: none; border-radius: 9px;
  background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 17px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-size: .95rem; letter-spacing: .04em; }
.brand-text small  { color: var(--muted); font-size: .7rem; letter-spacing: .04em; }
.sidebar-close { margin-left: auto; background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--r-sm);
  color: var(--ink-2); font-weight: 500; font-size: .9rem;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--brand-tint); color: var(--brand); text-decoration: none; }
.nav-link.is-active { background: var(--brand); color: #fff; }
.nav-link.is-active:hover { background: var(--brand-dark); color: #fff; }
.nav-badge {
  margin-left: auto; font-style: normal; font-size: .68rem; font-weight: 700;
  background: var(--danger); color: #fff; border-radius: 20px; padding: 2px 7px; min-width: 20px; text-align: center;
}
.nav-link.is-active .nav-badge { background: rgba(255,255,255,.28); }

.sidebar-foot { padding: 12px; border-top: 1px solid var(--line-soft); }
.sidebar-user { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.avatar {
  width: 34px; height: 34px; flex: none; border-radius: 50%;
  background: var(--brand-light); color: var(--brand);
  display: grid; place-items: center; font-weight: 700;
}
.who { display: flex; flex-direction: column; min-width: 0; }
.who strong { font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who small  { color: var(--muted); font-size: .7rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logout-form { margin: 0; }
.build { margin: 8px 0 0; text-align: center; font-size: .68rem; color: var(--muted); }

.sidebar-scrim { position: fixed; inset: 0; background: rgba(16,20,40,.45); z-index: 55; }

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

.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h); display: flex; align-items: center; gap: 12px;
  padding: 0 14px; background: rgba(255,255,255,.92); backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { min-width: 0; flex: 1; }
.topbar-title h1 { margin: 0; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title p  { margin: 0; font-size: .76rem; color: var(--muted); }
.topbar-tools { display: flex; align-items: center; gap: 10px; }

.quick-search {
  display: none; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 30px;
  padding: 6px 14px; color: var(--muted);
}
.quick-search input { border: 0; background: none; outline: 0; font: inherit; font-size: .85rem; width: 190px; color: var(--ink); }

.chip {
  font-size: .72rem; font-weight: 650; letter-spacing: .03em;
  background: var(--brand-light); color: var(--brand);
  padding: 5px 11px; border-radius: 30px; white-space: nowrap;
}
.chip-currency { background: var(--ink); color: #fff; }

.icon-btn {
  display: grid; place-items: center; width: 38px; height: 38px;
  border: 1px solid var(--line); background: #fff; border-radius: var(--r-sm);
  color: var(--ink-2); cursor: pointer;
}
.icon-btn:hover { background: var(--brand-tint); color: var(--brand); }

.page-actions {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 12px 14px 0;
}
.page-actions .spacer { flex: 1; }

.page { flex: 1; padding: 14px; max-width: 1400px; width: 100%; }
.page-wide { max-width: none; }

.app-footer {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between;
  padding: 16px 18px; font-size: .74rem; color: var(--muted);
  border-top: 1px solid var(--line);
}

.only-desktop { display: none; }

/* ---------------------------------------------------------------- cards -- */

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 14px;
}
.card-tight { padding: 0; overflow: hidden; }
.card-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 16px 18px; border-bottom: 1px solid var(--line-soft);
}
.card-head h2, .card-head h3 { margin: 0; }
.card-head .spacer { flex: 1; }
.card-body { padding: 18px; }
.card-foot { padding: 14px 18px; border-top: 1px solid var(--line-soft); background: var(--brand-tint); }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: 1fr; }
.grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }

/* KPI cards */
.kpi {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 16px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--brand); }
.kpi.kpi-success::after { background: var(--success); }
.kpi.kpi-warning::after { background: var(--warning); }
.kpi.kpi-danger::after  { background: var(--danger); }
.kpi-label { display: flex; align-items: center; gap: 7px; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; }
.kpi-value { font-size: 1.55rem; font-weight: 700; letter-spacing: -.02em; margin: 8px 0 2px; font-variant-numeric: tabular-nums; }
.kpi-sub   { font-size: .76rem; color: var(--muted); }

/* --------------------------------------------------------------- forms --- */

.field { margin-bottom: 14px; }
.field > label, .label {
  display: block; font-size: .78rem; font-weight: 650; color: var(--ink-2);
  margin-bottom: 6px; letter-spacing: .01em;
}
.field .hint { font-size: .74rem; color: var(--muted); margin-top: 5px; }
.req { color: var(--danger); }

input[type=text], input[type=password], input[type=email], input[type=number],
input[type=date], input[type=datetime-local], input[type=search], input[type=tel],
input[type=url], select, textarea {
  width: 100%; padding: 10px 12px; font: inherit; font-size: .9rem;
  color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: 0; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(65,105,225,.14);
}
input[readonly], input:disabled, select:disabled, textarea:disabled {
  background: var(--bg); color: var(--muted); cursor: not-allowed;
}
textarea { min-height: 84px; resize: vertical; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%237b8199' stroke-width='1.8' d='M1 1.5 6 6.5l5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px;
}
.form-row { display: grid; gap: 0 14px; grid-template-columns: 1fr; }
.form-row-2 { grid-template-columns: 1fr; }
.form-row-3 { grid-template-columns: 1fr; }
.form-row-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }

.check { display: flex; align-items: flex-start; gap: 9px; font-size: .88rem; margin-bottom: 10px; cursor: pointer; }
.check input { width: 17px; height: 17px; margin: 1px 0 0; accent-color: var(--brand); flex: none; }

.input-group { display: flex; }
.input-group > :first-child { border-radius: var(--r-sm) 0 0 var(--r-sm); }
.input-group > :last-child  { border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.input-group > * + * { margin-left: -1px; }
.input-group .addon {
  display: grid; place-items: center; padding: 0 12px; font-size: .82rem; font-weight: 600;
  background: var(--bg); border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.input-group select { flex: none; width: auto; min-width: 96px; }

fieldset { border: 1px solid var(--line); border-radius: var(--r); padding: 16px; margin: 0 0 16px; }
legend { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--brand); padding: 0 6px; }

/* -------------------------------------------------------------- buttons -- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px; font: inherit; font-size: .87rem; font-weight: 600;
  border: 1px solid transparent; border-radius: var(--r-sm);
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .15s, border-color .15s, color .15s, transform .06s;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[disabled] { opacity: .55; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); color: #fff; }
.btn-ghost { background: #fff; color: var(--ink-2); border-color: var(--line); }
.btn-ghost:hover { background: var(--brand-tint); color: var(--brand); border-color: var(--brand); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #bf2f3e; color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #0d8a5e; color: #fff; }
.btn-soft { background: var(--brand-light); color: var(--brand); }
.btn-soft:hover { background: #dde5ff; }
.btn-sm { padding: 6px 10px; font-size: .78rem; gap: 5px; }
.btn-lg { padding: 14px 22px; font-size: 1rem; border-radius: var(--r); }
.btn-block { width: 100%; }
.btn-icon { padding: 7px; }

.btn-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }

/* --------------------------------------------------------------- tables -- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table.data { width: 100%; border-collapse: collapse; font-size: .87rem; }
table.data th, table.data td { padding: 11px 13px; text-align: left; vertical-align: middle; }
table.data thead th {
  background: var(--brand-tint); color: var(--ink-2);
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 700;
  border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
table.data tbody tr { border-bottom: 1px solid var(--line-soft); }
table.data tbody tr:last-child { border-bottom: 0; }
table.data tbody tr:hover { background: var(--brand-tint); }
table.data tfoot td { border-top: 2px solid var(--line); font-weight: 700; background: var(--brand-tint); }
table.data td.actions { white-space: nowrap; text-align: right; }
table.data .sub { display: block; font-size: .74rem; color: var(--muted); }
table.data.compact th, table.data.compact td { padding: 7px 10px; font-size: .82rem; }
tr.is-void td { opacity: .55; text-decoration: line-through; }
tr.row-danger  { background: var(--danger-bg); }
tr.row-warning { background: var(--warning-bg); }

.badge {
  display: inline-block; font-size: .7rem; font-weight: 700; letter-spacing: .03em;
  padding: 3px 9px; border-radius: 20px; white-space: nowrap;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger);  }
.badge-info    { background: var(--info-bg);    color: var(--info);    }
.badge-muted   { background: #eef0f6;           color: var(--muted);   }

.pager {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-top: 1px solid var(--line-soft); font-size: .82rem;
}
.pager-links { display: flex; gap: 4px; flex-wrap: wrap; }
.pager-links a, .pager-links span {
  padding: 5px 11px; border-radius: var(--r-sm); border: 1px solid var(--line); color: var(--ink-2);
}
.pager-links a:hover { background: var(--brand-tint); color: var(--brand); text-decoration: none; }
.pager-links .is-current { background: var(--brand); color: #fff; border-color: var(--brand); }

.filters {
  display: grid; gap: 10px; grid-template-columns: 1fr;
  padding: 14px 16px; background: var(--brand-tint); border-bottom: 1px solid var(--line);
}
.filters .field { margin: 0; }
.filters-actions { display: flex; gap: 8px; align-items: flex-end; }

.empty-state { padding: 46px 20px; text-align: center; color: var(--muted); }
.empty-state svg { color: var(--line); margin-bottom: 10px; }
.empty-state h3 { color: var(--ink-2); margin-bottom: 4px; }

/* --------------------------------------------------------------- toasts -- */

.toast-stack { position: fixed; top: 76px; right: 14px; z-index: 90; display: flex; flex-direction: column; gap: 8px; max-width: min(400px, calc(100vw - 28px)); }
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; border-radius: var(--r); background: #fff; box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--brand); font-size: .87rem; animation: toastIn .25s ease;
}
.toast-success { border-left-color: var(--success); }
.toast-error   { border-left-color: var(--danger);  }
.toast-warning { border-left-color: var(--warning); }
.toast-x { margin-left: auto; background: none; border: 0; font-size: 20px; line-height: 1; color: var(--muted); cursor: pointer; }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } }

/* --------------------------------------------------------------- modals -- */

.modal-host { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(16,20,40,.5); }
.modal {
  position: relative; background: #fff; border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  padding: 22px; width: min(560px, 100%); max-height: 90vh; overflow-y: auto;
}
.modal-lg { width: min(880px, 100%); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }

/* ------------------------------------------------------------------ POS -- */

/* minmax(0,1fr) — not 1fr — or the grid item's automatic min-width lets the
   filter-chip row blow the column out past the viewport on a phone. */
.pos-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-items: start; }
.pos-layout > * { min-width: 0; }

.pos-search { display: flex; gap: 8px; margin-bottom: 12px; }
.pos-search input { font-size: 1rem; padding: 12px 14px; }

.pos-filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 10px; }
.pos-filters button {
  flex: none; padding: 7px 13px; font: inherit; font-size: .8rem; font-weight: 600;
  background: #fff; border: 1px solid var(--line); border-radius: 30px; color: var(--ink-2); cursor: pointer;
}
.pos-filters button.is-active { background: var(--brand); color: #fff; border-color: var(--brand); }

.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 10px; }
.tile {
  display: flex; flex-direction: column; gap: 4px; text-align: left;
  padding: 12px; background: #fff; border: 1px solid var(--line); border-radius: var(--r);
  cursor: pointer; font: inherit; transition: border-color .15s, box-shadow .15s, transform .06s;
  min-height: 108px;
}
.tile:hover { border-color: var(--brand); box-shadow: var(--shadow); }
.tile:active { transform: scale(.985); }
.tile:disabled { opacity: .5; cursor: not-allowed; }
.tile .t-name { font-weight: 650; font-size: .84rem; line-height: 1.3; }
.tile .t-meta { font-size: .7rem; color: var(--muted); }
.tile .t-price { margin-top: auto; font-weight: 700; color: var(--brand); font-size: .95rem; }
.tile .t-stock { font-size: .68rem; font-weight: 700; }
.tile .t-stock.ok   { color: var(--success); }
.tile .t-stock.low  { color: var(--warning); }
.tile .t-stock.none { color: var(--danger); }

.cart-panel {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden;
}
.cart-head { padding: 14px 16px; border-bottom: 1px solid var(--line-soft); display: flex; align-items: center; gap: 8px; }
.cart-items { max-height: 42vh; overflow-y: auto; }
.cart-row { padding: 10px 14px; border-bottom: 1px solid var(--line-soft); }
.cart-row .cr-top { display: flex; gap: 8px; align-items: flex-start; }
.cart-row .cr-name { font-weight: 620; font-size: .85rem; flex: 1; }
.cart-row .cr-x { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px; }
.cart-row .cr-x:hover { color: var(--danger); }
.cart-row .cr-line { display: flex; gap: 6px; align-items: center; margin-top: 7px; flex-wrap: wrap; }
.cart-row input { padding: 6px 8px; font-size: .82rem; }
.qty-stepper { display: flex; align-items: center; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.qty-stepper button { width: 32px; height: 32px; border: 0; background: var(--bg); font-size: 17px; cursor: pointer; color: var(--ink-2); }
.qty-stepper button:hover { background: var(--brand-light); color: var(--brand); }
.qty-stepper input { width: 52px; border: 0; text-align: center; padding: 6px 2px; }
.cr-sub { margin-left: auto; font-weight: 700; font-size: .87rem; font-variant-numeric: tabular-nums; }
.cr-batch { font-size: .68rem; color: var(--muted); margin-top: 4px; display: block; }
.cr-batch select { font-size: .7rem; padding: 4px 22px 4px 6px; margin-top: 3px; }

.totals { padding: 12px 16px; border-top: 1px solid var(--line); background: var(--brand-tint); }
.totals .t-row { display: flex; justify-content: space-between; font-size: .85rem; padding: 3px 0; }
.totals .t-row.grand { font-size: 1.2rem; font-weight: 750; border-top: 1px dashed var(--line); margin-top: 7px; padding-top: 9px; color: var(--brand); }

/* -------------------------------------------------------------- charts --- */

.chart-card { background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px; box-shadow: var(--shadow); }
.chart-card h3 { font-size: .92rem; margin-bottom: 12px; }
.chart-box { position: relative; height: 280px; }
.chart-box canvas { max-width: 100%; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; font-size: .76rem; }
.chart-legend span { display: flex; align-items: center; gap: 6px; }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* Hand-rolled horizontal bar (aging, top products) */
.bar-list { display: flex; flex-direction: column; gap: 10px; }
.bar-item .bar-label { display: flex; justify-content: space-between; font-size: .8rem; margin-bottom: 4px; gap: 10px; }
.bar-track { height: 9px; background: var(--line-soft); border-radius: 20px; overflow: hidden; }
.bar-fill  { height: 100%; background: var(--brand); border-radius: 20px; transition: width .5s ease; }
.bar-fill.warning { background: var(--warning); }
.bar-fill.danger  { background: var(--danger);  }
.bar-fill.success { background: var(--success); }

/* --------------------------------------------------------------- misc ---- */

.stat-strip { display: flex; flex-wrap: wrap; gap: 18px; padding: 14px 18px; background: var(--brand-tint); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 14px; }
.stat-strip div { min-width: 130px; }
.stat-strip .s-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; }
.stat-strip .s-value { font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs a {
  padding: 10px 15px; font-size: .86rem; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs a:hover { color: var(--brand); text-decoration: none; }
.tabs a.is-active { color: var(--brand); border-bottom-color: var(--brand); }

.alert {
  display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--r);
  font-size: .86rem; margin-bottom: 14px; border: 1px solid transparent;
}
.alert-info    { background: var(--info-bg);    border-color: #cdd9ff; color: #24387d; }
.alert-warning { background: var(--warning-bg); border-color: #f3ddb0; color: #8a5600; }
.alert-danger  { background: var(--danger-bg);  border-color: #f5c3c8; color: #91202e; }
.alert-success { background: var(--success-bg); border-color: #b6e6d2; color: #0a6b48; }

.kv { display: grid; grid-template-columns: 1fr; gap: 2px 16px; font-size: .87rem; }
.kv dt { color: var(--muted); font-size: .76rem; }
.kv dd { margin: 0 0 9px; font-weight: 600; }

.doc-head { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 18px; }

.spinner {
  width: 18px; height: 18px; border: 2px solid var(--brand-light); border-top-color: var(--brand);
  border-radius: 50%; animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.list-reset { list-style: none; margin: 0; padding: 0; }

.split-payments { display: flex; flex-direction: column; gap: 8px; }
.split-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; align-items: center; }

/* ---------------------------------------------------------- responsive --- */

@media (min-width: 560px) {
  .grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .form-row-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .form-row-3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .kv { grid-template-columns: auto 1fr; }
  .kv dt { padding-top: 2px; }
}

@media (min-width: 860px) {
  body { font-size: 15px; }
  .grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
  .form-row-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .form-row-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
  .filters { grid-template-columns: repeat(4, minmax(0,1fr)); align-items: end; }
  .quick-search { display: flex; }
  .page { padding: 18px; }
  .page-actions { padding: 16px 18px 0; }
}

@media (min-width: 1024px) {
  .sidebar { transform: none; }
  .sidebar-close, .sidebar-scrim { display: none !important; }
  .app-main { margin-left: var(--sidebar-w); }
  .only-mobile { display: none; }
  .only-desktop { display: inline-block; }
  .pos-layout { grid-template-columns: minmax(0,1fr) 380px; }
  .cart-panel { position: sticky; top: calc(var(--topbar-h) + 14px); max-height: calc(100vh - var(--topbar-h) - 28px); }
  .cart-items { max-height: none; flex: 1; }
}

@media (min-width: 1280px) {
  .pos-layout { grid-template-columns: minmax(0,1fr) 420px; }
}

/* ------------------------------------------------- POS on phones ------- */
/*
   On a phone the catalogue fills the screen and the cart becomes a bottom
   sheet: a permanently visible summary bar (item count, running total and a
   Checkout button) that slides up into the full cart when tapped. Without
   this the cashier has to scroll past every product tile to reach the total.
*/

.cart-peek { display: none; }

@media (max-width: 1023px) {

  .pos-page { --peek-h: 68px; }

  /* Never let the fixed bar cover the last row of tiles. */
  .pos-page .page { padding-bottom: calc(var(--peek-h) + env(safe-area-inset-bottom, 0px) + 20px); }
  .pos-page .pos-layout { gap: 0; }

  /* ---- the sheet ---- */
  .pos-page .cart-panel {
    position: fixed; z-index: 70;
    left: 0; right: 0; bottom: 0;
    height: min(86vh, 660px);
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    border-width: 1px 0 0;
    box-shadow: 0 -6px 30px rgba(16, 20, 40, .18);
    transform: translateY(calc(100% - var(--peek-h)));
    transition: transform .26s cubic-bezier(.32, .72, 0, 1);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .pos-page .cart-panel.is-open { transform: none; }

  /* Users who prefer less motion still get the state change, just instantly. */
  @media (prefers-reduced-motion: reduce) {
    .pos-page .cart-panel { transition: none; }
  }

  .cart-scrim { position: fixed; inset: 0; z-index: 65; background: rgba(16, 20, 40, .45); }

  /* ---- the always-visible summary bar ---- */
  .cart-peek {
    display: flex; align-items: center; gap: 8px; flex: none;
    height: var(--peek-h); padding: 0 12px 0 4px;
    background: #fff; border-bottom: 1px solid var(--line-soft);
    border-radius: var(--r-lg) var(--r-lg) 0 0;
  }
  .peek-grab {
    flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px;
    background: none; border: 0; font: inherit; color: var(--ink);
    padding: 8px; min-height: 52px; cursor: pointer; text-align: left;
    border-radius: var(--r-sm);
  }
  .peek-grab:active { background: var(--brand-tint); }
  .peek-chevron { flex: none; color: var(--muted); transition: transform .26s ease; }
  .cart-panel.is-open .peek-chevron { transform: rotate(180deg); }
  .peek-info { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
  .peek-info strong {
    font-size: .74rem; font-weight: 650; color: var(--muted);
    text-transform: uppercase; letter-spacing: .04em;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .peek-info span {
    font-size: 1.12rem; font-weight: 750; color: var(--brand);
    font-variant-numeric: tabular-nums; white-space: nowrap;
  }
  .peek-go { flex: none; min-height: 48px; padding: 0 20px; font-size: .95rem; }

  /* A quick pulse so adding an item is obvious while the sheet is shut. */
  .cart-peek.is-bumped .peek-info span { animation: peekBump .3s ease; }
  @keyframes peekBump { 40% { transform: scale(1.13); } }

  /* ---- inside the expanded sheet ---- */
  .pos-page .cart-items { max-height: none; flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

  /* 16px stops iOS zooming the whole page when a field takes focus. */
  .pos-page input, .pos-page select, .pos-page textarea,
  .pos-page .cart-row input, .pos-page .cart-row select { font-size: 16px; }
  .pos-page .cr-batch select { font-size: 14px; }

  /* Fingers, not mouse pointers. */
  .pos-page .qty-stepper button { width: 44px; height: 44px; font-size: 20px; }
  .pos-page .qty-stepper input { width: 58px; padding: 8px 2px; }
  .pos-page .cart-row { padding: 12px 14px; }
  .pos-page .cart-row .cr-x { padding: 8px; margin: -8px -4px -8px 0; }
  .pos-page .cart-row .cr-line { gap: 8px; margin-top: 9px; }
  .pos-page .cr-sub { font-size: .95rem; }

  /* ---- catalogue ---- */
  .pos-page .pos-search input { font-size: 16px; padding: 13px 14px; }
  .pos-page .pos-filters { scrollbar-width: none; }
  .pos-page .pos-filters::-webkit-scrollbar { display: none; }
  .pos-page .pos-filters button { min-height: 40px; }
  .pos-page .tile { min-height: 116px; }

  /* ---- dialogs behave as sheets too ---- */
  .pos-page .modal-host { padding: 0; place-items: end stretch; }
  .pos-page .modal {
    width: 100%; max-height: 94vh; border-radius: var(--r-lg) var(--r-lg) 0 0;
    padding: 20px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  }
  /* Keep "Complete sale" reachable without scrolling to the bottom. */
  .pos-page .modal-actions {
    position: sticky; bottom: calc(-16px - env(safe-area-inset-bottom, 0px));
    background: #fff; padding: 12px 0 calc(4px + env(safe-area-inset-bottom, 0px));
    margin-top: 16px; border-top: 1px solid var(--line-soft);
  }
  .pos-page .modal-actions .btn { flex: 1; min-height: 48px; }
  .pos-page fieldset { padding: 14px 12px; }
  .pos-page .split-row { grid-template-columns: 1fr 1fr auto; }
}

/* Two comfortable columns on the narrowest handsets. */
@media (max-width: 420px) {
  .pos-page .tile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .pos-page .tile { padding: 10px; min-height: 108px; }
  .pos-page .tile .t-name { font-size: .8rem; }
  .pos-page .peek-go { padding: 0 15px; font-size: .9rem; }
}

@media print {
  .sidebar, .topbar, .app-footer, .page-actions, .toast-stack, .no-print { display: none !important; }
  .app-main { margin: 0; }
  .page { padding: 0; max-width: none; }
  .card { border: 0; box-shadow: none; padding: 0; }
}
