:root {
  --ink: #1C2326;
  --muted: #5F6C70;
  --paper: #EEF1F0;
  --surface: #FFFFFF;
  --line: #D3DBDA;
  --brand: #14505C;
  --brand-deep: #0E3A44;
  --brand-tint: #E2EEF0;
  --amber: #F0A63A;
  --amber-deep: #C9821A;
  --ok: #2F8F5B;
  --ok-tint: #E3F3EA;
  --warn: #C8542C;
  --warn-tint: #FBE8E1;
  --receipt: #FBFAF5;
  --font: "IBM Plex Sans", -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  --nav-h: 64px;
  --r: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); color: var(--ink); background: var(--paper);
  font-size: 16px; line-height: 1.4; -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 26px; }
p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }

/* Layout */
.app { min-height: 100%; padding: 16px 16px calc(var(--nav-h) + 24px); max-width: 1100px; }
.view { display: none; }
.view.active { display: block; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.view-head p { color: var(--muted); }
.section-title { font-size: 14px; font-weight: 600; color: var(--muted); margin: 24px 0 8px; }

/* Nav: bottom bar on phone, left rail on tablet */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--nav-h); z-index: 20;
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-brand { display: none; }
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: none; border: 0; color: var(--muted); font-size: 11px; font-weight: 500; min-height: 48px;
}
.nav-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-btn.active { color: var(--brand); }
.nav-sell { color: var(--brand); }
.nav-sell svg { background: var(--amber); border-radius: 50%; padding: 4px; stroke: var(--brand-deep); stroke-width: 2.4; width: 32px; height: 32px; margin-top: -8px; }
.nav-desktop-only { display: none; }
.brand-mark { display: inline-block; width: 22px; height: 22px; border-radius: 6px 6px 6px 0; background: linear-gradient(135deg, var(--amber), var(--amber-deep)); }

