:root {
  color-scheme: light;
  --bg: #f2f4f8; --surface: #ffffff; --surface-2: #eef1f7; --border: #dde3ee;
  --text: #0b1630; --text-2: #4a5470; --muted: #7a839c;
  --nav: #0a1f44; --nav-text: #c3cfe6; --nav-active: #15315f; --brand: #f47c20; --brand-ink: #0a1f44;
  --accent: #ee7420; --accent-ink: #0a1f44;   /* orange buttons, navy text (5:1) */
  --link: #1b3f8f;
  --s1: #2a78d6; --s2: #eb6834;
  --good: #11875d; --good-bg: #e3f4ec; --warn: #9a6500; --warn-bg: #fbf0d9;
  --bad: #c23b3a; --bad-bg: #fbe5e4; --info-bg: #e5eefa;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 0 0 1px var(--border);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0a1020; --surface: #111a2e; --surface-2: #18233b; --border: #26324e;
    --text: #eef2fa; --text-2: #b7c1d8; --muted: #8590ab;
    --nav: #060d1d; --nav-text: #aab8d4; --nav-active: #13264a; --brand: #f7913a; --brand-ink: #0a1630;
    --accent: #f7913a; --accent-ink: #0a1630;
    --link: #9ab9f5;
    --s1: #3987e5; --s2: #d95926;
    --good: #4cc995; --good-bg: #15302a; --warn: #e8b04a; --warn-bg: #33290f;
    --bad: #ef7d7c; --bad-bg: #3a1a1a; --info-bg: #17253a;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

/* layout */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side { background: var(--nav); color: var(--nav-text); padding: 18px 12px; position: sticky; top: 0; height: 100vh;
  overflow-y: auto; }
.logo { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 16px;
  padding: 4px 10px 18px; }
.logo span { width: 28px; height: 28px; border-radius: 8px; background: var(--brand); display: grid; place-items: center;
  color: var(--brand-ink); font-size: 15px; font-weight: 800; }
.side .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; opacity: .55; margin: 16px 10px 6px; }
.side a { display: flex; align-items: center; gap: 10px; color: var(--nav-text); padding: 7px 10px; border-radius: 7px; }
.side a:hover { background: var(--nav-active); text-decoration: none; color: #fff; }
.side a.on { background: var(--nav-active); color: #fff; box-shadow: inset 3px 0 0 var(--brand); }
.side svg { width: 17px; height: 17px; flex: none; opacity: .85; }
.main { min-width: 0; }
.top { display: flex; align-items: center; gap: 16px; padding: 14px 28px; background: var(--surface);
  border-bottom: 1px solid var(--border); box-shadow: inset 0 3px 0 var(--brand); position: sticky; top: 0; z-index: 5; }
.top form { flex: 1; max-width: 420px; }
.top .who { margin-left: auto; color: var(--text-2); display: flex; gap: 14px; align-items: center; }
.top .menu-btn { display: none; }
.page { padding: 24px 28px 48px; max-width: 1400px; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.head .sub { color: var(--text-2); margin-top: 2px; }

/* building blocks */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-side { grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; margin-bottom: 16px; }
.kpi { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.kpi .l { color: var(--text-2); font-size: 12.5px; }
.kpi .v { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .n { color: var(--muted); font-size: 12px; }
.kpi a.v { color: var(--text); display: block; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; color: var(--text-2); font-size: 12px; text-transform: uppercase;
  letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.mono, td .mono { white-space: nowrap; }
.table-wrap { overflow-x: auto; margin: -6px -10px; }
.empty { color: var(--muted); padding: 22px 10px; text-align: center; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 99px; font-size: 12px;
  font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.b-active, .b-paid, .b-online, .b-closed.ok { background: var(--good-bg); color: var(--good); }
.b-suspended, .b-unpaid, .b-pending, .b-high { background: var(--warn-bg); color: var(--warn); }
.b-disabled, .b-void, .b-reject, .b-offline { background: var(--bad-bg); color: var(--bad); }
.b-lead, .b-open { background: var(--info-bg); color: var(--s1); }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: 7px 13px; border-radius: 8px; font: inherit; font-weight: 550; cursor: pointer;
  white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 3px 9px; font-size: 12.5px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; margin: 0; }

label { display: block; font-size: 12.5px; color: var(--text-2); font-weight: 550; margin-bottom: 4px; }
input, select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent);
  border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 14px; }
.fields .wide { grid-column: 1 / -1; }
.field-row { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.field-row > div { flex: 1; min-width: 140px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--text); }
.check input { width: auto; }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: var(--good-bg); color: var(--good);
  font-weight: 550; word-break: break-word; }
.flash.err { background: var(--bad-bg); color: var(--bad); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }

.dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
.dl dt { color: var(--text-2); }
.dl dd { margin: 0; word-break: break-word; }
.tabs { display: flex; gap: 4px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 5px 12px; border-radius: 99px; color: var(--text-2); }
.tabs a.on { background: var(--surface); box-shadow: var(--shadow); color: var(--text); font-weight: 600; }
details.box { border: 1px dashed var(--border); border-radius: 8px; padding: 10px 14px; margin-top: 12px; }
details.box summary { cursor: pointer; font-weight: 600; }
pre.code { background: var(--surface-2); padding: 14px; border-radius: 8px; overflow-x: auto; font-size: 12.5px; margin: 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.on { background: var(--good); }
.muted { color: var(--muted); }
.right { text-align: right; }

/* bar chart */
.viz-legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-2); margin-bottom: 10px; }
.viz-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px;
  vertical-align: -1px; }
.bars { display: flex; align-items: flex-end; gap: 10px; height: 180px; border-bottom: 1px solid var(--border);
  padding-top: 8px; }
.bars .col { flex: 1; display: flex; flex-direction: column; align-items: stretch; height: 100%; position: relative; }
.bars .pair { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 2px; }
.bars .bar { width: min(26px, 40%); border-radius: 4px 4px 0 0; }
.bars .stack { width: 100%; display: flex; flex-direction: column-reverse; gap: 2px; }
.bars .stack .bar { width: 100%; border-radius: 0; }
.bars .stack .bar:last-child { border-radius: 3px 3px 0 0; }
.bars.dense { gap: 3px; }
.bars .col:hover .bar { filter: brightness(1.12); }
.bars .col:hover::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 4px); left: 50%;
  transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 5px 8px; border-radius: 6px;
  font-size: 12px; white-space: pre; z-index: 3; pointer-events: none; }
