/* Longstar Center — CRM */
:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --sidebar: #ffffff;
  --surface: #ffffff;
  --surface-2: #f2f4f7;
  --text: #101828;
  --text-2: #475467;
  --muted: #8a94a6;
  --line: #eaecf0;
  --line-strong: #d0d5dd;
  --accent: #911c1d;
  --accent-hover: #74161a;
  --accent-text: #ffffff;
  --accent-wash: #fbefef;
  --focus: #911c1d;
  --ok: #067647;  --ok-bg: #ecfdf3;
  --warn: #b54708; --warn-bg: #fffaeb;
  --bad: #c4320a;  --bad-bg: #fff4ed;
  --info: #175cd3; --info-bg: #eff8ff;
  --violet: #5925dc; --violet-bg: #f4f3ff;
  --neutral-bg: #f2f4f7;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 12px 32px rgba(16, 24, 40, .10);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0c0e12; --sidebar: #111318; --surface: #15181e; --surface-2: #1d2129; --text: #f2f4f7; --text-2: #b4bccb;
    --muted: #7d8697; --line: #232831; --line-strong: #323946; --accent: #e5484d; --accent-hover: #f06a6e; --accent-text: #0c0e12;
    --accent-wash: #3a1517; --focus: #f06a6e;
    --ok: #47cd89; --ok-bg: #0f2a1d; --warn: #fdb022; --warn-bg: #2e2110; --bad: #f97066; --bad-bg: #331512;
    --info: #53b1fd; --info-bg: #102a43; --violet: #a48afb; --violet-bg: #231a42; --neutral-bg: #1d2129;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4); --shadow: 0 1px 3px rgba(0,0,0,.4), 0 12px 32px rgba(0,0,0,.45);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c0e12; --sidebar: #111318; --surface: #15181e; --surface-2: #1d2129; --text: #f2f4f7; --text-2: #b4bccb;
  --muted: #7d8697; --line: #232831; --line-strong: #323946; --accent: #e5484d; --accent-hover: #f06a6e; --accent-text: #0c0e12;
  --accent-wash: #3a1517; --focus: #f06a6e;
  --ok: #47cd89; --ok-bg: #0f2a1d; --warn: #fdb022; --warn-bg: #2e2110; --bad: #f97066; --bad-bg: #331512;
  --info: #53b1fd; --info-bg: #102a43; --violet: #a48afb; --violet-bg: #231a42; --neutral-bg: #1d2129;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4); --shadow: 0 1px 3px rgba(0,0,0,.4), 0 12px 32px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: 24px; line-height: 1.25; letter-spacing: -0.02em; margin: 0; font-weight: 650; }
h2 { font-size: 18px; letter-spacing: -0.01em; margin: 0 0 4px; font-weight: 650; }
p { margin: 4px 0; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: 12.5px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spacer { flex: 1; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  box-shadow: var(--shadow-sm); transition: background .15s, border-color .15s; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; box-shadow: none; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
label { display: block; font-size: 13px; font-weight: 550; color: var(--text-2); margin: 12px 0 0; }
input:where(:not([type="file"]):not([type="checkbox"])), .select, textarea {
  display: block; width: 100%; margin-top: 6px; padding: 0 12px; height: 40px;
  border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface);
  color: var(--text); font: inherit; font-size: 14px; box-shadow: var(--shadow-sm);
}
textarea { height: auto; padding: 9px 12px; resize: vertical; }
input:focus, .select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 18%, transparent); }
.select { width: auto; margin: 0; padding-right: 32px; }
.select.full { width: 100%; margin-top: 6px; }
label.check { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text); margin-top: 16px; cursor: pointer; }
label.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.form-error { color: var(--bad); font-size: 13.5px; margin-top: 12px; }

/* ---------- auth ---------- */
.center-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 32px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 22px; margin: 24px 0 4px; }
.auth-card .btn { margin-top: 24px; height: 44px; }
.auth-card .small { margin-top: 16px; text-align: center; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -0.01em; font-size: 15px; }
.brand.big { font-size: 17px; }
.logo { width: 40px; height: 40px; object-fit: contain; flex: none; }
.brand.big .logo { width: 72px; height: 72px; }
.mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-text); font-size: 15px; flex: none; }

