/* ==========================================================================
   main.css — Pixel design system (tokens + shared components)
   Palette & type follow the Pikolq pixel style: lavender/plum surfaces,
   deep-purple hero, yellow accent, hard offset shadows, square corners.
   ========================================================================== */

:root {
  /* Brand */
  --deep: #3B2A47;
  --deep-2: #2C1F36;
  --deep-3: #4A3459;
  --accent: #F7D774;
  --accent-strong: #E7BB4E;
  --accent-hover: #FBE08A;
  --primary: #A489B8;
  --primary-strong: #8F72A5;
  --plum: #6F527F;
  --plum-hover: #5C4369;

  /* Surfaces */
  --bg: #F3EDF7;
  --surface: #FFFFFF;
  --surface-2: #FAF7FC;
  --lav-100: #E5D8ED;
  --header-bg: rgba(236, 226, 243, 0.97);

  /* Text */
  --text: #33283B;
  --text-2: #786C82;
  --heading: #3B2A47;
  --on-fill: #FFFFFF;

  /* Lines & pixel shadow */
  --border: #E9E1EC;
  --border-strong: #DACDE3;
  --px-ink: #3B2A47;
  --px-line: #3B2A47;
  --px-shadow: #3B2A47;
  --px-u: 3px;

  /* Status */
  --success-bg: #DDF2E5; --success-fg: #2D6A45; --success-line: #A9D9BB;
  --warning-bg: #FFF0CE; --warning-fg: #855A00; --warning-line: #F2D58C;
  --error-bg:   #FCE4E7; --error-fg:   #A8394B; --error-line:   #F1C2CA;
  --neutral-bg: #F1EDF2; --neutral-fg: #5E5466;

  --focus: 0 0 0 3px var(--accent), 3px 3px 0 3px var(--px-ink);

  /* Type */
  --font: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --px-font: "Pixelify Sans", "Plus Jakarta Sans", sans-serif;
  --px-label: "Silkscreen", "Pixelify Sans", monospace;

  --touch: 44px;
  --gutter: 24px;
  --maxw: 1180px;
  color-scheme: light;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1A1321;
  --surface: #261C30;
  --surface-2: #2C2137;
  --lav-100: #3A2C47;
  --header-bg: rgba(30, 22, 38, 0.97);
  --text: #EEE7F3;
  --text-2: #B7AAC2;
  --heading: #F3EDF7;
  --on-fill: #1A1321;
  --border: #3A2E46;
  --border-strong: #4D3D5B;
  --primary-strong: #C3AED3;
  --plum: #A88BC0;
  --plum-hover: #8E70A6;
  --px-ink: #0B070F;
  --px-line: #5E4A6E;
  --px-shadow: #0B070F;
  --success-bg: #1E3829; --success-fg: #8FD9AE; --success-line: #2F5C43;
  --warning-bg: #3A2F18; --warning-fg: #F2D58C; --warning-line: #6B5420;
  --error-bg:   #3D1E26; --error-fg:   #F2A3B0; --error-line:   #6E2E3B;
  --neutral-bg: #2E2538; --neutral-fg: #C2B6CC;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1 0 auto; }
h1, h2, h3, h4 { font-family: var(--px-font); color: var(--heading); margin: 0 0 .5em; line-height: 1.15; font-weight: 700; }
p { margin: 0 0 1em; }
a { color: var(--plum); }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

.px-container { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 var(--gutter); }
@media (max-width: 640px) { :root { --gutter: 16px; } }

.px-label { font-family: var(--px-label); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; }
.muted { color: var(--text-2); }
.mono-num { font-variant-numeric: tabular-nums; }

/* ---------- Header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 30;
  background: var(--header-bg);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid var(--px-line);
}
.header-inner { display: flex; align-items: center; gap: 14px; padding-top: 12px; padding-bottom: 12px; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; min-width: 0; }
.brand-mark {
  width: 44px; height: 44px; flex: 0 0 44px;
  display: grid; place-items: center;
  background: var(--surface);
  border: 2px solid var(--px-ink);
  box-shadow: var(--px-u) var(--px-u) 0 var(--px-shadow);
}
html[data-theme="dark"] .brand-mark { background: #F3EDF7; }
.brand-mark svg { width: 34px; height: 34px; }
.brand-text { min-width: 0; display: flex; flex-direction: column; }
.brand-name { font-family: var(--px-font); font-weight: 700; font-size: 1.3rem; color: var(--heading); line-height: 1.1; white-space: nowrap; }
.brand-name span { color: var(--plum); }
.brand-tagline { font-family: var(--px-label); font-size: .6rem; letter-spacing: .12em; text-transform: uppercase; color: var(--text-2); margin-top: 3px; white-space: nowrap; }
.header-nav { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.header-link {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 10px;
  font-family: var(--px-label); font-size: .68rem; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text); text-decoration: none;
}
.header-link:hover { color: var(--plum); }
.header-link svg { width: 14px; height: 14px; }
@media (max-width: 560px) {
  .brand-tagline { display: none; }
  .brand-name { font-size: 1.1rem; }
  .header-link .hl-text { display: none; }
}

/* Theme toggle */
.theme-toggle {
  width: 40px; height: 40px; display: grid; place-items: center; cursor: pointer;
  background: var(--surface); color: var(--deep);
  border: 2px solid var(--px-ink);
  box-shadow: var(--px-u) var(--px-u) 0 var(--px-shadow);
}
html[data-theme="dark"] .theme-toggle { background: #2C2137; color: var(--accent); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .tt-moon { display: none; }
html[data-theme="dark"] .theme-toggle .tt-sun { display: none; }
html[data-theme="dark"] .theme-toggle .tt-moon { display: block; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  min-height: var(--touch); padding: 8px 18px;
  font-family: var(--px-label); font-size: .74rem; letter-spacing: .08em; text-transform: uppercase; line-height: 1.2;
  text-decoration: none; text-align: center; white-space: nowrap;
  border: 2px solid var(--px-ink);
  background: var(--surface); color: var(--heading);
  box-shadow: var(--px-u) var(--px-u) 0 var(--px-shadow);
  transition: transform .08s steps(2), box-shadow .08s steps(2), background .12s;
}
.btn:hover:not(:disabled) { transform: translate(-1px, -1px); box-shadow: calc(var(--px-u) + 1px) calc(var(--px-u) + 1px) 0 var(--px-shadow); }
.btn:active:not(:disabled) { transform: translate(var(--px-u), var(--px-u)); box-shadow: 0 0 0 var(--px-shadow); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; flex: 0 0 auto; }
.btn-primary { background: var(--plum); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--plum-hover); }
html[data-theme="dark"] .btn-primary { color: #1A1321; }
.btn-accent { background: var(--accent); color: var(--deep); }
.btn-accent:hover:not(:disabled) { background: var(--accent-hover); }
.btn-danger { background: var(--error-bg); color: var(--error-fg); }
.btn-danger:hover:not(:disabled) { background: var(--error-fg); color: #fff; }
.btn-ghost { background: transparent; box-shadow: none; border-color: transparent; }
.btn-ghost:hover:not(:disabled) { box-shadow: none; transform: none; background: var(--lav-100); }
.btn-lg { min-height: 54px; padding: 0 28px; font-size: .82rem; }
.btn-sm { min-height: 34px; padding: 4px 12px; font-size: .64rem; --px-u: 2px; }
.btn-icon { width: 40px; padding: 0; }
.btn-block { width: 100%; }

/* ---------- Panels / cards ---------- */
.panel {
  background: var(--surface);
  border: 2px solid var(--px-ink);
  box-shadow: 4px 4px 0 var(--px-shadow);
  padding: 18px 20px 20px;
  min-width: 0;
}
html[data-theme="dark"] .panel { border-color: var(--px-line); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.panel-title { display: flex; align-items: center; gap: 10px; margin: 0; font-family: var(--px-font); font-size: 1.15rem; color: var(--heading); }
.panel-icon {
  width: 32px; height: 32px; flex: 0 0 32px; display: grid; place-items: center;
  background: var(--accent); color: var(--deep); border: 2px solid var(--px-ink);
}
.panel-icon svg { width: 16px; height: 16px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px;
  font-family: var(--px-label); font-size: .6rem; letter-spacing: .08em; text-transform: uppercase; white-space: nowrap;
  border: 2px solid currentColor;
}
.badge-dot { width: 6px; height: 6px; background: currentColor; }
.badge-success { background: var(--success-bg); color: var(--success-fg); }
.badge-warning { background: var(--warning-bg); color: var(--warning-fg); }
.badge-error   { background: var(--error-bg);   color: var(--error-fg); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral-fg); }
.badge-plum    { background: var(--lav-100);    color: var(--plum); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field-label { font-family: var(--px-label); font-size: .64rem; letter-spacing: .1em; text-transform: uppercase; color: var(--text-2); }
.field input, .field select, .field textarea {
  width: 100%; min-height: var(--touch); padding: 9px 12px;
  background: var(--surface-2); color: var(--text);
  border: 2px solid var(--px-line);
  box-shadow: inset 3px 3px 0 rgba(59, 42, 71, .08);
  border-radius: 0;
}
html[data-theme="dark"] .field input, html[data-theme="dark"] .field select, html[data-theme="dark"] .field textarea { background: #130D19; box-shadow: inset 3px 3px 0 #000; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; box-shadow: var(--focus); background: var(--surface); }
.field textarea { min-height: 80px; resize: vertical; }
.field input[readonly] { color: var(--text-2); }
.field-hint { font-size: .78rem; color: var(--text-2); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .span-2 { grid-column: span 2; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } .form-grid .span-2 { grid-column: auto; } }
.form-error {
  padding: 10px 12px; background: var(--error-bg); color: var(--error-fg);
  border: 2px solid var(--error-line); font-size: .88rem;
}

/* Input with a trailing button (e.g. barcode + camera) */
.input-row { display: flex; gap: 8px; align-items: stretch; }
.input-row input { flex: 1; min-width: 0; }
.input-row .btn { flex: 0 0 auto; min-height: var(--touch); }

/* Camera scanner */
.scan-wrap { border: 2px solid var(--px-ink); box-shadow: 4px 4px 0 var(--px-shadow); background: #0B070F; }
.scan-region { width: 100%; min-height: 220px; background: #0B070F; }
.scan-region video { width: 100% !important; height: auto !important; display: block; }
.scan-status {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; min-height: 44px;
  background: var(--deep); color: #fff; font-size: .88rem; border-top: 2px solid #0B070F;
}
.scan-status svg { width: 16px; height: 16px; flex: 0 0 16px; }
.scan-status.is-ok { background: var(--success-bg); color: var(--success-fg); }
.scan-status.is-error { background: var(--error-bg); color: var(--error-fg); }

/* Segmented choice (radio pills) */
.seg { display: flex; border: 2px solid var(--px-line); }
.seg label { flex: 1; text-align: center; padding: 9px 8px; cursor: pointer; font-family: var(--px-label); font-size: .62rem; letter-spacing: .08em; text-transform: uppercase; color: var(--text-2); background: var(--surface-2); }
.seg label + label { border-left: 2px solid var(--px-line); }
.seg label { position: relative; }
.field .seg input, .seg input { position: absolute; inset: 0; width: 1px; height: 1px; min-height: 0; padding: 0; opacity: 0; pointer-events: none; }
.seg input:checked + span { color: inherit; }
.seg label:has(input:checked) { background: var(--plum); color: #fff; }
html[data-theme="dark"] .seg label:has(input:checked) { color: #1A1321; }
.seg label:has(input:focus-visible) { box-shadow: var(--focus); position: relative; }

/* ---------- Modal (native <dialog>) ---------- */
.modal {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  padding: 0; border: 2px solid var(--px-ink);
  background: var(--surface); color: var(--text);
  box-shadow: 6px 6px 0 var(--px-shadow);
}
html[data-theme="dark"] .modal { border-color: var(--px-line); }
.modal::backdrop { background: rgba(26, 19, 33, .55); }
.modal[open] { display: flex; flex-direction: column; overflow: hidden; animation: px-pop .18s steps(3); }
.modal-head, .modal-foot { flex: 0 0 auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; background: var(--deep); color: #fff; }
.modal-head h2 { margin: 0; font-size: 1.15rem; color: #fff; }
.modal-close { background: none; border: 0; color: #fff; width: 36px; height: 36px; display: grid; place-items: center; cursor: pointer; }
.modal-close svg { width: 18px; height: 18px; }
.modal-body { padding: 18px; overflow-y: auto; overflow-x: hidden; flex: 1 1 auto; min-height: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; padding: 14px 18px; border-top: 2px dashed var(--border-strong); }
.modal-foot .spacer { margin-right: auto; }
@keyframes px-pop { from { transform: scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Toasts ---------- */
.toast-stack { position: fixed; z-index: 100; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 10px; max-width: calc(100vw - 32px); }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px; min-width: 240px;
  background: var(--deep); color: #fff; border: 2px solid var(--px-ink); box-shadow: 4px 4px 0 var(--px-shadow);
  font-size: .9rem; animation: px-pop .18s steps(3);
}
.toast::before { content: ""; width: 10px; height: 10px; flex: 0 0 10px; background: var(--accent); }
.toast.is-error::before { background: #F2A3B0; }
.toast.is-success::before { background: #8FD9AE; }
html[data-theme="dark"] .toast { background: #F3EDF7; color: #1A1321; }

/* ---------- Loading / empty ---------- */
.px-loader { display: inline-flex; gap: 5px; }
.px-loader i { width: 8px; height: 8px; background: var(--plum); animation: px-blink 0.9s steps(1) infinite; }
.px-loader i:nth-child(2) { animation-delay: .3s; }
.px-loader i:nth-child(3) { animation-delay: .6s; }
@keyframes px-blink { 0%, 100% { opacity: .25; } 33% { opacity: 1; } }
.state-box { padding: 36px 16px; text-align: center; color: var(--text-2); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.state-box h3 { margin: 0; font-size: 1.1rem; }
.state-box p { margin: 0; max-width: 420px; }
.notice {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px;
  background: var(--warning-bg); color: var(--warning-fg); border: 2px solid var(--warning-line); font-size: .9rem;
}
.notice code { font-size: .85em; }

/* ---------- Footer ---------- */
.site-footer { margin-top: 56px; background: var(--deep-2); color: rgba(255,255,255,.75); border-top: 2px solid var(--px-ink); }
.site-footer .px-container { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding-top: 22px; padding-bottom: 22px; font-size: .85rem; }
.site-footer a { color: var(--accent); }
.site-footer .px-label { color: var(--accent); }

/* ---------- Money & numbers: clear, non-pixel font ----------
   In the pixel font a 5 looks like an S and 0/8 blur together, so every
   amount, total, count and code uses the regular font with even-width digits. */
.stat .stat-value, .info-big, .summary-box strong, .product-tile .pt-price, .cart-item .ci-total,
.cart-total strong, .change-row strong, .pos-mobile-bar strong, .receipt .grand td, .stepper input,
.chart-y, .chart-tip, .chart-tip strong, .num, .mono-num, .money, input.code-input,
.product-tile .pt-qty, .select-bar .sb-count, .period-label strong, .cal-title, .day-title h2 {
  font-family: var(--font) !important;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.stat .stat-value, .info-big, .cart-total strong, .change-row strong, .pos-mobile-bar strong,
.product-tile .pt-price, .cart-item .ci-total, .receipt .grand td, .summary-box strong { font-weight: 800; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
