:root {
  --bg: #f6f7f9; --panel: #fff; --text: #1b1f24; --muted: #667085; --line: #e4e7ec;
  --brand: #128c4a; --brand-ink: #fff; --brand-soft: #e6f6ec; --danger: #c0362c; --danger-soft: #fdeceb;
  --warn: #9a6700; --warn-soft: #fff4d6; --info: #175cd3; --info-soft: #e8f0fe; --bubble-in: #f0f2f5; --bubble-out: #d9f7e4;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --panel: #171b21; --text: #e6e9ee; --muted: #98a2b3; --line: #2a303a;
    --brand: #2fbf71; --brand-ink: #06210f; --brand-soft: #12301f; --danger: #ff7b72; --danger-soft: #3a1815;
    --warn: #f0b429; --warn-soft: #3a2f10; --info: #7cb0ff; --info-soft: #14233f; --bubble-in: #232932; --bubble-out: #14402a;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 1.35rem; margin: 0 0 .25rem; } h2 { font-size: 1.05rem; margin: 0 0 .75rem; } h3 { font-size: .95rem; margin: 0 0 .5rem; }
a { color: var(--info); } .muted { color: var(--muted); } .small { font-size: .85rem; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.boot { padding: 2rem; text-align: center; color: var(--muted); }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { width: 100%; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
input[type=checkbox], input[type=radio] { width: auto; }
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
label { display: block; font-weight: 600; font-size: .88rem; margin: 0 0 .3rem; }
.field { margin-bottom: .9rem; } .hint { color: var(--muted); font-size: .82rem; margin-top: .25rem; font-weight: 400; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; } .row > .grow { flex: 1 1 200px; }
.grid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid.g3 { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-weight: 600; }
.btn:hover { border-color: var(--muted); } .btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.small { padding: .25rem .6rem; font-size: .85rem; } .btn.link { border: 0; background: none; color: var(--info); padding: 0; font-weight: 500; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card.pad0 { padding: 0; overflow: hidden; }
.chip { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 700; background: var(--bubble-in); color: var(--muted); }
.chip.ok { background: var(--brand-soft); color: var(--brand); } .chip.bad { background: var(--danger-soft); color: var(--danger); }
.chip.warn { background: var(--warn-soft); color: var(--warn); } .chip.info { background: var(--info-soft); color: var(--info); }
.alert { padding: .7rem .9rem; border-radius: 8px; margin-bottom: 1rem; background: var(--info-soft); color: var(--info); }
.alert.warn { background: var(--warn-soft); color: var(--warn); } .alert.bad { background: var(--danger-soft); color: var(--danger); } .alert.ok { background: var(--brand-soft); color: var(--brand); }
table { width: 100%; border-collapse: collapse; } th, td { text-align: left; padding: .55rem .75rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: color-mix(in srgb, var(--bg) 50%, var(--panel)); }
tr:last-child td { border-bottom: 0; } .tablewrap { overflow-x: auto; }
.bar { height: 8px; background: var(--bubble-in); border-radius: 99px; overflow: hidden; } .bar > i { display: block; height: 100%; background: var(--brand); }
.stat { padding: .75rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); } .stat b { display: block; font-size: 1.4rem; line-height: 1.1; } .stat span { color: var(--muted); font-size: .8rem; }
/* layout */
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 1rem .75rem; display: flex; flex-direction: column; gap: .15rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-weight: 800; font-size: 1.05rem; padding: .25rem .6rem 1rem; display: flex; gap: .5rem; align-items: center; }
.brand i { width: 22px; height: 22px; border-radius: 6px; background: #25d366; display: inline-block; }
.side a.nav { display: flex; justify-content: space-between; gap: .5rem; padding: .5rem .7rem; border-radius: 8px; color: var(--text); text-decoration: none; font-weight: 600; }
.side a.nav:hover { background: var(--bubble-in); } .side a.nav.on { background: var(--brand-soft); color: var(--brand); }
.badge { background: var(--danger); color: #fff; border-radius: 99px; font-size: .72rem; padding: .05rem .45rem; font-weight: 700; }
.main { padding: 1.25rem 1.5rem 3rem; min-width: 0; max-width: 1200px; width: 100%; }
.top { display: flex; gap: .75rem; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; flex-wrap: wrap; }
.top select { width: auto; min-width: 200px; } .menu-btn { display: none; }
@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; } .menu-btn { display: inline-flex; }
  .side { position: fixed; inset: 0 25% 0 0; z-index: 20; transform: translateX(-102%); transition: transform .2s; box-shadow: 4px 0 24px rgba(0,0,0,.25); }
  .side.open { transform: none; } .main { padding: 1rem 16px 3rem; }
}
/* login */
.login { max-width: 380px; margin: 12vh auto; padding: 0 16px; } .login .card { padding: 1.5rem; }
/* modal / toast */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border-radius: 12px; padding: 1.25rem; width: min(560px, 100%); max-height: 90vh; overflow: auto; }
.modal.wide { width: min(820px, 100%); } .modal h2 { margin-bottom: 1rem; } .modal .actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: .5rem; z-index: 60; }
.toast { background: var(--text); color: var(--bg); padding: .65rem .9rem; border-radius: 8px; max-width: 360px; box-shadow: 0 4px 18px rgba(0,0,0,.25); }
.toast.bad { background: var(--danger); color: #fff; } .toast.ok { background: var(--brand); color: var(--brand-ink); }
.qr { display: block; margin: 0 auto; width: 260px; height: 260px; image-rendering: pixelated; background: #fff; padding: 8px; border-radius: 8px; }
.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); }
.checks { display: flex; gap: .75rem; flex-wrap: wrap; } .checks label { display: flex; align-items: center; gap: .3rem; font-weight: 500; margin: 0; }
.vars { display: flex; gap: .35rem; flex-wrap: wrap; margin: .35rem 0; } .vars button { cursor: pointer; }
.preview { background: var(--bubble-out); border-radius: 10px 10px 2px 10px; padding: .6rem .8rem; white-space: pre-wrap; word-break: break-word; max-width: 420px; }
/* inbox */
.inbox { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 150px); min-height: 420px; }
.convs { border-right: 1px solid var(--line); overflow-y: auto; } .conv { padding: .7rem .9rem; border-bottom: 1px solid var(--line); cursor: pointer; }
.conv:hover, .conv.on { background: var(--bubble-in); } .conv .l1 { display: flex; justify-content: space-between; gap: .5rem; font-weight: 700; }
.conv .l2 { color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread { display: flex; flex-direction: column; min-width: 0; } .msgs { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .4rem; }
.bubble { max-width: 75%; padding: .45rem .7rem; border-radius: 10px; background: var(--bubble-in); white-space: pre-wrap; word-break: break-word; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); } .bubble small { display: block; color: var(--muted); font-size: .72rem; text-align: right; margin-top: .15rem; }
.composer { display: flex; gap: .5rem; padding: .75rem; border-top: 1px solid var(--line); } .composer textarea { min-height: 44px; height: 44px; }
@media (max-width: 800px) { .inbox { grid-template-columns: 1fr; height: auto; } .convs { max-height: 240px; border-right: 0; border-bottom: 1px solid var(--line); } .thread { height: 70vh; } }
