:root {
  --bg: #f6f7f9; --panel: #fff; --line: #e3e5e9; --text: #1d2129; --muted: #6b7280;
  --accent: #2563eb; --accent-soft: #e8efff; --danger: #dc2626;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 6px; padding: 6px 12px; }
button:hover { background: #f0f2f5; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: #1d4fd8; }
button.icon { padding: 4px 9px; font-size: 16px; line-height: 1; }
button.link { border: 0; background: none; color: var(--muted); padding: 4px 0; }
button.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: inherit; border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.err { color: var(--danger); margin: 0; min-height: 1em; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 0; min-height: 1em; word-break: break-all; }

/* login */
.login { height: 100%; display: flex; align-items: center; justify-content: center; }
.loginbox { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 32px; width: 320px; display: flex; flex-direction: column; gap: 12px; }
.loginbox h1 { margin: 0 0 4px; font-size: 22px; }

/* layout */
.app { display: grid; grid-template-columns: 240px 380px 1fr; height: 100%; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 16px 14px; display: flex; flex-direction: column; gap: 6px; overflow-y: auto; }
.brand { font-weight: 700; font-size: 16px; margin-bottom: 8px; word-break: break-all; }
.wide { width: 100%; margin-bottom: 8px; padding: 9px; }
nav a, .addrs li { display: flex; align-items: center; gap: 6px; padding: 7px 10px; border-radius: 6px; cursor: pointer; text-decoration: none; color: var(--text); }
nav a:hover, .addrs li:hover { background: #f0f2f5; }
nav a.active, .addrs li.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
nav a .count { margin-left: auto; font-size: 12px; font-weight: 600; color: var(--accent); }
.sect { margin-top: 16px; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.newaddr { display: flex; align-items: center; gap: 4px; }
.newaddr input { flex: 1; min-width: 0; padding: 6px 7px; }
.newaddr .at { color: var(--muted); font-size: 12px; white-space: nowrap; }
.newaddr button { padding: 4px 10px; font-weight: 700; }
.addrs { list-style: none; margin: 0; padding: 0; flex: 1; }
.addrs li { font-size: 13px; padding: 5px 8px; }
.addrs li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.addrs li .act { visibility: hidden; border: 0; background: none; padding: 0 3px; color: var(--muted); font-size: 13px; }
.addrs li:hover .act { visibility: visible; }
.addrs li .act:hover { color: var(--text); }
.addrs li .tag { font-size: 10px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }

.list { display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--panel); min-width: 0; }
.listbar { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line); }
.listbar input { flex: 1; min-width: 0; }
.back { display: none; }
.filter { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 12px; background: var(--accent-soft); color: var(--accent); font-size: 13px; }
.filter button { border: 0; background: none; color: var(--accent); padding: 0 4px; }
.msgs { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; }
.msgs li { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.msgs li:hover { background: #f8f9fb; }
.msgs li.sel { background: var(--accent-soft); }
.msgs .row1 { display: flex; gap: 8px; }
.msgs .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msgs .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.msgs .subj { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); margin-top: 2px; }
.msgs li.unread .who, .msgs li.unread .subj { font-weight: 700; color: var(--text); }
.msgs li.unread { box-shadow: inset 3px 0 0 var(--accent); }
.msgs .none { color: var(--muted); text-align: center; cursor: default; padding: 40px; border: 0; }
.pager { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 8px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }

.read { display: flex; flex-direction: column; min-width: 0; background: var(--panel); }
.read .empty { margin: auto; color: var(--muted); }
.mhead { padding: 16px 20px 12px; border-bottom: 1px solid var(--line); }
.mhead h2 { margin: 0 0 10px; font-size: 19px; word-break: break-word; }
.mhead .meta { color: var(--muted); font-size: 13px; line-height: 1.6; word-break: break-word; }
.mhead .meta b { color: var(--text); font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.imgbar { padding: 6px 20px; background: #fff8e6; font-size: 13px; display: flex; gap: 10px; align-items: center; }
.imgbar button { padding: 2px 8px; font-size: 12px; }
.body { flex: 1; min-height: 0; display: flex; }
.body iframe { flex: 1; border: 0; width: 100%; height: 100%; background: #fff; }
.body pre { flex: 1; margin: 0; padding: 16px 20px; white-space: pre-wrap; word-break: break-word; font-family: inherit; overflow-y: auto; }
.atts { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 20px; border-top: 1px solid var(--line); }
.atts a { font-size: 13px; border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; text-decoration: none; color: var(--text); }
.atts a:hover { background: #f0f2f5; }

/* compose */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .35); display: flex; align-items: center; justify-content: center; z-index: 10; }
.composebox { background: var(--panel); border-radius: 12px; width: min(760px, 96vw); height: min(680px, 94vh); display: flex; flex-direction: column; padding: 14px 18px; gap: 6px; }
.chead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.composebox label { display: flex; align-items: center; gap: 8px; }
.composebox label > span { width: 56px; color: var(--muted); font-size: 13px; }
.composebox label > input, .fromrow { flex: 1; min-width: 0; }
.fromrow { display: flex; gap: 6px; }
.fromrow input { width: 160px; }
.fromrow select { flex: 1; min-width: 0; }
.composebox textarea { flex: 1; resize: none; margin-top: 6px; line-height: 1.5; }
.cfoot { display: flex; align-items: center; gap: 10px; }
.cfoot .err { flex: 1; }
.cfoot input[type=file] { border: 0; padding: 0; max-width: 260px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1d2129; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 20; }

/* mobile: one pane at a time */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 30% 0 0; z-index: 5; box-shadow: 0 0 30px rgba(0,0,0,.2); transform: translateX(-105%); transition: transform .2s; }
  .app.menu .side { transform: none; }
  .back { display: inline-block; }
  .read { display: none; }
  .app.reading .list { display: none; }
  .app.reading .read { display: flex; }
}
