:root {
  --bg: #f4f5f3; --panel: #ffffff; --panel-2: #fafaf8; --ink: #1c2321; --ink-2: #56605d; --ink-3: #8a9591;
  --line: #e3e6e2; --line-2: #eef0ec; --accent: #0e7c66; --accent-ink: #ffffff; --accent-soft: #e2f3ee;
  --ok: #1a7f4b; --ok-bg: #e3f4ea; --warn: #9a6200; --warn-bg: #fdf1d6; --err: #b3261e; --err-bg: #fbe5e3;
  --shadow: 0 1px 2px rgba(20,30,25,.06), 0 8px 24px rgba(20,30,25,.08);
  --radius: 12px; --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111513; --panel: #181d1b; --panel-2: #1c2220; --ink: #e7ece9; --ink-2: #a2aca8; --ink-3: #75807c;
    --line: #2a322f; --line-2: #222927; --accent: #34c3a0; --accent-ink: #07241d; --accent-soft: #17332b;
    --ok: #5ed39a; --ok-bg: #153325; --warn: #f0b64d; --warn-bg: #3a2c10; --err: #ff8f86; --err-bg: #3b1916;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.45 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.hidden { display: none !important; }
.muted { color: var(--ink-2); } .faint { color: var(--ink-3); } .mono { font-family: var(--mono); font-size: 12.5px; }

/* buttons & inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--panel); cursor: pointer; transition: background .12s, border-color .12s, transform .05s; white-space: nowrap; }
.btn:hover { background: var(--panel-2); border-color: var(--ink-3); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--err); } .btn.danger:hover { background: var(--err-bg); border-color: var(--err); }
.btn.ghost { border-color: transparent; background: transparent; } .btn.ghost:hover { background: var(--line-2); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field > label, .lbl { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.input { height: 38px; padding: 0 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); width: 100%; transition: border-color .12s, box-shadow .12s; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.hint { font-size: 12px; color: var(--ink-3); }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.err-text { color: var(--err); font-size: 13px; min-height: 18px; }

/* chips */
.chip { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--ok); } .chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.err { background: var(--err-bg); color: var(--err); } .chip.acc { background: var(--accent-soft); color: var(--accent); }
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.chip.plain::before { display: none; }

