:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5d6877;
  --line: #e3e7ec;
  --accent: #0f766e;
  --accent-dark: #0b5953;
  --accent-soft: #e6f4f2;
  --warn: #b45309;
  --warn-soft: #fef3e2;
  --ok: #15803d;
  --ok-soft: #e8f6ed;
  --info: #1d4ed8;
  --info-soft: #e8efff;
  --danger: #b91c1c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1418;
    --surface: #182027;
    --text: #e8edf2;
    --muted: #9aa7b4;
    --line: #2a3540;
    --accent: #2dd4bf;
    --accent-dark: #5eead4;
    --accent-soft: #123a37;
    --warn: #fbbf24;
    --warn-soft: #3b2c0b;
    --ok: #4ade80;
    --ok-soft: #0f3320;
    --info: #93b4ff;
    --info-soft: #1a2747;
    --danger: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: clamp(1.5rem, 3vw, 2rem); }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none !important; }
.icon { width: 22px; height: 22px; flex: none; }
.icon-sm { width: 18px; height: 18px; flex: none; }

/* Boot */
.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Header */
.header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  max-width: 1200px; margin: 0 auto; padding: .75rem 1rem;
  display: flex; align-items: center; gap: 1rem;
}
.brand { display: flex; align-items: center; gap: .6rem; color: var(--text); font-weight: 700; font-size: 1.1rem; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand img { width: 34px; height: 34px; }
.nav { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.nav a {
  color: var(--muted); padding: .45rem .75rem; border-radius: 999px; font-weight: 500; font-size: .95rem;
}
.nav a:hover { background: var(--accent-soft); color: var(--accent-dark); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent-dark); }
.header-actions { display: flex; align-items: center; gap: .5rem; margin-left: auto; }
.icon-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  height: 42px; min-width: 42px; padding: 0 .75rem; border-radius: 999px; cursor: pointer; font: inherit;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.badge-count {
  position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 999px; background: var(--accent); color: #fff; font-size: .75rem; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.user-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.menu-toggle { display: none; }

@media (max-width: 900px) {
  .menu-toggle { display: inline-flex; }
  .nav {
    display: none; position: absolute; left: 0; right: 0; top: 100%;
    background: var(--surface); border-bottom: 1px solid var(--line);
    flex-direction: column; padding: .5rem 1rem 1rem; box-shadow: var(--shadow);
  }
  .nav.open { display: flex; }
  .nav a { padding: .75rem; border-radius: 10px; }
  .user-name { display: none; }
}

/* Layout */
.main { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1rem 4rem; min-height: 70vh; }
.footer { border-top: 1px solid var(--line); color: var(--muted); font-size: .875rem; }
.footer-inner { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1rem; display: flex; gap: 1rem; flex-wrap: wrap; justify-content: space-between; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.back { display: inline-flex; align-items: center; gap: .25rem; color: var(--muted); margin-bottom: .75rem; font-size: .95rem; }

/* Hero */
.hero {
  border-radius: calc(var(--radius) + 6px); padding: clamp(1.5rem, 4vw, 3rem);
  background: linear-gradient(135deg, #0f5f7a 0%, #0f766e 55%, #14b8a6 100%);
  color: #fff; margin-bottom: 2rem; box-shadow: var(--shadow);
}
.hero h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); }
.hero p { opacity: .92; max-width: 60ch; font-size: 1.05rem; }
.hero .btn { background: #fff; color: #0b5953; border-color: #fff; }
.hero .btn.ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.6); }
.hero-actions { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: 1rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
  padding: .65rem 1.15rem; border-radius: 999px; font: inherit; font-weight: 600; cursor: pointer;
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--accent-dark); border-color: var(--accent-dark); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.block { width: 100%; }
.btn.lg { padding: .85rem 1.4rem; font-size: 1.05rem; }
.btn.sm { padding: .4rem .8rem; font-size: .9rem; }
.link-btn { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 0; }
.link-btn:hover { text-decoration: underline; }

/* Chips and search */
.toolbar { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; margin-bottom: 1.25rem; }
.chips { display: flex; gap: .5rem; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: .4rem .9rem; border-radius: 999px; cursor: pointer; font: inherit; font-size: .92rem;
}
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.search {
  display: flex; align-items: center; gap: .5rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: 999px; padding: 0 .9rem; min-width: min(100%, 320px); flex: 1; max-width: 420px;
}
.search input { border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; padding: .6rem 0; width: 100%; }
.search:focus-within { border-color: var(--accent); }

/* Product grid */
.grid { display: grid; gap: 1.25rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
@media (max-width: 560px) { .grid { grid-template-columns: 1fr; } }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow);
  transition: transform .15s, box-shadow .15s;
}
.tile:hover { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(16,24,40,.12); }
.tile-media { aspect-ratio: 4 / 3; background: var(--accent-soft); display: grid; place-items: center; position: relative; color: var(--accent); }
.tile-media img { width: 100%; height: 100%; object-fit: contain; padding: 1rem; }
.tile-media .icon { width: 56px; height: 56px; opacity: .6; }
.saving {
  position: absolute; top: .75rem; left: .75rem; background: var(--ok); color: #fff;
  font-size: .78rem; font-weight: 700; padding: .2rem .6rem; border-radius: 999px;
}
.tile-body { padding: 1rem 1rem .5rem; flex: 1; display: flex; flex-direction: column; gap: .25rem; }
.tile-cat { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.tile-title { font-weight: 700; font-size: 1.05rem; color: var(--text); }
.tile-title:hover { color: var(--accent); text-decoration: none; }
.tile-sub { color: var(--muted); font-size: .92rem; }
.price-row { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; margin-top: auto; padding-top: .5rem; }
.price { font-weight: 800; font-size: 1.2rem; }
.price-from { font-size: .82rem; color: var(--muted); }
.price-old { text-decoration: line-through; color: var(--muted); font-size: .9rem; }
.tile-actions { display: flex; gap: .5rem; padding: .5rem 1rem 1rem; }
.tile-actions .btn { flex: 1; }

/* Product detail */
.product { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 2rem; align-items: start; }
@media (max-width: 860px) { .product { grid-template-columns: 1fr; } }
.product-media {
  background: var(--surface); border: 1px solid var(--line); border-radius: calc(var(--radius) + 4px);
  aspect-ratio: 1 / 1; display: grid; place-items: center; position: relative; overflow: hidden; color: var(--accent);
}
.product-media img { width: 100%; height: 100%; object-fit: contain; padding: 2rem; }
.product-media .icon { width: 96px; height: 96px; opacity: .5; }
.product-info { display: flex; flex-direction: column; gap: 1rem; }
.product-price { display: flex; align-items: baseline; gap: .75rem; flex-wrap: wrap; }
.product-price .price { font-size: 2rem; }
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem; box-shadow: var(--shadow);
}
.panel + .panel { margin-top: 1rem; }
.option-group { margin-bottom: 1rem; }
.option-group > .label { font-weight: 600; margin-bottom: .4rem; display: block; }
.seg { display: flex; flex-wrap: wrap; gap: .5rem; }
.seg button {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: .5rem .9rem; border-radius: 10px; cursor: pointer; font: inherit; min-width: 64px;
}
.seg button:hover { border-color: var(--accent); }
.seg button.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; }
.seg button:disabled { opacity: .4; cursor: default; }
.addon {
  display: flex; gap: .75rem; align-items: flex-start; padding: .75rem; border: 1px solid var(--line);
  border-radius: 12px; cursor: pointer; margin-bottom: .5rem;
}
.addon:hover { border-color: var(--accent); }
.addon input { margin-top: .25rem; width: 18px; height: 18px; accent-color: var(--accent); }
.addon .addon-text { flex: 1; }
.addon .addon-price { font-weight: 600; white-space: nowrap; }
.switch { display: flex; align-items: center; gap: .6rem; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); }
.description { white-space: pre-line; color: var(--text); }

