:root {
  --bg: #f6f4ef; --surface: #ffffff; --surface-2: #faf8f4; --ink: #1c2330; --muted: #6b7280; --line: #e7e2d8;
  --brand: #163a8a; --brand-ink: #ffffff; --accent: #c8383f; --ok: #1d7a4d; --warn: #a8660a; --bad: #b4282f;
  --ok-bg: #e5f4ec; --warn-bg: #fbf0dc; --bad-bg: #fbe7e8; --info-bg: #e8eefb;
  --shadow: 0 1px 2px rgba(20,25,40,.05), 0 8px 24px rgba(20,25,40,.06); --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f131b; --surface: #171c27; --surface-2: #1b2130; --ink: #e8ebf2; --muted: #93a0b5; --line: #2a3243;
    --brand: #7ea2ff; --brand-ink: #0b1220; --accent: #ff7a80; --ok: #62d09b; --warn: #f0b562; --bad: #ff8b91;
    --ok-bg: #12301f; --warn-bg: #33270f; --bad-bg: #3a1618; --info-bg: #17233f;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }

/* top bar */
.top { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.top .wrap { display: flex; align-items: center; gap: 12px; height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .2px; }
.logo { width: 32px; height: 32px; border-radius: 9px; background: var(--brand); display: grid; place-items: center; }
.logo svg { width: 18px; height: 18px; fill: var(--brand-ink); }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; margin-top: -2px; }
.spacer { flex: 1; }
.who { color: var(--muted); font-size: 13px; display: none; }
@media (min-width: 720px) { .who { display: block; } }

/* buttons */
.btn { border: 1px solid var(--line); background: var(--surface); padding: 9px 14px; border-radius: 10px; cursor: pointer; transition: transform .08s, box-shadow .15s, background .15s; }
.btn:hover { box-shadow: var(--shadow); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: transparent; font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 7px 11px; cursor: pointer; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--brand); color: var(--brand-ink); font-weight: 600; }

/* page */
main { padding: 28px 0 80px; }
h1 { font-size: 26px; margin: 0 0 4px; letter-spacing: -.3px; }
.sub { color: var(--muted); margin: 0 0 22px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 22px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi b { display: block; font-size: 28px; letter-spacing: -.5px; }
.kpi span { color: var(--muted); font-size: 13px; }
.bar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.search { flex: 1; min-width: 200px; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 14px; }

/* tenant cards / table */
.list { display: grid; gap: 10px; }
.row { display: grid; grid-template-columns: 2.2fr 1.6fr 1.2fr repeat(3, .8fr) 1.1fr; gap: 12px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; cursor: pointer; transition: box-shadow .15s, transform .1s; }
.row:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.row.head { background: transparent; border: 0; box-shadow: none; cursor: default; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; padding-top: 0; padding-bottom: 0; }
.row.head:hover { transform: none; box-shadow: none; }
.name { font-weight: 650; }
.slug, .muted { color: var(--muted); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--info-bg); color: var(--brand); }
.badge.ok { background: var(--ok-bg); color: var(--ok); } .badge.warn { background: var(--warn-bg); color: var(--warn); } .badge.bad { background: var(--bad-bg); color: var(--bad); }
.stack { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.cell-label { display: none; }
@media (max-width: 900px) {
  .row { grid-template-columns: 1fr 1fr; }
  .row.head { display: none; }
  .cell-label { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
}
.empty { text-align: center; color: var(--muted); padding: 48px 0; }

/* drawer + modal */
.scrim { position: fixed; inset: 0; background: rgba(10,14,24,.45); z-index: 20; animation: fade .15s; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--bg); z-index: 21; overflow: auto; padding: 22px; box-shadow: -12px 0 40px rgba(0,0,0,.2); animation: slide .2s ease-out; }
@keyframes slide { from { transform: translateX(24px); opacity: 0 } to { transform: none; opacity: 1 } }
.modal { position: fixed; z-index: 21; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(620px, calc(100% - 24px)); max-height: calc(100% - 24px); overflow: auto; background: var(--bg); border-radius: 18px; padding: 22px; box-shadow: var(--shadow); }
.dh { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.dh h2 { margin: 0; font-size: 21px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 14px; }
.card h3 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }
label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select {
  width: 100%; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; outline: none;
}
input:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.checks { display: flex; gap: 14px; flex-wrap: wrap; }
.checks label { display: flex; gap: 6px; align-items: center; margin: 0; color: var(--ink); font-size: 14px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
.stat { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat div { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.stat b { display: block; font-size: 19px; } .stat span { font-size: 12px; color: var(--muted); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; background: var(--surface-2); padding: 2px 6px; border-radius: 6px; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 40; background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 12px; box-shadow: var(--shadow); max-width: calc(100% - 24px); }
.toast.bad { background: var(--bad); color: #fff; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .box { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 30px; box-shadow: var(--shadow); }
.login h1 { font-size: 22px; margin: 16px 0 4px; } .login .sub { margin-bottom: 20px; }
.login .top-r { display: flex; justify-content: space-between; align-items: center; }
.err { color: var(--bad); font-size: 13.5px; margin: 0 0 10px; min-height: 1em; }

.full { width: 100%; }
.inline { display: flex; gap: 8px; }
.inline > input, .inline > select { flex: 1; min-width: 0; }
.flush { margin-top: 0; }

/* billing */
.seg.nav { margin-left: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin-bottom: 22px; }
.grid3 .card { margin-bottom: 0; }
.kpi.alert b { color: var(--bad); }
.h2 { font-size: 18px; margin: 0; }
.li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); cursor: pointer; }
.li:first-of-type { border-top: 0; }
.li.static { cursor: default; }
.li:hover:not(.static) .name { color: var(--brand); }
.right { text-align: right; }
.ilist { margin-top: 12px; }
.row.inv { grid-template-columns: 1.2fr 1.8fr 1fr 1fr 1fr 1fr 1.2fr; }
.tbl { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 14px; }
.tbl td { padding: 7px 4px; border-top: 1px solid var(--line); vertical-align: middle; }
.tbl tr.th td { border-top: 0; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.tbl tr.strong td { font-weight: 700; }
.tbl td.r { text-align: right; }
.tbl.form td input[type=number] { padding: 6px 8px; min-width: 70px; }
.tot { display: flex; justify-content: space-between; align-items: baseline; padding-top: 10px; border-top: 2px solid var(--line); }
.tot b { font-size: 20px; }
.chk { display: flex; gap: 8px; align-items: center; color: var(--ink); font-size: 14px; margin: 6px 0; }
.tier { align-items: flex-end; margin-bottom: 8px; }
.fx { flex: 1; }
.scrim.top2 { z-index: 30; }
.modal.wide { width: min(720px, calc(100% - 24px)); z-index: 31; }
@media print {
  body * { visibility: hidden; }
  .printable, .printable * { visibility: visible; }
  .printable { position: absolute; left: 0; top: 0; width: 100%; border: 0; }
}
.xbtn { width: 34px; flex: 0 0 34px; }