/* ---------- app shell: sidebar + main ---------- */
#appView:not([hidden]) { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 8px;
  background: var(--sidebar); border-right: 1px solid var(--line); padding: 20px 12px 12px;
}
.sidebar .brand { padding: 0 8px 16px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-label { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 14px 10px 6px; }
.nav button {
  display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; font: inherit; font-weight: 550;
  color: var(--text-2); padding: 9px 10px; border-radius: 8px; cursor: pointer; text-align: left;
}
.nav button:hover { background: var(--surface-2); color: var(--text); }
.nav button[aria-current="page"] { background: var(--accent-wash); color: var(--accent); }
.ico { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav-count { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--accent-text); font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; }
.user-menu { position: relative; }
.user-card { display: flex; align-items: center; gap: 10px; width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px; font: inherit; color: inherit; cursor: pointer; text-align: left; }
.user-card:hover { background: var(--surface-2); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-wash); color: var(--accent); font-weight: 700; display: grid; place-items: center; flex: none; }
.user-text { display: flex; flex-direction: column; min-width: 0; }
.user-text #userEmail { font-weight: 600; font-size: 13px; }
.menu { position: absolute; top: calc(100% + 6px); right: 0; min-width: 210px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; z-index: 20; }
.menu.up { top: auto; bottom: calc(100% + 6px); left: 0; right: 0; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; font: inherit; color: var(--text); padding: 9px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }
.main { min-width: 0; }

/* ---------- page ---------- */
.page { max-width: 1180px; margin: 0 auto; padding: 32px 32px 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.actions { display: flex; gap: 8px; align-items: center; }
.title-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.loc-select { height: 34px; font-weight: 600; border-radius: 999px; padding-left: 14px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; text-align: left; font: inherit; color: inherit; box-shadow: var(--shadow-sm); }
button.stat { cursor: pointer; }
button.stat:hover { border-color: var(--line-strong); }
.stat .label { font-size: 13px; color: var(--text-2); font-weight: 500; }
.stat .value { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; margin-top: 6px; }
.stat .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.alert .value { color: var(--warn); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.search { position: relative; flex: 1; min-width: 220px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.search input { margin: 0; padding-left: 38px; }
.chips { display: inline-flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 10px; border: 1px solid var(--line); }
.chips button { height: 32px; padding: 0 12px; border-radius: 7px; border: 0; background: none; color: var(--text-2); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.chips button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- lists / tables ---------- */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.list-head, .row { display: grid; grid-template-columns: 1fr 120px 140px; gap: 16px; align-items: center; padding: 0 18px; }
.list-head { height: 40px; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--line); }
.row { width: 100%; min-height: 60px; border: 0; border-bottom: 1px solid var(--line); background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; transition: background .12s; }
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--surface-2); }
.row .name { font-weight: 600; }
.row .sub { font-size: 12.5px; color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.row .price { font-weight: 600; }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.low { background: var(--warn-bg); color: var(--warn); }
.pill.out { background: var(--bad-bg); color: var(--bad); }
.empty { padding: 56px 24px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }

.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.yes, .badge.entregado { background: var(--ok-bg); color: var(--ok); }
.badge.no, .badge.cancelado { background: var(--neutral-bg); color: var(--muted); }
.badge.programado { background: var(--violet-bg); color: var(--violet); }
.badge.pendiente { background: var(--warn-bg); color: var(--warn); }
.badge.pagado { background: var(--info-bg); color: var(--info); }
.badge.enviado { background: var(--accent-wash); color: var(--accent); }

/* ---------- catalog ---------- */
.cat-group { margin-bottom: 24px; }
.cat-title { display: flex; align-items: baseline; gap: 8px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 8px 2px; }
.cat-row { grid-template-columns: 1fr 110px 110px; }
.cat-row .colors-line { font-size: 12.5px; color: var(--muted); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-flex; align-items: center; height: 28px; padding: 0 11px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: 12.5px; font-weight: 550; }
.sheet-price { font-size: 32px; font-weight: 700; letter-spacing: -0.02em; margin: 20px 0 6px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 20px; }

/* ---------- orders & customers ---------- */
.order-row { grid-template-columns: 1fr 150px 110px 120px; }
.order-row .when { font-size: 12.5px; color: var(--text-2); }
.order-row .when.late { color: var(--bad); font-weight: 600; }
.order-row .when.today { color: var(--accent); font-weight: 600; }
.group-title { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 8px 2px; }
.group-title.late { color: var(--bad); }
.group-title.today { color: var(--accent); }
.group { margin-bottom: 22px; }
.customer-row { grid-template-columns: 1fr 160px 90px 120px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; margin: 12px 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 550; overflow-wrap: anywhere; }
.card { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-top: 16px; }
.items { margin-top: 8px; }
.item { display: grid; grid-template-columns: 1fr auto; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .what { font-weight: 600; }
.item .meta { font-size: 12.5px; color: var(--muted); }
.totals { margin-top: 8px; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; font-variant-numeric: tabular-nums; }
.totals .grand { font-size: 17px; font-weight: 700; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; }
.status-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 20px; }
.wa { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; text-decoration: none; }

/* order form */
dialog.wide { max-width: 720px; }
.form-section { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 14px; }
.form-section:first-of-type { border-top: 0; margin-top: 8px; padding-top: 0; }
.form-section-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.combo { position: relative; }
.combo-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); max-height: 280px; overflow-y: auto; z-index: 5; padding: 4px; }
.combo-list button { display: flex; justify-content: space-between; gap: 12px; width: 100%; text-align: left; border: 0; background: none; font: inherit; color: var(--text); padding: 9px 10px; border-radius: 6px; cursor: pointer; }
.combo-list button:hover, .combo-list button:focus { background: var(--surface-2); outline: none; }
.combo-list .opt-sub { color: var(--muted); font-size: 12.5px; }
.combo-list .opt-head { font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 10px 4px; }
.lines { margin-top: 10px; }
.line { display: grid; grid-template-columns: 1fr 74px 96px 90px 36px; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.line input { margin: 0; height: 36px; }
.line .lt { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.line .stock-note { font-size: 12px; color: var(--muted); }
.line .stock-note.warn { color: var(--bad); }
.lines-head { display: grid; grid-template-columns: 1fr 74px 96px 90px 36px; gap: 8px; font-size: 12px; color: var(--muted); font-weight: 550; padding-top: 4px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; align-items: end; }
.total-box { display: flex; flex-direction: column; align-items: flex-end; padding-bottom: 6px; }
.total-box strong { font-size: 22px; letter-spacing: -0.02em; }

/* ---------- drawer ---------- */
.scrim { position: fixed; inset: 0; background: rgba(16, 24, 40, .35); z-index: 30; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100%); background: var(--surface);
  border-left: 1px solid var(--line); box-shadow: var(--shadow); z-index: 31; overflow-y: auto;
  transform: translateX(100%); transition: transform .22s ease; padding: 24px;
}
.drawer.open { transform: none; }
.drawer-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.drawer h2 { font-size: 20px; }
.close-btn { border: 0; background: var(--surface-2); width: 34px; height: 34px; border-radius: 50%; font-size: 18px; color: var(--text-2); cursor: pointer; flex: none; }
.stock-hero { margin: 20px 0 16px; padding: 18px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); }
.stock-hero .big { font-size: 40px; font-weight: 700; letter-spacing: -0.03em; line-height: 1; margin: 6px 0 10px; font-variant-numeric: tabular-nums; }
.quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.details { margin: 18px 0; }
.details div { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.details dt { color: var(--text-2); }
.details dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.section-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 24px 0 8px; }

