:root {
  --bg: #f3f5f9;
  --panel: #ffffff;
  --line: #e2e6ee;
  --ink: #1e2534;
  --muted: #6b7280;
  --brand: #4f46e5;
  --brand-ink: #4338ca;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --info: #0ea5e9;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.1);
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body { font: 14px/1.45 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; color: var(--ink); background: var(--bg); }
.hidden { display: none !important; }
a { color: var(--brand-ink); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.app { display: flex; height: 100vh; }
.sidebar { width: 232px; background: #141927; color: #cbd2e0; display: flex; flex-direction: column; flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; border-bottom: 1px solid rgba(255,255,255,.07); }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: #dc2626; color: #fff; font-weight: 700; display: grid; place-items: center; font-size: 17px; }
.brand-name { font-weight: 600; color: #eef1f8; letter-spacing: .2px; }
.nav { flex: 1; padding: 10px 8px; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 5.5px 12px; border-radius: 9px; color: #b9c2d6; font-weight: 500; margin-bottom: 1px; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav a.active { background: rgba(79,70,229,.28); color: #fff; }
.nav .nav-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.nav-section { padding: 8px 12px 3px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: #7b8499; border-top: 1px solid rgba(255,255,255,.07); margin-top: 8px; }
.side-foot { padding: 12px; font-size: 11px; color: #7b8499; border-top: 1px solid rgba(255,255,255,.07); }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { height: 56px; background: var(--panel); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 22px; }
.view-title { font-size: 17px; font-weight: 650; }
.tb-right { display: flex; align-items: center; gap: 14px; }
.whoami { display: flex; flex-direction: column; align-items: flex-end; font-size: 12px; }
.whoami .u-name { font-weight: 600; font-size: 13px; }
.whoami .u-role { color: var(--brand-ink); font-weight: 600; }
.content { flex: 1; overflow: auto; padding: 20px 22px 60px; }
.page { max-width: 1280px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 19px; margin: 0; font-weight: 650; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ---------- Cards / grid ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { display: block; }
.kpi .k-val { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .k-lab { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi .k-sub { font-size: 11px; color: var(--brand); font-weight: 600; margin-top: 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; }
@media (max-width: 900px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.client-info { margin-bottom: 6px; }
.kv { width: 100%; border-collapse: collapse; }
.kv td { padding: 5px 12px 5px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.kv tr:last-child td { border-bottom: none; }
.kv-k { color: var(--muted); white-space: nowrap; width: 1%; }
.rel-list { display: flex; flex-direction: column; gap: 6px; margin: 4px 0 14px; }
.rel-item { display: flex; align-items: center; gap: 6px; }

/* ---------- Forms ---------- */
.form { display: grid; gap: 12px; }
.f-check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #374151; cursor: pointer; }
.f-check input { flex: 0 0 auto; }
.form2 { grid-template-columns: 1fr 1fr; }
.f-field { display: flex; flex-direction: column; gap: 5px; }
  .f-field > label { font-size: 12px; font-weight: 600; color: #374151; }
  .f-group { grid-column: 1 / -1; margin: 10px 0 2px; }
  .f-group .f-sub { font-size: 12px; font-weight: 700; letter-spacing: .3px; color: var(--brand-ink); padding: 6px 10px; background: #eef0ff; border-radius: 6px; }
.f-hint { font-size: 11px; color: var(--muted); }
input, select, textarea {
  padding: 8px 10px; border: 1px solid #d3d9e3; border-radius: 8px; font: inherit; background: #fff; width: 100%; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(79,70,229,.35); border-color: var(--brand); }
textarea { resize: vertical; min-height: 64px; }
input[readonly] { background: #f1f3f8; }
.f-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line); background: #fff; font: inherit; font-weight: 550; cursor: pointer; color: var(--ink); }
.btn:hover { border-color: #c3c9d6; }
.pt-info { grid-column: 1 / -1; margin-top: 4px; background: #eef0ff; border-radius: 8px; padding: 8px 12px; display: flex; flex-direction: column; gap: 5px; }
  .pt-info .pt-row { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
  .pt-info .pt-row span { color: var(--muted); }
  .pt-info .pt-row b { font-weight: 600; color: var(--brand-ink); text-align: right; }
  .cq { position: relative; }
  .cq .cq-list { position: absolute; left: 0; right: 0; top: 100%; margin-top: 4px; background: #fff; border: 1px solid #d6d9e4; border-radius: 8px; max-height: 260px; overflow-y: auto; z-index: 60; box-shadow: 0 8px 24px rgba(15,23,42,.14); }
  .cq .cq-item { display: block; width: 100%; text-align: left; padding: 8px 12px; font-size: 13px; background: none; border: 0; cursor: pointer; }
  .cq .cq-item:hover { background: #eef0ff; }
  .cq .cq-empty { padding: 8px 12px; font-size: 13px; color: var(--muted); }
  .cq-new { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 13px; color: var(--muted); cursor: pointer; }
  .cq-new input { width: auto; margin: 0; }
  .filters { display: flex; gap: 8px; flex-wrap: wrap; }
  .filters .fselect { width: auto; min-width: 170px; max-width: 240px; }
  .badge.b-min { font-size: 10px; padding: 1px 6px; letter-spacing: .3px; }
  .stgl { min-width: 86px; justify-content: center; }
  .stgl-on { background: #16a34a; border-color: #16a34a; color: #fff; }
  .stgl-on:hover { background: #15803d; border-color: #15803d; }
  .stgl-off { background: #e5e7eb; border-color: #d1d5db; color: #6b7280; }
  .stgl-off:hover { background: #d1d5db; }
  .form-submit { width: 100%; margin-top: 12px; justify-content: center; grid-column: 1 / -1; }
  .f-parent { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .f-parent.hidden { display: none !important; }
  .btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
  .btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
  .btn-primary.is-danger { background: #dc2626; border-color: #dc2626; }
  .btn-primary.is-danger:hover { background: #b91c1c; }
  .btn.is-violet { background: #8773A1; border-color: #8773A1; color: #fff; }
  .btn.is-violet:hover { background: #76608F; }
.btn-primary:hover { background: var(--brand-ink); }
.btn-danger { background: #fff; border-color: #f0c4c4; color: var(--bad); }
.btn-danger:hover { background: #fef2f2; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--brand-ink); }
.btn-sm { padding: 4px 9px; font-size: 12.5px; border-radius: 7px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Table ---------- */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid #eef1f6; vertical-align: middle; }
.tbl tr:hover td { background: #fafbff; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .actions { display: flex; gap: 6px; white-space: nowrap; justify-content: flex-end; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12px; }
.nowrap { white-space: nowrap; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.b-ok { background: #e7f7ec; color: #128a3e; }
.b-warn { background: #fdf3e3; color: #b4690e; }
.b-bad { background: #fdeaea; color: #c22020; }
.b-info { background: #e4f4fd; color: #0b74a8; }
.b-muted { background: #eef1f6; color: #5b6472; }
.b-brand { background: #e8e8ff; color: var(--brand-ink); }

/* ---------- Dashboards ---------- */
.shortcuts { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.alert-item { display: flex; gap: 10px; padding: 10px 12px; border-bottom: 1px solid #eef1f6; }
.alert-item:last-child { border-bottom: none; }
.alert-item .al-title { font-weight: 600; font-size: 13px; }
.chart-bar-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 12px; }
.chart-bar { height: 18px; background: var(--brand); border-radius: 5px; min-width: 2px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; }
.login-card { width: 380px; max-width: 92vw; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 30px; }
.login-card .l-title { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.login-card .l-sub { color: var(--muted); margin-bottom: 20px; font-size: 13px; }
.login-err { background: #fdeaea; color: #c22020; border-radius: 9px; padding: 9px 12px; font-size: 13px; margin-top: 12px; display: none; }
.login-err.show { display: block; }
.pw-wrap { position: relative; display: flex; align-items: center; }
.pw-wrap input { padding-right: 42px; width: 100%; box-sizing: border-box; }
.pw-eye { position: absolute; right: 4px; background: none; border: none; cursor: pointer; font-size: 16px; opacity: .6; padding: 6px; border-radius: 8px; }
.pw-eye:hover { opacity: 1; background: #eef1f6; }
.pw-eye.on { opacity: 1; }
.login-card .hint { color: var(--muted); font-size: 12px; margin-top: 6px; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,20,35,.45); display: grid; place-items: center; z-index: 50; }
.modal { background: #fff; border-radius: 14px; width: 520px; max-width: 94vw; max-height: 88vh; overflow: auto; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal.m-wide { width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; align-items: center; }
.modal-foot .form-submit { width: auto; margin: 0; min-width: 120px; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 99; }
.toast { background: #161d2e; color: #fff; padding: 10px 14px; border-radius: 10px; font-size: 13px; box-shadow: var(--shadow); animation: toast-in .18s ease-out; max-width: 380px; }
.toast.ok { border-left: 4px solid var(--ok); }
.toast.err { border-left: 4px solid var(--bad); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Misc ---------- */
.loading { color: var(--muted); padding: 26px; text-align: center; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding-top: 12px; }
.empty { padding: 26px; text-align: center; color: var(--muted); }
.seg { display: inline-flex; background: #eef1f6; border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { border: none; background: transparent; padding: 6px 12px; border-radius: 7px; font: inherit; font-weight: 550; cursor: pointer; color: var(--muted); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.subline { font-size: 12px; margin-top: 2px; }
