:root {
  --bg: #f3f5f8; --panel: #fff; --text: #14202b; --muted: #6b7a88; --line: #e3e8ee; --soft: #f6f8fa;
  --brand: #0f766e; --brand-d: #0b5c56; --red: #dc2626; --green: #16a34a; --amber: #d97706; --blue: #2563eb;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1115; --panel: #131c23; --text: #e8eef3; --muted: #8b9ba8; --line: #23313b; --soft: #18242d; --brand: #14b8a6; --brand-d: #0f9d8e; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
textarea { min-height: 120px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; }
input[type=checkbox] { width: auto; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 12px; cursor: pointer; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--brand-d); }
.btn.danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, var(--line)); }
.btn.sm { padding: 3px 9px; font-size: .85rem; }
.btn.wide { width: 100%; padding: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.linklike { background: none; border: 0; color: var(--brand); cursor: pointer; padding: 0; text-decoration: underline; }
.muted { color: var(--muted); font-size: .86rem; }
.err { color: var(--red); min-height: 1.4em; }

#login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); padding: 26px; border-radius: 14px; border: 1px solid var(--line); }
.login-card h1 { margin: 0 0 16px; font-size: 1.4rem; color: var(--brand); }
label { display: block; margin-bottom: 12px; font-size: .88rem; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--text); }
label.chk { display: flex; align-items: flex-start; gap: 8px; color: var(--text); }
label.chk input { margin-top: 5px; }

#shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
#side { background: var(--panel); border-right: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; gap: 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; flex-direction: column; padding: 0 8px; }
.brand b { font-size: 1.15rem; color: var(--brand); }
#nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
#nav button { text-align: left; padding: 9px 12px; border: 0; background: none; border-radius: 8px; cursor: pointer; }
#nav button:hover { background: var(--soft); }
#nav button.on { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); font-weight: 600; }
.side-foot { display: flex; justify-content: space-between; padding: 0 8px; font-size: .88rem; }
#main { padding: 22px; min-width: 0; outline: none; }
#main h1 { margin: 0 0 16px; font-size: 1.4rem; }
#main h2 { margin: 24px 0 10px; font-size: 1.05rem; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.stat .n { font-size: 1.7rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: .85rem; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.chart { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.chart h3 { margin: 0 0 8px; font-size: .95rem; }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 110px; }
.bars i { flex: 1; background: var(--c, var(--brand)); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.bars i:last-child { opacity: 1; }
.axis { display: flex; justify-content: space-between; color: var(--muted); font-size: .75rem; margin-top: 4px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar input[type=search], .toolbar input[type=text] { width: 220px; }
.toolbar select { width: auto; }
.toolbar label { margin: 0; display: flex; gap: 6px; align-items: center; color: var(--text); }
.toolbar .grow { flex: 1; }
.tbl-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; }
table { border-collapse: collapse; width: 100%; min-width: 640px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; background: var(--soft); }
tr:last-child td { border-bottom: 0; }
td.wrap { white-space: normal; min-width: 220px; max-width: 480px; overflow-wrap: anywhere; }
td.acts { display: flex; gap: 6px; }
.empty { text-align: center; color: var(--muted); padding: 28px; }
.tag { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: .78rem; background: var(--soft); border: 1px solid var(--line); }
.tag.green { color: var(--green); } .tag.red { color: var(--red); } .tag.amber { color: var(--amber); } .tag.blue { color: var(--blue); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--line); margin-right: 6px; }
.dot.on { background: var(--green); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 14px; max-width: 760px; }
.panel h2 { margin-top: 0 !important; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.hint { color: var(--muted); font-size: .82rem; margin: -6px 0 12px; }
.warn { background: #fef3c7; color: #78350f; padding: 10px 12px; border-radius: 8px; font-size: .88rem; margin-bottom: 12px; }
.purge { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.purge input { width: 90px; }

#modal-wrap { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); display: grid; place-items: center; padding: 16px; z-index: 30; }
#modal { background: var(--panel); border-radius: 14px; padding: 20px; width: 100%; max-width: 440px; max-height: 92vh; overflow-y: auto; }
#modal h3 { margin: 0 0 14px; }
.modal-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
#toast { position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px); background: #1f2c35; color: #fff; padding: 10px 18px; border-radius: 999px; opacity: 0; pointer-events: none; transition: .25s; z-index: 50; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 800px) {
  #shell { grid-template-columns: 1fr; }
  #side { position: static; height: auto; flex-direction: column; padding: 10px; }
  #nav { flex-direction: row; overflow-x: auto; gap: 4px; }
  #nav button { white-space: nowrap; }
  #main { padding: 14px; }
  .grid2 { grid-template-columns: 1fr; }
}

/* Billing additions */
.stat.hl { border-color: color-mix(in srgb, var(--brand) 45%, var(--line)); }
.stat.alert { border-color: var(--amber); cursor: pointer; }
.stat[role=button] { cursor: pointer; }
.amt.pos { color: var(--green); font-weight: 600; } .amt.neg { color: var(--red); font-weight: 600; }
.nbadge { font-style: normal; background: var(--red); color: #fff; border-radius: 999px; font-size: .72rem; padding: 0 7px; margin-left: 6px; }
.calc table { min-width: 0; } .calc td, .calc th { padding: 6px 12px; }