/* Quantity stepper */
.qty { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--surface); }
.qty button { width: 38px; height: 38px; border: 0; background: transparent; color: var(--text); font-size: 1.15rem; cursor: pointer; }
.qty button:hover { background: var(--accent-soft); color: var(--accent-dark); }
.qty button:disabled { opacity: .35; cursor: default; }
.qty span { min-width: 32px; text-align: center; font-weight: 600; }

/* Basket */
.basket { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1.5rem; align-items: start; }
@media (max-width: 860px) { .basket { grid-template-columns: 1fr; } }
.basket-line { display: flex; gap: 1rem; padding: 1rem 0; border-bottom: 1px solid var(--line); align-items: center; }
.basket-line:last-child { border-bottom: 0; }
.basket-line.addon-line { padding-left: 2.5rem; }
.basket-thumb { width: 64px; height: 64px; border-radius: 12px; background: var(--accent-soft); display: grid; place-items: center; flex: none; overflow: hidden; color: var(--accent); }
.basket-thumb img { width: 100%; height: 100%; object-fit: contain; padding: .35rem; }
.basket-main { flex: 1; min-width: 0; }
.basket-title { font-weight: 600; }
.basket-amount { font-weight: 700; white-space: nowrap; min-width: 90px; text-align: right; }
.basket-controls { display: flex; align-items: center; gap: .5rem; }
.summary-row { display: flex; justify-content: space-between; padding: .35rem 0; }
.summary-row.total { font-weight: 800; font-size: 1.15rem; border-top: 1px solid var(--line); margin-top: .5rem; padding-top: .75rem; }

