:root {
  --bg: #f4f5f4; --surface: #ffffff; --surface-2: #eef1ef; --text: #17201d; --muted: #5d6a65;
  --line: #dde3e0; --accent: #0f766e; --accent-ink: #ffffff; --accent-soft: #d8f0ec;
  --danger: #b42318; --danger-soft: #fde8e6; --warn: #b45309; --warn-soft: #fef3c7;
  --radius: 12px; --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .05);
  --nav-h: 64px; --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1413; --surface: #171e1c; --surface-2: #1f2825; --text: #e8eeeb; --muted: #94a39d;
    --line: #2b3632; --accent: #2dd4bf; --accent-ink: #062a26; --accent-soft: #123b36;
    --danger: #f87171; --danger-soft: #3b1715; --warn: #fbbf24; --warn-soft: #3a2a0b;
    --shadow: 0 1px 2px rgb(0 0 0 / .4);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0; }
h3 { font-size: .95rem; margin: 0 0 .6rem; color: var(--muted); font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }
.pad { padding: 1rem 0; }
[hidden] { display: none !important; }
.boot { text-align: center; margin-top: 30vh; color: var(--muted); }

/* ---------- controls */
input, select, button { font: inherit; color: inherit; }
input, select {
  width: 100%; padding: .65rem .75rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); min-height: 44px;
}
input:focus-visible, select:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
label { display: grid; gap: .3rem; font-size: .9rem; color: var(--muted); font-weight: 500; }
label > input, label > select { color: var(--text); font-weight: 400; }
label.check { display: flex; align-items: center; gap: .6rem; color: var(--text); }
label.check input { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .6rem 1rem; min-height: 44px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 600; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn.danger.ghost { background: transparent; color: var(--danger); border-color: var(--line); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: .35rem .7rem; font-size: .9rem; }
.btn.wide { width: 100%; }
.btn.big { min-height: 54px; font-size: 1.05rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: .6rem; }
.form-error { color: var(--danger); background: var(--danger-soft); padding: .6rem .8rem; border-radius: 8px; font-size: .92rem; }
.stack { display: grid; gap: .9rem; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.tag { display: inline-block; font-size: .75rem; padding: .05rem .45rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); margin-left: .35rem; font-weight: 500; vertical-align: middle; }
.tag.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- login/setup */
.center-card {
  max-width: 420px; margin: max(6vh, 1rem) auto; padding: 1.75rem 1.25rem; background: var(--surface);
  border-radius: 18px; box-shadow: var(--shadow); display: grid; gap: 1rem; text-align: left;
}
.center-card > img { margin: 0 auto; }
.center-card > h1 { text-align: center; }
@media (max-width: 480px) { .center-card { margin: 0; min-height: 100dvh; border-radius: 0; box-shadow: none; align-content: center; } }

/* ---------- shell */
.shell { min-height: 100dvh; padding-bottom: calc(var(--nav-h) + var(--safe-b)); }
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .6rem 1rem; padding-top: max(.6rem, env(safe-area-inset-top)); background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; min-width: 0; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-right { display: flex; gap: .4rem; flex-shrink: 0; }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; background: var(--surface);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
}
.tab {
  flex: 1; display: grid; justify-items: center; gap: 2px; padding: .45rem .2rem; min-height: var(--nav-h);
  border: 0; background: none; cursor: pointer; color: var(--muted); font-size: .75rem; font-weight: 600;
}
.tab-icon { font-size: 1.3rem; line-height: 1.2; filter: grayscale(1); opacity: .75; }
.tab[aria-current="page"] { color: var(--accent); }
.tab[aria-current="page"] .tab-icon { filter: none; opacity: 1; }
main { padding: 1rem; max-width: 1200px; margin: 0 auto; }

@media (min-width: 900px) {
  .shell { padding-bottom: 0; display: grid; grid-template-columns: 200px 1fr; grid-template-rows: auto 1fr; }
  .top { grid-column: 1 / -1; }
  .tabs { position: sticky; top: 61px; align-self: start; flex-direction: column; border: 0; border-right: 1px solid var(--line); height: calc(100dvh - 61px); padding: .75rem .5rem; gap: .25rem; background: transparent; }
  .tab { flex: none; display: flex; align-items: center; gap: .7rem; min-height: 44px; padding: .5rem .8rem; border-radius: 10px; font-size: .95rem; }
  .tab[aria-current="page"] { background: var(--accent-soft); }
  main { width: 100%; padding: 1.5rem 2rem; }
}

