:root {
  --bg: #fafaf8; --panel: #fff; --ink: #1b1b1f; --muted: #6b6b76; --line: #e4e4e0; --accent: #c8102e;
  --accent-ink: #fff; --p1: #c8102e; --p2: #b7791f; --p3: #6b6b76; --sel: #fdf0f2; --local: #1d6fb8;
  --font: ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #131316; --panel: #1b1b20; --ink: #ececf1; --muted: #9a9aa6; --line: #2c2c34;
          --accent: #ff4d6a; --accent-ink: #1b1b20; --p1: #ff6b81; --p2: #e0a84a; --p3: #9a9aa6;
          --sel: #2a1a1f; --local: #5aa9ee; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; width: 100%; }
textarea { resize: vertical; }
input[type=checkbox] { width: auto; }
.bar select, .bar input { width: auto; }
a { color: var(--accent); }
.small { font-size: 12.5px; color: var(--muted); }

.login { max-width: 340px; margin: 12vh auto; padding: 0 16px; display: grid; gap: 10px; }
.login h1 { margin: 0 0 4px; font-size: 22px; }

.shell { display: grid; grid-template-rows: auto auto 1fr; height: 100vh; }
.top { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.brand { font-weight: 700; margin-right: 6px; }
.top .grow { flex: 1; min-width: 120px; }
.top input[type=search] { max-width: 320px; }
.badge { padding: 1px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--line); }
.badge.warn { border-color: var(--p2); color: var(--p2); }
.tabs { display: flex; gap: 2px; padding: 0 8px; border-bottom: 1px solid var(--line); background: var(--panel); overflow-x: auto; }
.tab { padding: 8px 12px; border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; white-space: nowrap; }
.tab.on { border-bottom-color: var(--accent); font-weight: 600; }
.tab .n { color: var(--muted); font-size: 12px; margin-left: 4px; }

.main { display: grid; grid-template-columns: minmax(280px, 400px) 1fr; min-height: 0; }
.list { overflow-y: auto; border-right: 1px solid var(--line); background: var(--panel); }
.filters { padding: 8px 12px; display: flex; gap: 8px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 1; align-items: center; }
.filters select { max-width: 200px; }
.row { display: grid; grid-template-columns: 22px 1fr; gap: 6px; padding: 9px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.row.cur { background: var(--sel); }
.row.unread .subj { font-weight: 700; }
.row .subj { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; color: var(--muted); font-size: 12.5px; }
.pri { font-weight: 700; } .pri.P1 { color: var(--p1); } .pri.P2 { color: var(--p2); } .pri.P3 { color: var(--p3); }
.local { color: var(--local); font-weight: 600; }
.star { color: var(--p2); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.detail { overflow-y: auto; padding: 14px 20px 40px; min-width: 0; }
.detail h2 { margin: 0 0 4px; font-size: 19px; overflow-wrap: anywhere; }
.bar { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; align-items: center; }
.why { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin: 8px 0; font-size: 13.5px; }
.msg { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; margin: 10px 0; }
.msg > summary, .msg .head { padding: 8px 12px; cursor: pointer; list-style: none; }
.msg .head .who { font-weight: 600; }
.msg .body { padding: 4px 12px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.mine { background: var(--sel); }
.att { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 4px 12px 10px; font-size: 13.5px; }
.att audio { height: 34px; max-width: 100%; }
.compose { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 12px; margin: 14px 0; display: grid; gap: 8px; }
.compose label { font-size: 12.5px; color: var(--muted); display: grid; gap: 3px; }

.page { padding: 18px 20px 40px; max-width: 880px; overflow-y: auto; }
.page h2 { margin-top: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
pre.dg { white-space: pre-wrap; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; }

#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; }
.toast { background: var(--ink); color: var(--bg); padding: 9px 14px; border-radius: 8px; display: flex; gap: 12px; align-items: center; }
.toast button { background: transparent; color: inherit; border-color: currentColor; }

@media (max-width: 760px) {
  .main { grid-template-columns: 1fr; }
  .main.open .list { display: none; }
  .main:not(.open) .detail { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .detail { padding: 12px 14px 40px; }
  .back { display: inline-block !important; }
}
.back { display: none; }
