:root {
  --bg: #f4f2ee; --panel: #fffdfa; --raised: #ffffff; --ink: #1d1b18; --muted: #6f6a62; --faint: #9b958b;
  --line: #e6e1d8; --line-strong: #d6cfc3; --hover: #f0ece5; --selected: #e7f1ee;
  --accent: #1f6f5c; --accent-hover: #185a4a; --accent-ink: #ffffff; --accent-soft: #e2f0ec;
  --warn: #a9590a; --warn-soft: #fbefdc; --danger: #b3261e; --danger-soft: #fbe9e7;
  --side: #16201d; --side-ink: #e8ece9; --side-muted: #8fa099; --side-hover: #202d29; --side-active: #2a3b36;
  --shadow: 0 1px 2px rgba(30, 25, 15, .06), 0 8px 24px rgba(30, 25, 15, .06);
  --radius: 10px;
  --font: ui-sans-serif, -apple-system, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111413; --panel: #171a19; --raised: #1d2120; --ink: #ecebe7; --muted: #a09f99; --faint: #74756f;
    --line: #272b29; --line-strong: #353a37; --hover: #1e2221; --selected: #1b2b27;
    --accent: #4fb59b; --accent-hover: #63c4ab; --accent-ink: #0b1512; --accent-soft: #1a2e29;
    --warn: #e0a458; --warn-soft: #33281a; --danger: #f0867d; --danger-soft: #3a1f1d;
    --side: #0c0f0e; --side-hover: #161b19; --side-active: #1d2623;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
#root { height: 100%; }
h1, h2, h3, p { margin: 0; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.icon { display: inline-flex; width: 18px; height: 18px; flex: none; }
.icon svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--raised); font-weight: 550; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; height: 42px; }
.btn:disabled { opacity: .55; cursor: default; }
.field { display: grid; gap: 6px; }
.field label { font-size: 13px; font-weight: 550; }
.field .hint { font-size: 12.5px; color: var(--muted); }
.input, textarea.input, select.input { width: 100%; height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--raised); }
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 550;
  background: var(--hover); color: var(--muted); white-space: nowrap; }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.switch { position: relative; width: 36px; height: 20px; border-radius: 999px; border: 0; background: var(--line-strong); transition: background .15s; padding: 0; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(16px); }