@media (min-width: 900px) {
  :root { --nav-h: 0px; }
  .nav {
    top: 0; bottom: 0; right: auto; width: 220px; height: auto; flex-direction: column; align-items: stretch;
    border-top: 0; border-right: 1px solid var(--line); padding: 20px 12px; gap: 4px; background: var(--brand-deep); color: #fff;
  }
  .nav-brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 22px; font-weight: 600; color: #fff; }
  .nav-btn { flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 0 12px; border-radius: 8px; font-size: 15px; color: rgba(255,255,255,.75); }
  .nav-btn.active { background: rgba(255,255,255,.12); color: #fff; }
  .nav-sell, .nav-sell.active { color: var(--brand-deep); background: var(--amber); margin: 6px 0 12px; }
  .nav-sell svg { margin: 0; width: 24px; height: 24px; padding: 2px; background: none; }
  .nav-more { display: none; }
  .nav-desktop-only { display: flex; }
  .app { margin-left: 220px; padding: 28px 32px 40px; }
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px;
  border-radius: var(--r); border: 1px solid transparent; font-weight: 600; font-size: 16px; white-space: nowrap;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:active { background: var(--brand-deep); }
.btn-amber { background: var(--amber); color: var(--brand-deep); }
.btn-ghost { background: var(--surface); border-color: var(--line); }
.btn-danger { background: var(--warn-tint); color: var(--warn); }
.btn-block { width: 100%; }
.btn-hero { width: 100%; min-height: 64px; font-size: 19px; margin-top: 16px; background: var(--amber); color: var(--brand-deep); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.self-end { align-self: end; }

/* Stats */
.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { background: var(--surface); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; border-left: 4px solid var(--brand); }
.stat-warn { border-left-color: var(--amber); }
.stat-label { font-size: 13px; color: var(--muted); }
.stat strong { font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; margin: 2px 0; }
.stat-sub { font-size: 13px; color: var(--muted); }

/* Lists and rows */
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: var(--surface); border: 0;
  border-radius: var(--r); padding: 14px 16px; min-height: 64px;
}
.row:active { background: var(--brand-tint); }
.row-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.row-main strong { font-weight: 600; }
.row-main span { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-end { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.row-end strong { font-variant-numeric: tabular-nums; }
.badge { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.badge-paid { background: var(--ok-tint); color: var(--ok); }
.badge-unpaid { background: var(--warn-tint); color: var(--warn); }
.badge-partial { background: #FCEFD8; color: var(--amber-deep); }
.badge-void { background: #E4E7E6; color: var(--muted); }
.badge-refunded, .badge-credit, .badge-applied { background: var(--brand-tint); color: var(--brand); }
.done-wrap { display: flex; flex-direction: column; gap: 14px; }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.action-grid .btn { min-height: 56px; padding: 0 10px; white-space: normal; text-align: center; }
.table.mini { margin-bottom: 0; font-size: 14px; }
.table.mini td { padding: 8px 10px; }
.empty { color: var(--muted); padding: 32px 16px; text-align: center; background: var(--surface); border-radius: var(--r); }

/* Inputs */
input[type=text], input[type=search], input[type=number], input[type=password], input[type=date], input[type=tel], input[type=email], input:not([type]), select, textarea {
  width: 100%; min-height: 48px; padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface);
}
textarea { min-height: 80px; resize: vertical; }
input[type=search] { -webkit-appearance: none; }
.search-full { margin-bottom: 12px; }
.form { display: flex; flex-direction: column; gap: 14px; max-width: 640px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 500; color: var(--muted); }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form .section-title:first-child { margin-top: 0; }
.check { flex-direction: row !important; align-items: center; gap: 10px !important; }
.check input { width: 22px; height: 22px; min-height: 0; }
label.inline { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
label.inline input { width: auto; }
.filter-row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; align-items: center; }
.filter-row input[type=search] { flex: 1 1 220px; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-weight: 500; font-size: 14px; }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.alert { background: var(--warn-tint); color: var(--warn); padding: 12px 14px; border-radius: var(--r); font-size: 14px; }
.printer-box { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.printer-box > div:first-child { display: flex; flex-direction: column; gap: 2px; font-size: 14px; }

/* Sell screen */
.sell-products { min-width: 0; }
.sell-toolbar { position: sticky; top: 0; background: var(--paper); padding-bottom: 10px; z-index: 5; display: flex; flex-direction: column; gap: 10px; }
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.pbtn {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 12px 10px; min-height: 92px;
  display: flex; flex-direction: column; justify-content: space-between; text-align: left; position: relative;
}
.pbtn:active { background: var(--brand-tint); border-color: var(--brand); }
.pbtn.in-ticket { border-color: var(--amber); }
.pbtn .pname { font-weight: 500; line-height: 1.25; }
.pbtn .pprice { display: flex; justify-content: space-between; align-items: baseline; margin-top: 8px; }
.pbtn .pprice strong { font-variant-numeric: tabular-nums; font-size: 17px; }
.pbtn .pprice span { font-size: 12px; color: var(--muted); }
.pbtn .pqty { position: absolute; top: -6px; right: -6px; background: var(--amber); color: var(--brand-deep); font-weight: 700; font-size: 13px; min-width: 24px; height: 24px; border-radius: 12px; display: flex; align-items: center; justify-content: center; padding: 0 6px; }

/* The ticket, styled like a thermal receipt */
.ticket {
  background: var(--receipt); font-family: var(--mono); font-size: 14px;
  box-shadow: 0 6px 24px rgba(20,40,45,.15); display: flex; flex-direction: column;
  border-radius: 4px 4px 0 0; position: relative;
}
.ticket::after {
  content: ""; display: block; height: 10px; width: 100%; position: absolute; bottom: -10px; left: 0;
  background: linear-gradient(-45deg, transparent 7px, var(--receipt) 0) 0 0 / 14px 14px repeat-x, linear-gradient(45deg, transparent 7px, var(--receipt) 0) 7px 0 / 14px 14px repeat-x;
}
.ticket-customer { width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px dashed #BBB; padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; font-family: var(--mono); }
.ticket-customer .tc-label { font-size: 11px; color: var(--muted); }
.ticket-customer strong { font-size: 15px; }
.ticket-customer.unset strong { color: var(--amber-deep); }
.ticket-lines { flex: 1; overflow-y: auto; padding: 8px 8px; min-height: 120px; }
.ticket-empty { color: var(--muted); text-align: center; padding: 32px 8px; font-family: var(--font); }
.tline { width: 100%; background: none; border: 0; text-align: left; padding: 8px; border-radius: 6px; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; font-family: var(--mono); font-size: 14px; }
.tline:active { background: rgba(0,0,0,.05); }
.tline .tname { grid-column: 1 / -1; }
.tline .tqty { color: var(--muted); }
.tline .ttotal { text-align: right; font-variant-numeric: tabular-nums; }
.ticket-totals { padding: 10px 16px; border-top: 1px dashed #BBB; }
.ticket-totals div { display: flex; justify-content: space-between; padding: 2px 0; font-variant-numeric: tabular-nums; }
.ticket-totals .grand { font-weight: 600; font-size: 20px; padding-top: 6px; }
.ticket-actions { display: grid; grid-template-columns: 1fr 1.2fr; gap: 8px; padding: 12px 16px 16px; }
.ticket-actions .btn { font-family: var(--font); padding: 0 10px; }

/* Phone: ticket becomes a bottom sheet, with a summary bar */
.ticket-bar {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + 10px); z-index: 15; display: none;
  align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; padding: 0 18px; border: 0;
  background: var(--brand-deep); color: #fff; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.25); font-weight: 600;
}
.ticket-bar strong { font-size: 18px; font-variant-numeric: tabular-nums; }
@media (max-width: 899px) {
  .view-sell.active { padding-bottom: 80px; }
  .view-sell.active .ticket-bar { display: flex; }
  .ticket { position: fixed; left: 0; right: 0; bottom: 0; top: 12vh; z-index: 30; transform: translateY(105%); transition: transform .25s ease; border-radius: 16px 16px 0 0; }
  .ticket.open { transform: none; }
  .ticket::after { display: none; }
}
@media (min-width: 900px) {
  .view-sell.active { display: grid; grid-template-columns: 1fr 340px; gap: 24px; align-items: start; }
  .ticket { position: sticky; top: 28px; max-height: calc(100vh - 60px); }
  .sell-toolbar { top: -28px; padding-top: 28px; margin-top: -28px; }
}
@media (prefers-reduced-motion: reduce) { .ticket, .sheet { transition: none; } }

/* Sheets */
.sheet-backdrop { display: none; position: fixed; inset: 0; background: rgba(14,58,68,.45); z-index: 25; }
.sheet-backdrop.show { display: block; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: var(--surface); border-radius: 16px 16px 0 0;
  max-height: 92vh; overflow-y: auto; transform: translateY(105%); transition: transform .22s ease; padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
}
.sheet:not(.open) { pointer-events: none; visibility: hidden; transition: transform .22s ease, visibility 0s .22s; }
.sheet.open { transform: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h2 { font-size: 20px; }
.sheet-close { background: var(--paper); border: 0; width: 40px; height: 40px; border-radius: 50%; font-size: 20px; }
.sheet .form { max-width: none; }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-actions .btn { flex: 1; }
@media (min-width: 700px) {
  .sheet { left: 50%; right: auto; bottom: auto; top: 50%; width: 560px; max-width: 94vw; border-radius: 16px; transform: translate(-50%, -46%); opacity: 0; }
  .sheet.open { transform: translate(-50%, -50%); opacity: 1; }
}

/* Quantity editor */
.qty-editor { display: grid; grid-template-columns: 64px 1fr 64px; gap: 10px; align-items: center; margin: 8px 0 16px; }
.qty-editor button { min-height: 64px; font-size: 28px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface); }
.qty-editor input { text-align: center; font-size: 28px; min-height: 64px; font-variant-numeric: tabular-nums; }
.qty-editor input::-webkit-outer-spin-button, .qty-editor input::-webkit-inner-spin-button { -webkit-appearance: none; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.seg button { min-height: 48px; border: 0; background: var(--surface); font-weight: 500; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--brand); color: #fff; }
.pay-total { display: flex; justify-content: space-between; align-items: baseline; font-size: 18px; padding: 12px 0; border-bottom: 1px dashed var(--line); margin-bottom: 12px; }
.pay-total strong { font-size: 30px; font-variant-numeric: tabular-nums; }

/* Receipt preview after saving / in invoice detail */
.receipt-wrap { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.receipt { background: var(--receipt); font-family: var(--mono); font-size: 12px; white-space: pre; padding: 18px 12px 24px; width: 100%; max-width: 380px; box-shadow: 0 6px 24px rgba(20,40,45,.15); line-height: 1.35; margin: 0; overflow-x: auto; }
.receipt-wrap .btn-row { width: 100%; max-width: 380px; }
.receipt-wrap .btn-row .btn { flex: 1; }
.done-head { text-align: center; margin-bottom: 8px; }
.done-head strong { display: block; font-size: 22px; }
.done-head span { color: var(--muted); }

/* Products view */
.cat-title { font-size: 14px; font-weight: 600; color: var(--muted); margin: 18px 0 8px; }

/* Reports */
.table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--r); overflow: hidden; margin-bottom: 20px; font-size: 15px; }
.table th, .table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); }
.table th { font-size: 13px; color: var(--muted); font-weight: 600; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr:last-child td { border-bottom: 0; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px); transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 15px; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--warn); }

/* Login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; background: var(--brand-deep); }
.login-card { background: var(--surface); border-radius: 16px; padding: 32px 28px; width: 100%; max-width: 400px; }
.login-brand { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin-bottom: 24px; }
.login-brand h1 { font-size: 24px; margin-top: 8px; }
.login-brand p { color: var(--muted); }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); font-weight: 500; }
.login-form input { font-size: 17px; }

/* Print: only the receipt */
.print-area { display: none; }
@media print {
  body { background: #fff; }
  .nav, .app, .sheet, .sheet-backdrop, .toast, .ticket-bar { display: none !important; }
  .print-area { display: block; font-family: var(--mono); font-size: 11px; white-space: pre-wrap; line-height: 1.3; color: #000; }
}