/* ---------- pages */
.page { display: grid; gap: 1rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }
.page-head select { width: auto; }
.section-title { margin-top: .5rem; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.danger-zone h3 { color: var(--danger); }
.danger-zone p { margin-bottom: .8rem; }
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); display: grid; gap: .8rem; justify-items: center; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip { border: 1px solid var(--line); background: var(--surface); padding: .4rem .85rem; border-radius: 99px; cursor: pointer; white-space: nowrap; min-height: 38px; font-weight: 500; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; display: grid; gap: .15rem; }
.stat-label { font-size: .8rem; color: var(--muted); }
.stat-value { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.two-col { display: grid; gap: .75rem; }
.two-col:empty { display: none; }
@media (min-width: 900px) { .two-col { grid-template-columns: repeat(3, 1fr); align-items: start; } }
table.mini { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.mini td { padding: .35rem 0; border-bottom: 1px solid var(--line); }
table.mini tr:last-child td { border-bottom: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; padding-left: .75rem; white-space: nowrap; }
.search { min-height: 48px; }

/* ---------- sell */
.sell { display: grid; gap: 1rem; }
.sell-products { display: grid; gap: .75rem; align-content: start; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6rem; padding-bottom: 5rem; }
.tiles > .empty, .tiles > p { grid-column: 1 / -1; }
.tile {
  display: grid; gap: .2rem; align-content: space-between; text-align: left; min-height: 96px; padding: .75rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; box-shadow: var(--shadow);
  transition: transform .06s ease;
}
.tile:hover { border-color: var(--accent); }
.tile:active { transform: scale(.97); background: var(--accent-soft); }
.tile-name { font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.tile-sku { font-size: .75rem; color: var(--muted); }
.tile-price { font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }

.cart {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--safe-b)); z-index: 25;
  background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -6px 24px rgb(0 0 0 / .12);
  border-radius: 16px 16px 0 0; max-height: calc(100dvh - var(--nav-h) - 80px); display: flex; flex-direction: column;
}
.cart-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; width: 100%; padding: .85rem 1rem;
  background: none; border: 0; cursor: pointer; font-size: 1rem;
}
.cart-bar strong { margin-left: auto; font-variant-numeric: tabular-nums; }
.chev { transition: transform .15s; color: var(--muted); }
.cart.open .chev { transform: rotate(180deg); }
.cart-body { display: none; padding: 0 1rem 1rem; overflow-y: auto; }
.cart.open .cart-body { display: grid; gap: .75rem; }
.cart-head { display: flex; justify-content: space-between; align-items: center; }
.lines { list-style: none; margin: 0; padding: 0; display: grid; }
.line { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: .75rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.line-name { display: grid; min-width: 0; }
.line-name span { overflow-wrap: anywhere; }
.line-total { min-width: 4.5rem; text-align: right; font-variant-numeric: tabular-nums; }
.qty { display: flex; align-items: center; gap: .25rem; }
.qbtn { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; font-size: 1.1rem; line-height: 1; }
.qn { min-width: 1.6rem; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.cart-foot { display: grid; gap: .75rem; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); padding: 4px; border-radius: 12px; gap: 4px; }
.seg-btn { border: 0; background: transparent; padding: .55rem; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--muted); min-height: 40px; }
.seg-btn[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

@media (min-width: 900px) {
  .sell { grid-template-columns: 1fr 360px; align-items: start; }
  .tiles { padding-bottom: 0; }
  .cart { position: sticky; top: calc(61px + 1.5rem); bottom: auto; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); max-height: calc(100dvh - 61px - 3rem); }
  .cart-bar { display: none; }
  .cart-body, .cart.open .cart-body { display: grid; gap: .75rem; padding: 1rem; }
}

/* ---------- sales list */
.sale-list, .inv, .team { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.sale { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.sale summary { display: grid; grid-template-columns: 1fr auto; gap: .1rem 1rem; padding: .75rem 1rem; cursor: pointer; list-style: none; }
.sale summary::-webkit-details-marker { display: none; }
.sale-when { font-weight: 600; }
.sale-meta { grid-row: 2; font-size: .85rem; }
.sale-total { grid-row: 1 / 3; grid-column: 2; align-self: center; font-variant-numeric: tabular-nums; }
.sale[open] summary { border-bottom: 1px solid var(--line); }
.sale table { padding: .25rem 1rem; display: block; }
.sale table tbody { display: table; width: 100%; }
.row-end { display: flex; justify-content: flex-end; padding: .5rem 1rem .9rem; }

/* ---------- inventory */
.inv-row {
  width: 100%; display: grid; grid-template-columns: 1fr auto auto; grid-template-areas: "name price qty" "sku price qty";
  gap: 0 1rem; align-items: center; text-align: left; padding: .7rem 1rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer;
}
.inv-row:hover { border-color: var(--accent); }
.inv-name { grid-area: name; font-weight: 600; overflow-wrap: anywhere; }
.inv-sku { grid-area: sku; font-size: .8rem; }
.inv-price { grid-area: price; font-variant-numeric: tabular-nums; }
.qty-badge { grid-area: qty; min-width: 3rem; text-align: center; padding: .25rem .5rem; border-radius: 8px; background: var(--surface-2); font-weight: 700; font-variant-numeric: tabular-nums; }
.qty-badge.low { background: var(--warn-soft); color: var(--warn); }
.qty-badge.out { background: var(--danger-soft); color: var(--danger); }

/* ---------- team */
.member { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .6rem; padding: .75rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.member-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.inline-form { display: flex; gap: .6rem; align-items: end; flex-wrap: wrap; }
.inline-form label { flex: 1 1 200px; }
.temp-pw { display: block; font: 600 1.4rem/1.2 ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace; letter-spacing: .08em; padding: .9rem; text-align: center; background: var(--surface-2); border-radius: 10px; user-select: all; }

/* ---------- dialogs & toasts */
.dlg { border: 0; border-radius: 16px; padding: 0; width: min(480px, calc(100vw - 2rem)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / .3); }
.dlg::backdrop { background: rgb(0 0 0 / .45); }
.dlg-form { display: grid; gap: 1rem; padding: 1.25rem; max-height: calc(100dvh - 3rem); overflow-y: auto; }
.dlg-actions { display: flex; justify-content: flex-end; gap: .5rem; flex-wrap: wrap; }
.dlg-actions .btn.danger.ghost { margin-right: auto; }
details > summary { cursor: pointer; font-weight: 600; }
details > summary + form { margin-top: 1rem; }
#toasts { position: fixed; z-index: 100; left: 50%; transform: translateX(-50%); top: max(.75rem, env(safe-area-inset-top)); display: grid; gap: .5rem; width: min(440px, calc(100vw - 2rem)); pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: .75rem 1rem; border-radius: 12px; box-shadow: var(--shadow); font-weight: 500; transition: opacity .3s, transform .3s; }
.toast.error { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; transform: translateY(-8px); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