/* login */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(900px 500px at 15% -10%, var(--accent-soft), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 32px 28px 24px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand img { width: 30px; height: 30px; }
.login-card h1 { font-size: 22px; letter-spacing: -.02em; margin: 22px 0 4px; }
.login-card p.sub { margin: 0 0 22px; color: var(--ink-2); }
.login-card .btn.primary { width: 100%; height: 42px; font-size: 15px; margin-top: 4px; }
.login-foot { margin-top: 18px; text-align: center; font-size: 12px; color: var(--ink-3); }
.pw { position: relative; } .pw .input { padding-right: 70px; }
.pw button { position: absolute; right: 6px; top: 6px; height: 26px; padding: 0 8px; border: 0; background: transparent; color: var(--ink-2); cursor: pointer; border-radius: 6px; font-size: 12.5px; }
.pw button:hover { background: var(--line-2); }

/* app shell */
.app { display: grid; grid-template-columns: 272px minmax(320px, 400px) 1fr; height: 100vh; height: 100dvh; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side .brand { padding: 16px 16px 10px; }
.side-scroll { overflow: auto; padding: 4px 10px 10px; flex: 1; }
.sect { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); padding: 14px 8px 6px; }
.acct { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border: 1px solid transparent; border-radius: 10px; background: transparent; text-align: left; cursor: pointer; }
.acct:hover { background: var(--line-2); }
.acct.active { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.acct .meta { min-width: 0; flex: 1; } .acct .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acct .a { font-size: 12px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; color: #fff; flex: none; font-size: 14px; position: relative; }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.acct .x { opacity: 0; border: 0; background: transparent; color: var(--ink-3); cursor: pointer; width: 22px; height: 22px; border-radius: 6px; }
.acct:hover .x { opacity: 1; } .acct .x:hover { background: var(--err-bg); color: var(--err); }
.nav { display: flex; align-items: center; gap: 10px; width: 100%; height: 36px; padding: 0 10px; border: 0; background: transparent; border-radius: 9px; cursor: pointer; text-align: left; color: var(--ink); }
.nav:hover { background: var(--line-2); } .nav.active { background: var(--line-2); font-weight: 600; }
.nav svg { width: 17px; height: 17px; color: var(--ink-2); flex: none; } .nav .grow { flex: 1; }
.side-foot { border-top: 1px solid var(--line); padding: 10px 12px; display: flex; align-items: center; gap: 8px; }
.side-foot .who { min-width: 0; flex: 1; } .side-foot .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ver { font-size: 11.5px; color: var(--ink-3); }

.list { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.list-head { padding: 14px 14px 10px; border-bottom: 1px solid var(--line-2); }
.list-head .row { display: flex; gap: 8px; align-items: center; }
.list-head h2 { margin: 0 0 10px; font-size: 17px; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
.search { position: relative; flex: 1; } .search .input { padding-left: 34px; height: 36px; }
.search svg { position: absolute; left: 10px; top: 9px; width: 17px; height: 17px; color: var(--ink-3); }
.seg { display: flex; gap: 4px; margin-top: 10px; flex-wrap: wrap; }
.seg button { height: 26px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line); background: transparent; cursor: pointer; font-size: 12.5px; color: var(--ink-2); }
.seg button.on { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.stats { display: flex; gap: 6px; padding: 10px 14px 0; flex-wrap: wrap; }
.items { overflow: auto; flex: 1; }
.item { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line-2); background: transparent; padding: 11px 14px 11px 16px; cursor: pointer; position: relative; }
.item:hover { background: var(--panel-2); } .item.sel { background: var(--accent-soft); }
.item.unread::before { content: ""; position: absolute; left: 5px; top: 18px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.item .r1 { display: flex; gap: 8px; align-items: baseline; } .item .who { font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .when { font-size: 12px; color: var(--ink-3); flex: none; }
.item .subj { margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .r3 { margin-top: 6px; display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--ink-3); }
.empty { padding: 48px 24px; text-align: center; color: var(--ink-3); }
.more { padding: 12px; text-align: center; }

.view { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.view-head { padding: 16px 22px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.view-head h2 { margin: 0 0 8px; font-size: 19px; letter-spacing: -.01em; overflow-wrap: anywhere; }
.kv { display: grid; grid-template-columns: 64px 1fr; gap: 3px 10px; font-size: 13px; } .kv dt { color: var(--ink-3); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; align-items: center; }
.tabs { display: flex; gap: 2px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.tabs button { height: 38px; padding: 0 12px; border: 0; background: transparent; cursor: pointer; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.body { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 14px 16px 16px; gap: 10px; }
.frame { flex: 1; min-height: 280px; width: 100%; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
pre.raw { margin: 0; flex: 1; overflow: auto; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); font: 12.5px/1.55 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.err-box { padding: 10px 12px; border-radius: 10px; background: var(--err-bg); color: var(--err); font-size: 13px; overflow-wrap: anywhere; }
.atts { display: flex; gap: 8px; flex-wrap: wrap; }
.att { display: inline-flex; gap: 6px; align-items: center; padding: 5px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); text-decoration: none; color: var(--ink); font-size: 13px; }
.att:hover { border-color: var(--accent); }
.placeholder { margin: auto; text-align: center; color: var(--ink-3); padding: 24px; }
.placeholder svg { width: 54px; height: 54px; opacity: .5; margin-bottom: 8px; }

/* admin */
.admin { grid-column: 2 / 4; overflow: auto; padding: 22px 28px 40px; background: var(--bg); }
.admin h2 { margin: 0 0 14px; font-size: 20px; letter-spacing: -.01em; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table.t { width: 100%; border-collapse: collapse; } table.t th { text-align: left; font-size: 12px; color: var(--ink-3); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); }
table.t td { padding: 10px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; } table.t tr:last-child td { border-bottom: 0; }
.tools { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; } .tools .grow { flex: 1; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.tbl-wrap { overflow-x: auto; }
.kvl { display: grid; grid-template-columns: 220px 1fr; } .kvl div { padding: 10px 16px; border-bottom: 1px solid var(--line-2); } .kvl div:nth-last-child(-n+2) { border-bottom: 0; } .kvl .k { color: var(--ink-2); }

/* modal & toast */
.overlay { position: fixed; inset: 0; background: rgba(10,16,13,.5); display: grid; place-items: center; padding: 16px; z-index: 50; animation: fade .12s; }
.modal { width: 100%; max-width: 520px; max-height: calc(100dvh - 32px); overflow: auto; background: var(--panel); border-radius: 16px; border: 1px solid var(--line); box-shadow: var(--shadow); animation: pop .14s ease-out; }
.modal header { padding: 18px 22px 0; display: flex; align-items: center; } .modal header h3 { margin: 0; flex: 1; font-size: 17px; }
.modal .mbody { padding: 16px 22px 6px; } .modal footer { padding: 12px 22px 20px; display: flex; gap: 8px; justify-content: flex-end; }
.secret { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border: 1px dashed var(--ink-3); border-radius: 9px; background: var(--panel-2); margin-bottom: 8px; }
.secret code { flex: 1; font: 13px var(--mono); overflow-wrap: anywhere; }
.snippet { font: 12.5px/1.6 var(--mono); background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pick { display: grid; gap: 6px; max-height: 180px; overflow: auto; padding: 4px 2px; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: var(--ink); color: var(--panel); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); max-width: 360px; animation: pop .14s; }
.toast.err { background: var(--err); color: #fff; }
@keyframes fade { from { opacity: 0 } } @keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98) } }

.menu-btn, .back-btn { display: none; }
@media (max-width: 1100px) { .app { grid-template-columns: 244px minmax(300px, 360px) 1fr; } }
@media (max-width: 860px) {
  .app { display: block; position: relative; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(88vw, 320px); z-index: 40; transform: translateX(-102%); transition: transform .18s; box-shadow: var(--shadow); }
  .app.drawer .side { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 30; }
  .list, .view, .admin { position: absolute; inset: 0; width: 100%; }
  .view { display: none; } .app.reading .list { display: none; } .app.reading .view { display: flex; }
  .admin { padding: 16px; }
  .menu-btn, .back-btn { display: inline-flex; }
  .view-head { padding: 12px 14px; } .body { padding: 10px; } .two { grid-template-columns: 1fr; }
  .kvl { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
.btn svg { width: 17px; height: 17px; flex: none; }
.att { white-space: nowrap; }
.view-head .row { display: flex; }