.x-labels { display: flex; gap: 10px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.x-labels span { flex: 1; text-align: center; }
.bars.dense + .x-labels { gap: 3px; }
.f1 { background: var(--s1); } .f2 { background: var(--s2); }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth .card { width: 100%; max-width: 380px; padding: 28px; }
.auth .logo { color: var(--text); padding: 0 0 18px; }

/* portal */
.portal-top { background: var(--nav); color: #fff; border-bottom: 3px solid var(--brand); }
.portal-top .in { max-width: 1040px; margin: 0 auto; display: flex; align-items: center; gap: 20px; padding: 14px 20px; }
.portal-top .logo { padding: 0; }
.portal-top nav { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.portal-top nav a { color: var(--nav-text); padding: 6px 10px; border-radius: 7px; }
.portal-top nav a:hover, .portal-top nav a.on { background: var(--nav-active); color: #fff; text-decoration: none; }
.portal { max-width: 1040px; margin: 0 auto; padding: 24px 20px 60px; }

/* thread */
.msg { padding: 12px 14px; border-radius: 10px; background: var(--surface-2); margin-bottom: 10px; max-width: 760px; }
.msg.cust { background: var(--info-bg); }
.msg .meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.msg .body { white-space: pre-wrap; }

/* invoice */
.invoice { max-width: 820px; margin: 24px auto; background: #fff; color: #111; padding: 44px; border-radius: 10px;
  box-shadow: var(--shadow); }
.invoice table th { color: #555; border-color: #ddd; } .invoice table td { border-color: #eee; }
.invoice .totals { margin-left: auto; width: 300px; margin-top: 12px; }
.invoice .totals td { border: 0; padding: 4px 10px; }
.invoice .totals tr.grand td { font-size: 17px; font-weight: 700; border-top: 2px solid #111; }
.inv-head { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 30px; }
.pre { white-space: pre-line; }
.noprint { max-width: 820px; margin: 18px auto 0; display: flex; gap: 8px; }
@media print {
  .noprint { display: none; }
  body { background: #fff; }
  .invoice { box-shadow: none; margin: 0; padding: 0; max-width: none; }
}

@media (max-width: 1000px) {
  .g-side, .g2, .g3 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; width: 240px; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .side { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .top .menu-btn { display: inline-flex; }
  .top { padding: 10px 16px; }
  .top .who span { display: none; }
  .page { padding: 16px; }
  .invoice { padding: 22px; margin: 12px 16px; }
  .inv-head { flex-direction: column; }
  .invoice .totals { width: 100%; }
  .bars { gap: 4px; }
}

/* sidebar counter */
.side a .count { margin-left: auto; background: var(--brand); color: var(--brand-ink); border-radius: 99px;
  font-size: 11.5px; padding: 0 7px; line-height: 18px; font-weight: 700; }

/* WhatsApp inbox */
.wa-list a.row { display: flex; gap: 12px; padding: 12px 10px; border-bottom: 1px solid var(--border); color: var(--text); }
.wa-list a.row:hover { background: var(--surface-2); text-decoration: none; }
.wa-list a.row:last-child { border-bottom: 0; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--nav); color: #fff; display: grid;
  place-items: center; font-weight: 700; flex: none; }
.wa-list .meta { flex: 1; min-width: 0; }
.wa-list .line1 { display: flex; gap: 8px; align-items: baseline; }
.wa-list .line1 strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wa-list .when { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.wa-list .preview { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.unread { background: var(--brand); color: var(--brand-ink); border-radius: 99px; font-size: 11.5px; padding: 0 7px;
  font-weight: 700; line-height: 18px; }
.chat { display: flex; flex-direction: column; height: calc(100vh - 210px); min-height: 420px; padding: 0; overflow: hidden; }
.thread { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 6px;
  background: var(--surface-2); }
.bubble { max-width: min(560px, 80%); padding: 8px 12px; border-radius: 12px; word-break: break-word;
  box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.bubble.in { align-self: flex-start; background: var(--surface); border-top-left-radius: 4px; }
.bubble.out { align-self: flex-end; background: #ffe7d3; color: #2a1606; border-top-right-radius: 4px; }
.bubble.bot { background: #dfe8fa; color: #0b1630; }
.bubble.failed { outline: 2px solid var(--bad); }
.bubble .txt { white-space: pre-wrap; }
.bubble .bmeta { display: block; font-size: 11px; opacity: .65; margin-top: 3px; text-align: right; white-space: nowrap; }
.bubble img { max-width: 260px; max-height: 260px; border-radius: 8px; display: block; margin-bottom: 4px; }
.day-sep { align-self: center; font-size: 11.5px; color: var(--muted); background: var(--surface); padding: 2px 10px;
  border-radius: 99px; margin: 8px 0; }
.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); background: var(--surface); align-items: end; }
.composer textarea { min-height: 42px; max-height: 160px; height: 42px; }
.window-note { padding: 10px 14px; background: var(--warn-bg); color: var(--warn); font-size: 13px;
  border-top: 1px solid var(--border); display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
@media (prefers-color-scheme: dark) {
  .bubble.out { background: #5a2e10; color: #fff3e8; }
  .bubble.bot { background: #1c2d52; color: #e7eefc; }
}
@media (max-width: 760px) { .chat { height: calc(100vh - 170px); } }

/* monitoring charts */
.side a .count.alarm { background: var(--bad); color: #fff; }
.mchart { position: relative; min-height: 220px; }
.mcharts .mchart + .mchart { margin-top: 0; }
.mchart-head { display: flex; gap: 14px; align-items: baseline; flex-wrap: wrap; margin-bottom: 6px; }
.mchart-now { margin-left: auto; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.mchart svg { display: block; overflow: visible; touch-action: pan-y; }
.mchart-tip { position: absolute; top: 40px; background: var(--surface); box-shadow: var(--shadow), 0 4px 14px rgba(0,0,0,.12);
  border-radius: 8px; padding: 6px 10px; font-size: 12.5px; pointer-events: none; white-space: nowrap; z-index: 4; }
.mchart-tip i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; }
.mchart-tip b { font-variant-numeric: tabular-nums; }
.badge.b-none { background: var(--surface-2); color: var(--muted); }

/* live (RouterOS API) charts */
.lchart { position: relative; }
.lchart-body svg { display: block; overflow: visible; touch-action: pan-y; }
.meter-sm { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.meter-sm i { display: block; height: 100%; background: var(--s1); border-radius: 99px; }
.meter-sm i.hot { background: var(--s2); }
