/* MikroTik Voucher System: UI styles. Light and dark themes via CSS variables.
   No inline styles are used anywhere in the UI (strict CSP). */
:root {
  --bg: #f4f6f9; --surface: #ffffff; --surface-2: #eef1f6; --border: #dfe4ec; --border-strong: #c9d1de;
  --text: #17202e; --muted: #5d6a82; --accent: #0d7a85; --accent-hover: #0a626b; --accent-weak: #dff1f3; --on-accent: #ffffff;
  --danger: #b4281c; --danger-weak: #fde9e7; --warn: #8a5a00; --warn-weak: #fff3d6; --ok: #17773f; --ok-weak: #e0f5e9;
  --info: #1f55c9; --info-weak: #e6eefc; --muted-weak: #eceff4;
  --sidebar: #0f1b2d; --sidebar-text: #b9c5d8; --sidebar-active: #1b2d49; --sidebar-border: #1d2b43;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08); --shadow-lg: 0 12px 32px rgba(16,24,40,.22);
  --radius: 10px; --radius-sm: 6px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --c1: #0d7a85; --c2: #d9831f; --c3: #6b5bd2; --c4: #2c9a5b; --c5: #c2410c; --c6: #8b5cf6;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0c121c; --surface: #141c2a; --surface-2: #1b2536; --border: #263249; --border-strong: #34425d;
  --text: #e6ebf3; --muted: #93a1ba; --accent: #34b6c3; --accent-hover: #5ccad6; --accent-weak: #12373d; --on-accent: #06242a;
  --danger: #ff8f84; --danger-weak: #3a1a18; --warn: #f0b955; --warn-weak: #3a2c0d; --ok: #62d68f; --ok-weak: #12301f;
  --info: #8db1ff; --info-weak: #18284a; --muted-weak: #1f2a3d;
  --sidebar: #0a111c; --sidebar-active: #172338; --sidebar-border: #162033;
  --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 12px 32px rgba(0,0,0,.6);
  --c1: #34b6c3; --c2: #f0a24a; --c3: #9a8cf0; --c4: #5ccb8a; --c5: #f08a5c; --c6: #b794f6;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c121c; --surface: #141c2a; --surface-2: #1b2536; --border: #263249; --border-strong: #34425d;
    --text: #e6ebf3; --muted: #93a1ba; --accent: #34b6c3; --accent-hover: #5ccad6; --accent-weak: #12373d; --on-accent: #06242a;
    --danger: #ff8f84; --danger-weak: #3a1a18; --warn: #f0b955; --warn-weak: #3a2c0d; --ok: #62d68f; --ok-weak: #12301f;
    --info: #8db1ff; --info-weak: #18284a; --muted-weak: #1f2a3d;
    --sidebar: #0a111c; --sidebar-active: #172338; --sidebar-border: #162033;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 12px 32px rgba(0,0,0,.6);
    --c1: #34b6c3; --c2: #f0a24a; --c3: #9a8cf0; --c4: #5ccb8a; --c5: #f08a5c; --c6: #b794f6;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 14px; line-height: 1.45; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
a { color: var(--accent); }
code, .mono { font-family: var(--mono); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); } .small { font-size: 12px; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 248px; flex: 0 0 248px; background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 30; }
.brand { padding: 18px 20px; display: flex; gap: 10px; align-items: center; color: #fff; font-weight: 700; font-size: 15px; border-bottom: 1px solid var(--sidebar-border); }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: var(--on-accent); flex: none; }
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav { padding: 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.nav a, .nav button { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px; color: var(--sidebar-text); text-decoration: none; background: none; border: 0; cursor: pointer; text-align: left; width: 100%; font-weight: 500; }
.nav a:hover, .nav button:hover { background: var(--sidebar-active); color: #fff; }
.nav a[aria-current="page"] { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav .spacer { flex: 1; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar h1 { font-size: 18px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn { display: none; }
.view { padding: 24px; max-width: 1400px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
.overlay { display: none; }
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  .nav-open .sidebar { transform: none; }
  .nav-open .overlay { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 25; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; } .view { padding: 16px; }
}

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h2 { flex: 1; min-width: 120px; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.kpi { padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; }
.kpi.accent { border-left: 4px solid var(--accent); } .kpi.warn { border-left: 4px solid var(--warn); } .kpi.danger { border-left: 4px solid var(--danger); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; font-weight: 600; text-decoration: none; color: var(--text); min-height: 36px; }
.btn:hover { background: var(--surface-2); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; } .btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 4px 10px; min-height: 28px; font-size: 12px; }
.btn.block { width: 100%; }
.login-mark { width: 44px; height: 44px; }
.btn.lg { padding: 12px 20px; font-size: 16px; min-height: 46px; }
.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-ok { background: var(--ok-weak); color: var(--ok); } .b-warn { background: var(--warn-weak); color: var(--warn); }
.b-danger { background: var(--danger-weak); color: var(--danger); } .b-info { background: var(--info-weak); color: var(--info); }
.b-muted { background: var(--muted-weak); color: var(--muted); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.dot.ok { background: var(--ok); } .dot.danger { background: var(--danger); } .dot.warn { background: var(--warn); }
.pill { display: inline-flex; align-items: center; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); font-size: 12px; font-weight: 600; }
.alert { padding: 12px 16px; border-radius: var(--radius-sm); border: 1px solid; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.alert .grow { flex: 1; min-width: 200px; }
.alert.warn { background: var(--warn-weak); color: var(--warn); border-color: var(--warn); }
.alert.danger { background: var(--danger-weak); color: var(--danger); border-color: var(--danger); }
.alert.info { background: var(--info-weak); color: var(--info); border-color: var(--info); }
.alert.ok { background: var(--ok-weak); color: var(--ok); border-color: var(--ok); }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; background: var(--surface-2); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; } tbody tr.clickable:hover { background: var(--surface-2); }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }
.pager { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--border); justify-content: flex-end; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.pager .grow { flex: 1; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--border); align-items: end; }
.filters label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); font-weight: 600; }
.filters .btn { align-self: end; }

/* forms */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field > label, .field > .lbl { font-weight: 600; font-size: 13px; }
.field .hint { color: var(--muted); font-size: 12px; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="search"], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); min-height: 36px; }
.filters input, .filters select { min-width: 140px; width: auto; }
textarea { min-height: 70px; resize: vertical; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.check input { width: 16px; height: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; } .row > * { flex: 1; min-width: 160px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 5px 12px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; font-weight: 600; font-size: 13px; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding: 0 12px; flex-wrap: wrap; }
.tab { padding: 10px 14px; border: 0; background: none; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

/* modal and toast */
.modal-backdrop { position: fixed; inset: 0; background: rgba(8,14,24,.55); display: grid; place-items: center; z-index: 100; padding: 16px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 520px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); gap: 12px; }
.modal-head h2 { flex: 1; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; max-width: min(420px, calc(100vw - 32px)); }
.toast { padding: 12px 16px; border-radius: 8px; background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg); font-weight: 500; }
.toast.ok { background: var(--ok); color: #fff; } .toast.error { background: var(--danger); color: #fff; } .toast.warn { background: var(--warn); color: #fff; }

/* data display */
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; margin: 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }
.secret { font-family: var(--mono); font-size: 20px; font-weight: 700; letter-spacing: .06em; padding: 10px 14px; background: var(--surface-2); border-radius: 8px; border: 1px dashed var(--border-strong); display: inline-block; user-select: all; }
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { display: flex; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--border); align-items: flex-start; }
.checklist li:last-child { border-bottom: 0; }
.checklist .grow { flex: 1; } .checklist .t { font-weight: 600; }
pre.json { margin: 0; padding: 10px; background: var(--surface-2); border-radius: 6px; overflow: auto; max-height: 220px; font-size: 12px; font-family: var(--mono); white-space: pre-wrap; word-break: break-word; }
.skeleton { height: 90px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* charts */
.chart { width: 100%; height: auto; display: block; }
.chart text { font-size: 11px; fill: var(--muted); font-family: var(--font); }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis { stroke: var(--border-strong); }
.chart .bar { fill: var(--c1); } .chart .bar:hover { opacity: .8; }
.chart .line { fill: none; stroke: var(--c1); stroke-width: 2.5; stroke-linejoin: round; }
.chart .area { fill: var(--c1); opacity: .12; }
.chart .pt { fill: var(--c1); }
.chart .val { fill: var(--text); font-weight: 600; }
.f1 { fill: var(--c1); } .f2 { fill: var(--c2); } .f3 { fill: var(--c3); } .f4 { fill: var(--c4); } .f5 { fill: var(--c5); } .f6 { fill: var(--c6); }
.bg1 { background: var(--c1); } .bg2 { background: var(--c2); } .bg3 { background: var(--c3); } .bg4 { background: var(--c4); } .bg5 { background: var(--c5); } .bg6 { background: var(--c6); }
.legend { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.legend li { display: flex; gap: 8px; align-items: center; } .legend .sw { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.donut-wrap { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; justify-content: center; padding: 8px; }

/* receipt / voucher */
.receipt { text-align: center; padding: 24px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.receipt .qr { width: 160px; height: 160px; background: #fff; padding: 6px; border-radius: 8px; border: 1px solid var(--border); }
.package-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.package-card { padding: 16px; text-align: left; cursor: pointer; border: 2px solid var(--border); border-radius: var(--radius); background: var(--surface); display: flex; flex-direction: column; gap: 4px; }
.package-card:hover:not(:disabled) { border-color: var(--accent); }
.package-card[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-weak); }
.package-card:disabled { opacity: .5; cursor: not-allowed; }
.package-card .p-name { font-weight: 700; font-size: 16px; } .package-card .p-price { font-size: 20px; font-weight: 700; color: var(--accent); }

/* login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--bg); }
.login-card { width: 100%; max-width: 400px; padding: 28px; }
.login-card h1 { margin: 14px 0 4px; } .seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 8px; margin: 18px 0; }
.seg button { padding: 8px; border: 0; background: none; border-radius: 6px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.form-error { color: var(--danger); min-height: 20px; margin: 4px 0 8px; font-weight: 500; }
.pw-wrap { position: relative; } .pw-wrap button { position: absolute; right: 4px; top: 4px; }

/* print: voucher cards */
#print-area { display: none; }
@media print {
  body.printing > *:not(#print-area) { display: none !important; }
  body.printing { background: #fff; color: #000; }
  body.printing #print-area { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4mm; padding: 0; }
  .vcard { border: 1px dashed #666; border-radius: 3mm; padding: 4mm; break-inside: avoid; display: flex; flex-direction: column; gap: 1.5mm; color: #000; background: #fff; font-family: var(--font); }
  .vcard .vc-biz { font-weight: 700; font-size: 11pt; } .vcard .vc-pkg { font-size: 9pt; }
  .vcard .vc-code { font-family: var(--mono); font-size: 14pt; font-weight: 700; letter-spacing: .08em; }
  .vcard img { width: 24mm; height: 24mm; } .vcard .vc-foot { font-size: 7pt; color: #333; }
}
.vcard { }

/* Salesperson: package picker and receipt */
.pkgs { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.pkg { text-align: left; cursor: pointer; padding: 16px; display: flex; flex-direction: column; gap: 4px; font: inherit; color: inherit; border: 1px solid var(--border); background: var(--surface); }
.pkg:hover:not(:disabled) { border-color: var(--accent); }
.pkg:disabled { opacity: .55; cursor: not-allowed; }
.pkg-name { font-weight: 650; font-size: 1.05rem; }
.pkg-price { font-size: 1.35rem; font-weight: 700; margin-top: 6px; }
.kpi-big { font-size: 1.9rem; font-weight: 700; margin: 4px 0 8px; }
.danger-text { color: var(--danger); }
.receipt-cred { display: flex; flex-wrap: wrap; gap: 20px; align-items: center; margin: 12px 0 16px; }
.receipt-cred .qr { width: 160px; height: 160px; background: #fff; padding: 6px; border-radius: 8px; border: 1px solid var(--border); }