.switch:disabled { opacity: .4; cursor: default; }
.avatar { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; flex: none; color: #fff; font-weight: 650; font-size: 13px; letter-spacing: .02em; }
.avatar.small { width: 28px; height: 28px; font-size: 11px; }
.status-tile { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; flex: none; background: var(--hover); color: var(--muted); border: 1px solid var(--line); }
.status-tile .icon { width: 20px; height: 20px; }
.status-tile.pos { color: #2fa866; background: color-mix(in srgb, #2fa866 12%, var(--panel)); border-color: color-mix(in srgb, #2fa866 28%, transparent); }
.status-tile.neg { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.thread.selected .status-tile:not(.pos):not(.neg) { background: var(--panel); }
.muted { color: var(--muted); }
.error-text { color: var(--danger); font-size: 13px; min-height: 20px; }

/* ---------- sign-in ---------- */
.auth { min-height: 100%; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); }
.auth-side { background: var(--side); color: var(--side-ink); padding: 48px; display: flex; flex-direction: column; justify-content: space-between;
  background-image: radial-gradient(circle at 20% 15%, rgba(79, 181, 155, .22), transparent 45%), radial-gradient(circle at 85% 90%, rgba(79, 181, 155, .12), transparent 40%); }
.auth-side h1 { font-size: 34px; line-height: 1.15; letter-spacing: -.02em; font-weight: 650; max-width: 12em; }
.auth-side p { color: var(--side-muted); margin-top: 14px; max-width: 30em; font-size: 15px; }
.auth-points { display: grid; gap: 12px; color: var(--side-muted); font-size: 13.5px; }
.auth-points div { display: flex; gap: 10px; align-items: center; }
.auth-points .icon { color: #4fb59b; }
.auth-main { display: grid; place-items: center; padding: 32px 20px; }
.auth-card { width: 100%; max-width: 380px; display: grid; gap: 18px; }
.auth-card h2 { font-size: 22px; letter-spacing: -.01em; }
.auth-card .sub { color: var(--muted); margin-top: -10px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: #4fb59b; color: #0b1512; display: grid; place-items: center; }
.steps { display: flex; gap: 6px; }
.steps span { height: 4px; flex: 1; border-radius: 2px; background: var(--line-strong); }
.steps span.on { background: var(--accent); }
.qr-box { display: flex; gap: 16px; align-items: center; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.qr-box img { width: 132px; height: 132px; border-radius: 6px; background: #fff; flex: none; }
.secret { font-family: var(--mono); font-size: 12.5px; word-break: break-all; background: var(--hover); padding: 6px 8px; border-radius: 6px; margin-top: 6px; user-select: all; }
.code-input { font-family: var(--mono); font-size: 22px; letter-spacing: .35em; text-align: center; height: 52px; }

/* ---------- app shell ---------- */
.shell { height: 100%; display: grid; grid-template-columns: 232px minmax(0, 1fr); }
.side { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; padding: 18px 12px 12px; gap: 4px; min-height: 0; }
.side .brand { padding: 2px 8px 16px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--side-muted); padding: 16px 10px 6px; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; height: 36px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent; color: var(--side-ink); text-align: left; font-weight: 500; }
.nav-item:hover { background: var(--side-hover); }
.nav-item.active { background: var(--side-active); }
.nav-item .icon { color: var(--side-muted); }
.nav-item.active .icon { color: #4fb59b; }
.nav-item .count { margin-left: auto; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--side-muted); }
.nav-item .count.hot { background: #4fb59b; color: #0b1512; border-radius: 999px; padding: 0 7px; font-weight: 650; }
.side-foot { margin-top: auto; border-top: 1px solid rgba(255,255,255,.08); padding-top: 10px; display: grid; gap: 2px; }
.me { display: flex; align-items: center; gap: 10px; padding: 6px 8px 10px; min-width: 0; }
.me div { min-width: 0; }
.me .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me .role { font-size: 12px; color: var(--side-muted); }
.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }

/* ---------- inbox ---------- */
.inbox { flex: 1; min-height: 0; display: grid; grid-template-columns: 372px minmax(0, 1fr); }
.list-pane { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.list-head { padding: 18px 16px 12px; display: grid; gap: 12px; border-bottom: 1px solid var(--line); }
.list-head h2 { font-size: 18px; letter-spacing: -.01em; }
.list-tools { display: flex; gap: 8px; align-items: center; }
.search { position: relative; flex: 1; }
.search .icon { position: absolute; left: 10px; top: 9px; color: var(--faint); }
.search input { padding-left: 34px; height: 36px; }
.seg { display: inline-flex; padding: 3px; background: var(--hover); border-radius: 8px; }
.seg button { border: 0; background: transparent; height: 30px; padding: 0 12px; border-radius: 6px; font-weight: 550; color: var(--muted); }
.seg button.on { background: var(--raised); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.1); }
.thread-list { overflow-y: auto; flex: 1; }
.thread { display: grid; grid-template-columns: 38px minmax(0, 1fr); gap: 12px; padding: 13px 16px; border: 0; border-bottom: 1px solid var(--line); background: transparent; width: 100%; text-align: left; position: relative; }
.thread:hover { background: var(--hover); }
.thread.selected { background: var(--selected); }
.thread.selected::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.thread .top { display: flex; align-items: baseline; gap: 8px; }
.thread .who { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread.unread .who { font-weight: 700; }
.thread .when { margin-left: auto; font-size: 12px; color: var(--faint); white-space: nowrap; font-variant-numeric: tabular-nums; }
.thread .subject { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread .snip { font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 1px; }
.thread .meta { display: flex; gap: 6px; margin-top: 7px; flex-wrap: wrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; align-self: center; }
.empty { display: grid; place-items: center; text-align: center; padding: 48px 24px; color: var(--muted); gap: 6px; flex: 1; }
.empty .icon { width: 34px; height: 34px; color: var(--faint); margin: 0 auto 6px; }
.empty strong { color: var(--ink); font-size: 15px; display: block; }

.detail { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.detail-head { display: flex; gap: 14px; align-items: center; padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--panel); }
.detail-head .titles { min-width: 0; flex: 1; }
.detail-head h2 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.detail-head .sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.detail-head select.input { width: auto; height: 34px; max-width: 180px; }
.back { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.msg { max-width: 720px; width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; align-self: flex-start; }
.msg.out { align-self: flex-end; background: var(--accent-soft); border-color: transparent; }
.msg-head { display: flex; gap: 8px; align-items: baseline; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; flex-wrap: wrap; }
.msg-head strong { color: var(--ink); font-size: 13px; }
.msg-head time { margin-left: auto; white-space: nowrap; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14.5px; line-height: 1.55; }
.msg-body.quoted { color: var(--muted); border-left: 2px solid var(--line-strong); padding-left: 12px; margin-top: 10px; font-size: 13px; }
.quote-toggle { margin-top: 8px; border: 0; background: var(--hover); border-radius: 6px; height: 20px; padding: 0 9px; color: var(--muted); font-weight: 700; letter-spacing: .1em; line-height: 1; }
.composer { border-top: 1px solid var(--line); background: var(--panel); padding: 14px 24px 16px; }
.composer-box { max-width: 900px; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--raised); overflow: hidden; }
.composer-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer textarea { display: block; width: 100%; min-height: 96px; max-height: 320px; border: 0; background: transparent; padding: 12px 14px; resize: vertical; outline: none; font-size: 14.5px; line-height: 1.5; }
.composer-bar { display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 14px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.composer-bar .grow { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- admin pages ---------- */
.page { flex: 1; overflow-y: auto; padding: 28px 32px 48px; }
.page-inner { max-width: 1040px; margin: 0 auto; display: grid; gap: 22px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; letter-spacing: -.015em; }
.page-head p { color: var(--muted); }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.card.pad { padding: 20px; }
.card h3 { font-size: 15px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; }
.tile .label { font-size: 12.5px; color: var(--muted); }
.tile .value { font-size: 30px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile.alert .value { color: var(--warn); }
.load-row { display: grid; grid-template-columns: 180px minmax(0, 1fr) 96px; gap: 14px; align-items: center; padding: 10px 0; }
.load-row + .load-row { border-top: 1px solid var(--line); }
.load-row .person { display: flex; gap: 10px; align-items: center; min-width: 0; font-weight: 550; }
.load-row .person span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 10px; border-radius: 5px; background: var(--hover); overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; background: var(--accent); }
.bar i.rest { background: color-mix(in srgb, var(--accent) 35%, transparent); }
.load-row .num { text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); }
.load-row .num strong { color: var(--ink); font-size: 14px; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); margin-top: 12px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--accent); margin-right: 6px; }
.legend i.rest { background: color-mix(in srgb, var(--accent) 35%, transparent); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 11px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.user-cell { display: flex; gap: 12px; align-items: center; min-width: 180px; }
.user-cell .name { font-weight: 600; }
.user-cell .handle { font-size: 12.5px; color: var(--muted); }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }
tr.inactive td { opacity: .55; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.kv { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 10px 16px; align-items: center; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack { display: grid; gap: 14px; }

/* ---------- modal + toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 18, 17, .5); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal { width: 100%; max-width: 440px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 22px; display: grid; gap: 16px; max-height: calc(100vh - 40px); overflow-y: auto; }
.modal h3 { font-size: 17px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.temp-pw { font-family: var(--mono); font-size: 19px; letter-spacing: .04em; text-align: center; padding: 16px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); user-select: all; }
.action-list { display: grid; gap: 8px; }
.action-list .btn { justify-content: flex-start; }
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 500; box-shadow: var(--shadow); max-width: 90vw; }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .auth { grid-template-columns: 1fr; }
  .auth-side { display: none; }
  .shell { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .side { flex-direction: row; align-items: center; padding: 8px 10px; overflow-x: auto; gap: 2px; }
  .side .brand { padding: 0 8px 0 4px; }
  .side .brand > span:last-child, .nav-label, .me, .nav-item .label { display: none; }
  .nav-item { width: auto; padding: 0 10px; }
  .nav-item .count { margin-left: 4px; }
  .side-foot { margin: 0 0 0 auto; border: 0; padding: 0; display: flex; }
  .inbox { grid-template-columns: 1fr; }
  .inbox.has-detail .list-pane, .inbox:not(.has-detail) .detail { display: none; }
  .back { display: inline-flex; }
  .page { padding: 20px 16px 40px; }
  .messages { padding: 16px; }
  .composer { padding: 12px 16px; }
  .detail-head { padding: 12px 16px; }
  .load-row { grid-template-columns: 120px minmax(0, 1fr) 80px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
