:root {
  --bg: #f5f6f8; --panel: #ffffff; --panel2: #f0f2f5; --line: #e2e5ea; --text: #14171d; --muted: #68707d;
  --accent: #2f5fe8; --accent-text: #ffffff; --accent-soft: #e6edff; --danger: #c73434; --warn: #a86200; --warn-soft: #fff4dd;
  --ok: #1d8a4e; --shadow: 0 10px 40px rgba(15, 23, 42, .14); --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
:root[data-theme="dark"] {
  --bg: #0b0d12; --panel: #12151c; --panel2: #181c25; --line: #252a35; --text: #e8ebf0; --muted: #8b93a1;
  --accent: #5b84ff; --accent-text: #0b0d12; --accent-soft: #1a2440; --danger: #ef6a6a; --warn: #e2a13c; --warn-soft: #2b2212;
  --ok: #4cc38a; --shadow: 0 10px 40px rgba(0, 0, 0, .5);
}
* { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
svg.ic { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
a { color: var(--accent); }
.hide { display: none !important; }

.btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; white-space: nowrap; }
a.btn { text-decoration: none; color: var(--text); }
.btn:hover { background: var(--panel2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--panel2); }
.btn.icon { width: 34px; padding: 0; justify-content: center; }
.btn:disabled { opacity: .5; cursor: default; }
.input, select.input, textarea.input { width: 100%; height: 36px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); outline: none; }
textarea.input { height: auto; padding: 8px 10px; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; background: var(--panel2); color: var(--muted); border: 1px solid var(--line); }
.badge.ok { color: var(--ok); } .badge.warn { color: var(--warn); } .badge.bad { color: var(--danger); }

/* Login */
.login { height: 100%; display: grid; place-items: center; padding: 20px; }
.login form { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.login h1 { font-size: 20px; margin: 0 0 4px; }
.login p { color: var(--muted); margin: 0 0 20px; }
.login .btn { width: 100%; justify-content: center; height: 40px; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 8px; }

/* Shell */
.shell { height: 100%; display: grid; grid-template-columns: 236px 380px 1fr; }
.shell.wide { grid-template-columns: 236px 1fr; }
.nav { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.nav .top { padding: 14px; display: flex; gap: 8px; align-items: center; }
.nav .brand { font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav .scroll { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.nav .compose { margin: 0 14px 12px; justify-content: center; height: 38px; }
.mbx { margin-top: 10px; }
.mbx > button { width: 100%; text-align: left; background: none; border: 0; padding: 6px 8px; cursor: pointer; border-radius: 8px; }
.mbx > button:hover { background: var(--panel2); }
.mbx .addr { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mbx .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; gap: 6px; align-items: center; }
.fld { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; cursor: pointer; color: var(--text); border: 0; background: none; width: 100%; text-align: left; }
.fld:hover { background: var(--panel2); }
.fld.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.fld .n { margin-left: auto; font-size: 12px; font-weight: 600; }
.nav .foot { border-top: 1px solid var(--line); padding: 8px; display: flex; gap: 4px; align-items: center; }
.nav .foot .who { flex: 1; min-width: 0; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-left: 6px; }

.list { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.bar { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--line); min-height: 55px; }
.bar h2 { font-size: 15px; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search { position: relative; flex: 1; }
.search svg { position: absolute; left: 10px; top: 9px; color: var(--muted); }
.search input { padding-left: 34px; }
.items { flex: 1; overflow-y: auto; }
.item { display: block; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 10px 14px; cursor: pointer; }
.item:hover { background: var(--panel2); }
.item.on { background: var(--accent-soft); }
.item .r1 { display: flex; gap: 8px; align-items: center; }
.item .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .when { font-size: 12px; color: var(--muted); flex: none; }
.item .sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .snip { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.unread .who, .item.unread .sub { font-weight: 700; }
.item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.item .meta { display: flex; gap: 6px; align-items: center; color: var(--muted); }
.item .meta svg { width: 14px; height: 14px; }
.item .cnt { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.more { padding: 12px; text-align: center; }

.read { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.read .body { flex: 1; overflow-y: auto; padding: 16px 20px 40px; }
.read h1 { font-size: 20px; margin: 4px 0 16px; overflow-wrap: anywhere; }
.msg { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; }
.msg .hd { display: flex; gap: 10px; padding: 12px 14px; cursor: pointer; align-items: flex-start; }
.msg .av { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; }
.msg .hd .mid { flex: 1; min-width: 0; }
.msg .from { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .from small { font-weight: 400; color: var(--muted); }
.msg .to { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.open .to { white-space: normal; }
.msg .when { font-size: 12px; color: var(--muted); flex: none; }
.msg .content { border-top: 1px solid var(--line); }
.msg iframe { width: 100%; border: 0; display: block; background: #fff; min-height: 60px; }
.msg pre.txt { margin: 0; padding: 14px; white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; }
.msg .note { padding: 8px 14px; font-size: 13px; background: var(--warn-soft); color: var(--warn); display: flex; gap: 10px; align-items: center; border-bottom: 1px solid var(--line); }
.msg .note button { margin-left: auto; }
.atts { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line); }
.att { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; text-decoration: none; color: var(--text); background: var(--panel2); max-width: 260px; }
.att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att small { color: var(--muted); flex: none; }
.att button { border: 0; background: none; cursor: pointer; padding: 0; display: flex; color: var(--muted); }
.msg .acts { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line); flex-wrap: wrap; }

/* Compose */
.overlay { position: fixed; inset: 0; background: rgba(8, 10, 16, .45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.sheet { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); width: 100%; max-width: 760px; max-height: 100%; display: flex; flex-direction: column; overflow: hidden; }
.sheet.sm { max-width: 460px; }
.sheet .hd { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); gap: 8px; }
.sheet .hd h3 { margin: 0; font-size: 15px; flex: 1; }
.sheet .bd { padding: 16px; overflow-y: auto; }
.sheet .ft { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); align-items: center; flex-wrap: wrap; }
.sheet .ft .sp { flex: 1; }
.crow { display: flex; align-items: center; border-bottom: 1px solid var(--line); padding: 0 16px; gap: 8px; }
.crow label { color: var(--muted); font-size: 13px; width: 56px; flex: none; }
.crow input, .crow select { flex: 1; border: 0; background: transparent; height: 40px; outline: none; min-width: 0; }
.crow select option { background: var(--panel); }
.tools { display: flex; gap: 2px; padding: 6px 12px; border-bottom: 1px solid var(--line); }
.editor { min-height: 220px; padding: 14px 16px; outline: none; overflow-y: auto; flex: 1; overflow-wrap: anywhere; }
.editor blockquote { margin: 8px 0 8px 4px; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.compose-body { display: flex; flex-direction: column; min-height: 0; flex: 1; overflow-y: auto; }

/* Admin */
.page { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.page .body { flex: 1; overflow: auto; padding: 16px 20px 40px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs button { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
.tabs button.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tbl th, .tbl td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--panel2); white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.act { text-align: right; white-space: nowrap; }
.tbl td.act .btn { height: 28px; padding: 0 8px; font-size: 12px; margin-left: 4px; }
.tblwrap { overflow-x: auto; }
.row { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.row .sp { flex: 1; }
.steps { padding-left: 18px; margin: 0; }
.steps li { margin-bottom: 10px; }
code { font-family: var(--mono); font-size: 12px; background: var(--panel2); padding: 1px 5px; border-radius: 4px; }
.check { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; max-width: 640px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.sig { min-height: 90px; border: 1px solid var(--line); border-radius: 8px; padding: 10px; outline: none; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); max-width: 340px; }
.toast.bad { background: var(--danger); color: #fff; }

.only-phone { display: none; }
@media (max-width: 1100px) { .shell { grid-template-columns: 210px 320px 1fr; } }
@media (max-width: 860px) {
  .only-phone { display: inline-flex; }
  .shell, .shell.wide { grid-template-columns: 1fr; }
  .shell > * { display: none; }
  .shell[data-pane="nav"] > .nav, .shell[data-pane="list"] > .list, .shell[data-pane="read"] > .read, .shell[data-pane="page"] > .page { display: flex; }
  .nav, .list { border-right: 0; }
  .bar { padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); }
  .read .body, .page .body { padding: 12px 12px 60px; }
  .read h1 { font-size: 17px; }
  .item { padding: 12px 14px; }
  .btn { height: 38px; } .btn.icon { width: 38px; }
  .overlay { padding: 0; place-items: stretch; }
  .sheet, .sheet.sm { max-width: none; border-radius: 0; border: 0; height: 100%; }
  .sheet .ft { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .nav .foot { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .crow input, .crow select, .input, .editor { font-size: 16px; }
  #toasts { left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); }
  .toast { max-width: none; }
}
