:root {
  --brand: #0a7d4f; --brand-ink: #fff; --ink: #1b2228; --muted: #61707a; --line: #e2e7ea; --bg: #f4f6f7; --panel: #fff;
  --bad: #b42318; --bad-bg: #fdecea; --warn: #9a6700; --warn-bg: #fff4d6; --good: #0a7d4f; --good-bg: #e6f4ee;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand); }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: #12201a; color: #cfe3d8; padding: 16px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .brand { color: #fff; font-weight: 700; font-size: 16px; padding: 4px 10px 14px; }
.side .tenant { padding: 0 10px 12px; }
.side select { width: 100%; background: #1d3229; color: #fff; border: 1px solid #2c473b; }
.side nav a { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-radius: 8px;
  color: inherit; text-decoration: none; margin-bottom: 1px; }
.side nav a:hover { background: #1d3229; }
.side nav a.on { background: var(--brand); color: #fff; }
.side nav .sep { margin: 12px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: #7fa594; }
.side .pill { background: #e8553f; color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; }
.shell > div { min-width: 0; }
.main { padding: 20px 24px 60px; min-width: 0; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.top .who { color: var(--muted); font-size: 13px; }
.menu-btn { display: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 30; inset: 0 30% 0 0; transform: translateX(-100%); transition: transform .2s; height: 100%; }
  .side.open { transform: none; box-shadow: 0 0 0 100vw rgba(0,0,0,.35); }
  .menu-btn { display: inline-flex; }
  .main { padding: 14px 12px 60px; }
  .top .who { display: none; }
  .bars .b span { font-size: 9px; }
}

/* blocks */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1000px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 600px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 2px; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.empty { color: var(--muted); padding: 24px; text-align: center; }

/* controls */
button, .btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 8px; padding: 7px 12px;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; white-space: nowrap; }
button:hover, .btn:hover { border-color: #c5ced3; }
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
button.danger { color: var(--bad); }
button.link { border: 0; background: none; padding: 0; color: var(--brand); text-decoration: underline; }
button:disabled { opacity: .55; cursor: default; }
input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; color: var(--ink); min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); border-color: var(--brand); }
textarea { width: 100%; min-height: 80px; }
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; }
.form .full { grid-column: 1 / -1; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form label > input, .form label > select, .form label > textarea { color: var(--ink); font-size: 14px; }
.form .check { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); }
@media (max-width: 600px) { .form { grid-template-columns: 1fr; } }

/* tables */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #fafbfb; font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f8faf9; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* badges */
.badge { display: inline-block; border-radius: 999px; padding: 1px 8px; font-size: 12px; background: #eef1f2; color: var(--muted); white-space: nowrap; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #c3cbd0; margin-right: 6px; }
.dot.on { background: #12b76a; }
.dot.off { background: #e8553f; }

/* bars */
.bars { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding-top: 8px; }
.bars .b { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.bars .b i { display: block; width: 100%; max-width: 34px; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .b span { font-size: 10px; color: var(--muted); margin-top: 4px; white-space: nowrap; }

/* modal & toast */
.backdrop { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 12px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 860px; }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; }
.modal .body { padding: 16px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
#toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: #1b2228; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 360px; }
.toast.bad { background: var(--bad); }

/* login */
.login { max-width: 380px; margin: 12vh auto; }
.login h1 { margin-bottom: 4px; }

/* chat */
.chat { display: grid; grid-template-columns: 300px 1fr; gap: 14px; min-height: 60vh; }
@media (max-width: 860px) { .chat { grid-template-columns: 1fr; } }
.threads { max-height: 70vh; overflow-y: auto; padding: 0; }
.thread { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.thread.on { background: var(--good-bg); }
.thread .last { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msgs { display: flex; flex-direction: column; gap: 8px; height: 48vh; overflow-y: auto; padding: 6px 2px 10px; }
.msg { max-width: 75%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; }
.msg.customer { align-self: flex-start; background: var(--bg); }
.msg.admin { align-self: flex-end; background: var(--brand); color: #fff; }
.msg time { display: block; font-size: 11px; opacity: .7; margin-top: 2px; }

/* units grid */
.units { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
.unit { border: 1px solid var(--line); border-radius: 8px; padding: 6px; text-align: center; font-size: 12px; background: #fff; }
.unit.on { background: var(--good-bg); border-color: #a6d8c0; color: var(--good); font-weight: 600; }

/* voucher print sheet */
.sheet { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; background: #fff; }
.vcard { border: 1px dashed #9aa5ab; padding: 8px 10px; height: 33mm; display: flex; flex-direction: column; justify-content: space-between; overflow: hidden; }
.vcard .net { font-weight: 700; font-size: 12px; }
.vcard .plan { font-size: 11px; color: #444; }
.vcard .code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 17px; font-weight: 700; letter-spacing: .08em; }
.vcard .how { font-size: 9px; color: #555; line-height: 1.25; }
@media print {
  @page { size: A4; margin: 8mm; }
  body { background: #fff; }
  .side, .top, .noprint, #toasts { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
  .card { border: 0; box-shadow: none; padding: 0; }
  .vcard { break-inside: avoid; }
}