/* Forms */
.form { display: grid; gap: 1rem; grid-template-columns: 1fr 1fr; }
.form .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form { grid-template-columns: 1fr; } }
.field label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
.field input, .field textarea, .field select {
  width: 100%; padding: .7rem .85rem; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit;
}
.field input:focus, .field textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); border-color: var(--accent); }
.field input[readonly] { background: var(--bg); color: var(--muted); }
.field textarea { min-height: 90px; resize: vertical; }
.form-actions { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: 1.25rem; }

/* Lists / tables */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { padding: .8rem 1rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list th { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--bg); font-weight: 600; }
table.list tr:last-child td { border-bottom: 0; }
table.list td.num, table.list th.num { text-align: right; white-space: nowrap; }
table.list tr.clickable { cursor: pointer; }
table.list tr.clickable:hover td { background: var(--accent-soft); }
.cards { display: none; }
@media (max-width: 720px) {
  .table-wrap.responsive table { display: none; }
  .table-wrap.responsive .cards { display: block; }
}
.card-row { display: flex; justify-content: space-between; gap: 1rem; padding: .9rem 1rem; border-bottom: 1px solid var(--line); cursor: default; }
.card-row:last-child { border-bottom: 0; }
.card-row.clickable { cursor: pointer; }
.card-row.clickable:hover { background: var(--accent-soft); }
.card-row .title { font-weight: 600; }
.card-row .right { text-align: right; white-space: nowrap; }

.status {
  display: inline-flex; align-items: center; padding: .2rem .65rem; border-radius: 999px;
  font-size: .8rem; font-weight: 600; background: var(--bg); color: var(--muted); white-space: nowrap;
}
.status.waiting { background: var(--warn-soft); color: var(--warn); }
.status.paid { background: var(--info-soft); color: var(--info); }
.status.done { background: var(--ok-soft); color: var(--ok); }
.status.cancelled { background: var(--bg); color: var(--muted); }
.neg { color: var(--danger); }
.pos { color: var(--ok); }

/* Detail views */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; text-align: right; word-break: break-word; }
.pay-box { display: flex; gap: 1.25rem; flex-wrap: wrap; align-items: center; }
.pay-box img { width: 168px; height: 168px; border-radius: 12px; background: #fff; padding: .5rem; border: 1px solid var(--line); }
.license {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--bg);
  border: 1px dashed var(--line); padding: .3rem .6rem; border-radius: 8px; font-size: .92rem; word-break: break-all;
}
.license-row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.desc-gap { margin-top: 2rem; }
.license-gap { margin-top: .4rem; }
.balance-card { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.balance-card .amount { font-size: 2rem; font-weight: 800; }

/* Empty and banner */
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty .icon { width: 48px; height: 48px; margin: 0 auto 1rem; color: var(--accent); opacity: .6; }
.banner { border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1.25rem; background: var(--ok-soft); color: var(--ok); display: flex; gap: .75rem; align-items: flex-start; }
.banner.info { background: var(--info-soft); color: var(--info); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.more { display: flex; justify-content: center; margin-top: 1.25rem; }

/* Login */
.auth { max-width: 440px; margin: 2rem auto; }
.auth .panel { padding: 2rem; }
.tabs { display: flex; gap: .25rem; background: var(--bg); padding: .25rem; border-radius: 999px; margin-bottom: 1.25rem; }
.tabs button { flex: 1; border: 0; background: transparent; padding: .55rem; border-radius: 999px; cursor: pointer; font: inherit; color: var(--muted); font-weight: 600; }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Toasts and dialogs */
.toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: .5rem; width: min(92vw, 460px); }
.toast {
  background: var(--text); color: var(--bg); padding: .85rem 1.1rem; border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25); animation: rise .2s ease-out; white-space: pre-line;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.scrim { position: fixed; inset: 0; background: rgba(10, 15, 20, .45); z-index: 70; display: grid; place-items: center; padding: 1rem; }
.dialog { background: var(--surface); color: var(--text); border-radius: 18px; padding: 1.5rem; width: min(100%, 440px); box-shadow: var(--shadow); }
.dialog p { white-space: pre-line; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
.dialog-choices { display: flex; flex-direction: column; gap: .5rem; margin-top: 1rem; }