/* ---------- colors ---------- */
.icon-btn { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); font: inherit; font-size: 16px; font-weight: 600; cursor: pointer; display: inline-grid; place-items: center; flex: none; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.variants { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.variant { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center; padding: 9px 10px 9px 14px; border-bottom: 1px solid var(--line); }
.variant:last-child { border-bottom: 0; }
.v-name { font-weight: 600; }
.v-actions { display: flex; gap: 4px; }
.colors { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.colors-title { font-weight: 650; margin-bottom: 8px; }
.color-head, .color-row { display: grid; grid-template-columns: 1fr 130px 34px; gap: 8px; align-items: center; }
.color-head { font-size: 12px; color: var(--muted); font-weight: 550; margin-bottom: 2px; }
.color-row { margin-bottom: 8px; }
.color-row input { margin: 0; }
.color-stock { padding-left: 4px; }
.add-color { padding: 0 8px; margin-left: -8px; }

/* ---------- movements ---------- */
.day { margin-bottom: 22px; }
.day-title { font-size: 12px; font-weight: 600; color: var(--muted); margin: 0 0 8px 2px; text-transform: capitalize; }
.mv-list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.mv { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.mv:last-child { border-bottom: 0; }
.mv .what { font-weight: 600; }
.mv .meta { font-size: 12.5px; color: var(--muted); }
.mv .qty { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.mv .qty.plus { color: var(--ok); }
.mv .qty.minus { color: var(--bad); }
.mv .after { font-size: 12.5px; color: var(--muted); text-align: right; }
.drawer .mv-list { border-radius: 10px; }
.drawer .mv { padding: 10px 14px; }

/* ---------- dialogs ---------- */
dialog { border: 0; border-radius: 16px; padding: 0; width: calc(100% - 32px); max-width: 500px; max-height: calc(100vh - 32px); background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(16, 24, 40, .45); }
dialog form { padding: 24px 28px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog-actions { display: flex; gap: 8px; align-items: center; margin-top: 24px; position: sticky; bottom: -24px; background: var(--surface); padding: 12px 0; margin-bottom: -12px; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; background: var(--surface-2); padding: 3px; border-radius: 10px; margin-top: 16px; border: 1px solid var(--line); }
.segmented button { height: 34px; border: 0; border-radius: 7px; background: none; font: inherit; font-weight: 600; color: var(--text-2); cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
input[type="file"] { margin-top: 12px; font: inherit; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 10px; font-weight: 550; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- tablet & phone ---------- */
@media (max-width: 1000px) {
  #appView:not([hidden]) { grid-template-columns: 72px 1fr; }
  .sidebar { padding: 16px 10px; align-items: center; }
  .sidebar .brand { padding: 0 0 12px; }
  .sidebar .label-full, .nav-label, .nav button span:not(.nav-count), .user-text { display: none; }
  .nav button { justify-content: center; padding: 11px; position: relative; }
  .nav-count { position: absolute; top: 2px; right: 2px; margin: 0; }
  .user-card { justify-content: center; border: 0; padding: 4px; }
  .menu.up { left: 0; right: auto; }
  .page { padding: 24px 20px 64px; }
}
@media (max-width: 760px) {
  #appView:not([hidden]) { display: block; padding-bottom: 72px; }
  .sidebar { position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: 64px; flex-direction: row; padding: 6px 8px; z-index: 25; border-right: 0; border-top: 1px solid var(--line); }
  .sidebar .brand { display: none; }
  .nav { flex-direction: row; justify-content: space-around; }
  .nav button { flex-direction: column; gap: 2px; padding: 6px 4px; font-size: 10.5px; }
  .nav button span:not(.nav-count) { display: block; }
  .sidebar-user { display: flex; align-items: center; }
  .menu.up { left: auto; right: 0; min-width: 200px; }
  .page { padding: 20px 16px 32px; }
  h1 { font-size: 22px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .list-head { display: none; }
  .row, .cat-row, .order-row, .customer-row { grid-template-columns: 1fr auto; padding: 12px 14px; row-gap: 4px; }
  .row .price { grid-column: 1; grid-row: 2; text-align: left; font-size: 13px; color: var(--text-2); }
  .row .stock-cell, .cat-row .status-cell, .order-row .status-cell { grid-column: 2; grid-row: 1 / span 2; }
  .order-row .when, .customer-row .hide-sm { display: none; }
  .page-head { align-items: flex-start; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; gap: 0; }
  .chips { width: 100%; overflow-x: auto; }
  .chips button { flex: 1; }
  .select { width: 100%; }
  .line, .lines-head { grid-template-columns: 1fr 60px 80px 32px; }
  .line .lt, .lines-head .lt { display: none; }
  dialog form { padding: 20px; }
}
.drawer .order-row { grid-template-columns: 1fr auto auto; padding: 10px 14px; }
.drawer .order-row .when { display: none; }
.brand-light { font-weight: 400; color: var(--text-2); }

/* date fields: Safari/WebKit adds its own inner offset; keep the value centered in the box */
input[type="date"] { text-align: center; }
input[type="date"]::-webkit-date-and-time-value { text-align: center; margin: 0; }
input[type="date"]::-webkit-datetime-edit { padding: 0; }
input[type="date"]::-webkit-datetime-edit-fields-wrapper { padding: 0; }
.date-inline { margin: 0; height: 36px; width: 160px; max-width: 100%; padding: 0 10px; }
.kv dd:has(.date-inline) { display: flex; align-items: center; }
.kv dt:has(+ dd > .date-inline) { align-self: center; }

.sub .due { color: var(--warn); font-weight: 600; }
.sub .paid { color: var(--ok); font-weight: 600; }
.totals .balance { font-weight: 700; }
.totals .balance.due { color: var(--warn); }
.totals .balance.paid { color: var(--ok); }
.deposit-edit { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; margin-top: 12px; }
.deposit-edit label { margin: 0; }
.total-box #oBalance { margin-top: 2px; }

/* ---------- admin ---------- */
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm); margin-bottom: 16px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.panel-head h2 { margin: 0; font-size: 16px; }
.usage-big { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; color: var(--text); }
.usage-bar { height: 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; margin: 12px 0 8px; }
.usage-bar > div { height: 100%; background: var(--accent); border-radius: 999px; min-width: 4px; }
.usage-bar.warn > div { background: var(--warn); }
.backup-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0 8px; }
.backup-status { display: flex; align-items: center; gap: 10px; color: var(--text); }
.backup-status .badge { flex: none; }
.stat-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.stat-table th, .stat-table td { text-align: right; padding: 9px 8px; border-bottom: 1px solid var(--line); }
.stat-table th:first-child, .stat-table td:first-child { text-align: left; }
.stat-table th { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat-table tr:last-child td { border-bottom: 0; }
.user-row { display: grid; grid-template-columns: 1fr 180px; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.user-row:last-child { border-bottom: 0; }
@media (max-width: 760px) { .admin-grid { grid-template-columns: 1fr; } .user-row { grid-template-columns: 1fr; } }

.lbl-short { display: none; }
@media (max-width: 1000px) { .nav button .lbl, .nav button .lbl-short { display: none !important; } }
@media (max-width: 760px) {
  .nav { gap: 0; }
  .nav button { flex: 1; min-width: 0; padding: 6px 2px; }
  .nav button .lbl-short { display: block !important; }
  .nav button span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .sidebar-user .user-card { padding: 2px; }
  .sidebar-user .avatar { width: 32px; height: 32px; }
}

.session-row { display: grid; grid-template-columns: 32px 1fr auto auto; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.session-row:last-child { border-bottom: 0; }
.device-ico { font-size: 22px; text-align: center; }
.session-state { text-align: right; }
.user-row { grid-template-columns: 1fr auto; }
.user-actions { display: flex; gap: 8px; align-items: center; }
.user-actions .select { width: 170px; margin: 0; }
@media (max-width: 760px) { .session-row { grid-template-columns: 28px 1fr; } .session-state, .session-row > .btn { grid-column: 2; text-align: left; justify-self: start; } .user-actions { flex-wrap: wrap; } }

/* color swatches */
.colors-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.swatches { display: inline-flex; gap: 4px; align-items: center; }
.sw { width: 14px; height: 14px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(16, 24, 40, .18); flex: none; position: relative; }
.sw.unknown { background: repeating-linear-gradient(45deg, var(--surface-2) 0 3px, var(--line-strong) 3px 5px); }
.sw.out { opacity: .35; }
.sw.out::after { content: ""; position: absolute; left: -2px; right: -2px; top: 50%; height: 1.5px; background: var(--text-2); transform: rotate(-45deg); }
.v-name { display: flex; align-items: center; gap: 8px; }
.tag .sw { margin-right: 6px; }

/* ---------- ads ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: var(--shadow); white-space: nowrap; opacity: 0; transition: opacity .1s; z-index: 2; }
.chart-tip b { display: block; font-size: 13px; margin-bottom: 2px; }
.legend { display: inline-flex; align-items: center; gap: 14px; }
.legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.table-scroll { overflow-x: auto; }
.stat-table th { cursor: pointer; user-select: none; white-space: nowrap; }
.stat-table th[aria-sort]::after { content: " ↓"; }
.stat-table th[aria-sort="ascending"]::after { content: " ↑"; }
.stat-table td { white-space: nowrap; }
.stat-table td:first-child { white-space: normal; min-width: 200px; }
.delta-up { color: var(--ok); font-weight: 600; }
.delta-down { color: var(--bad); font-weight: 600; }
:root { --series-1: #2a78d6; --series-2: #eb6834; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --series-1: #3987e5; --series-2: #d95926; } }
:root[data-theme="dark"] { --series-1: #3987e5; --series-2: #d95926; }
#adsMetaStats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (min-width: 1240px) { #adsMetaStats { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
@media (max-width: 760px) { #adsMetaStats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.click-row { cursor: pointer; }
.click-row:hover td { background: var(--surface-2); }
.ad-card { border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 12px; background: var(--surface); }
.ad-head { display: flex; gap: 12px; align-items: flex-start; }
.ad-thumb { width: 72px; height: 72px; border-radius: 8px; object-fit: cover; background: var(--surface-2); flex: none; border: 1px solid var(--line); }
.ad-thumb.empty { display: grid; place-items: center; font-size: 11px; color: var(--muted); text-align: center; }
.ad-info { min-width: 0; }
.ad-name { font-weight: 650; }
.ad-nums { font-size: 12.5px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.ad-text { font-size: 13px; color: var(--text-2); margin: 10px 0 0; white-space: pre-wrap; }
.ad-preview-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 12px; }
.chip-btn { height: 30px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text-2); font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.chip-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.ad-preview:not(:empty) { margin-top: 12px; }
.ad-iframe { display: block; width: 100%; max-width: 380px; height: 560px; border: 0; border-radius: 10px; background: var(--surface-2); margin: 0 auto; }
.ad-iframe.tall { height: 680px; }
.preview-demo { padding: 24px; border-radius: 10px; background: var(--surface-2); color: var(--muted); text-align: center; font-size: 13px; }
