:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --text: #111827;
  --muted: #5b6472;
  --border: #e2e5ea;
  --accent: #1d4ed8;
  --accent-text: #ffffff;
  --accent-soft: #e8eefc;
  --danger: #b42318;
  --ok: #067647;
  --radius: 10px;
  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --surface: #171b23;
    --text: #e8ebf0;
    --muted: #9aa3b2;
    --border: #2a303b;
    --accent: #5b8def;
    --accent-text: #0b1020;
    --accent-soft: #1a2542;
    --danger: #f97066;
    --ok: #47cd89;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
a { color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; }
h1 { font-size: 1.35rem; line-height: 1.25; margin: 0 0 8px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 650; color: var(--text); text-decoration: none; }
.topbar-right { display: flex; gap: 6px; align-items: center; }
.wrap { max-width: 860px; margin: 0 auto; padding: 16px; }

.btn { font: inherit; font-weight: 550; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 9px 14px; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; min-height: 40px; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:focus-visible, .tab:focus-visible, .chip:focus-visible, .row:focus-visible, textarea:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 12px; -webkit-overflow-scrolling: touch; }
.tab { white-space: nowrap; padding: 10px 12px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; font-weight: 550; }
.tab[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }
.count { display: inline-block; min-width: 20px; text-align: center; background: var(--accent-soft); color: var(--accent); border-radius: 10px; font-size: 0.78rem; padding: 0 6px; margin-left: 4px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { padding: 5px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text); text-decoration: none; font-size: 0.88rem; }
.chip[aria-current="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.mail-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.mail-list li + li { border-top: 1px solid var(--border); }
.row { display: flex; flex-direction: column; gap: 3px; padding: 12px 14px; color: var(--text); text-decoration: none; }
.row:hover { background: var(--accent-soft); }
.row-top, .row-bottom { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; min-width: 0; }
.who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
time { color: var(--muted); font-size: 0.82rem; white-space: nowrap; }
.subject { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.snippet { color: var(--muted); font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.tag { font-size: 0.75rem; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.tag.subtle { background: transparent; border: 1px solid var(--border); color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

.mail-head .meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 4px 0 14px; }
.state { font-size: 0.75rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); }
.state-new { color: var(--accent); border-color: var(--accent); }
.state-fix_live { color: var(--ok); border-color: var(--ok); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.thread { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin-bottom: 14px; }
.msg { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.msg.mine { border-left: 3px solid var(--accent); }
.msg summary { cursor: pointer; padding: 10px 14px; display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 2px 8px; list-style: none; }
.msg summary .who { white-space: normal; overflow-wrap: anywhere; min-width: 0; }
.msg summary::-webkit-details-marker { display: none; }
.msg-text { padding: 0 14px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }

.turn-into { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.label { color: var(--muted); font-size: 0.85rem; margin-right: 4px; }

.reply { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.reply label, .center-card label { display: block; font-weight: 600; margin-bottom: 6px; }
textarea, input { width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
textarea { resize: vertical; min-height: 180px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.error { color: var(--danger); font-weight: 550; }
.ok { color: var(--ok); font-weight: 550; }

.center-card { max-width: 420px; margin: 12vh auto 0; padding: 24px 16px; }
.center-card .btn { margin-top: 12px; }

dialog { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); padding: 0; width: min(520px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dlg { padding: 18px; }
.kv { display: grid; grid-template-columns: 72px 1fr; gap: 6px 10px; margin: 0 0 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; font-weight: 550; }
.preview { max-height: 30vh; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin: 0 0 10px; font: inherit; }

@media (max-width: 480px) {
  .wrap { padding: 12px 16px; }
  .btn { min-height: 44px; }
  .actions .btn { flex: 1 1 auto; justify-content: center; }
  .row-bottom { flex-wrap: wrap; }
  .snippet { flex-basis: 100%; }
}

.warn { background: #fff4e5; color: #7a3e00; border: 1px solid #f0b66b; border-radius: 8px; padding: 8px 12px; font-weight: 550; margin: 0 0 10px; }
.notice { background: #fdecea; color: #8a1c13; border: 1px solid #f1a9a1; border-radius: 8px; padding: 8px 12px; margin: 0 0 10px; overflow-wrap: anywhere; }
@media (prefers-color-scheme: dark) {
  .warn { background: #3a2a10; color: #ffd596; border-color: #7a5a22; }
  .notice { background: #3a1613; color: #ffb4ab; border-color: #7a2a24; }
}

/* part 2: items, dialogs, fixed mails, changelog */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h2 { margin-top: 0; }
.person { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 12px; }
.person:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.person h3 { font-size: 1rem; margin: 0 0 8px; overflow-wrap: anywhere; }
.plain-list { list-style: none; margin: 0 0 8px; padding: 0; }
.plain-list li { display: flex; gap: 6px 8px; align-items: center; flex-wrap: wrap; padding: 4px 0; overflow-wrap: anywhere; }
.linked { margin-bottom: 14px; }
.linked h2 { font-size: 0.95rem; margin-bottom: 4px; color: var(--muted); }
.small-btn { min-height: 32px; padding: 3px 10px; font-size: 0.85rem; }
.not-yet { font-weight: 600; color: var(--accent); }
select { width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }
.dlg label { display: block; font-weight: 600; margin: 8px 0 4px; }
.dlg input { margin-bottom: 6px; }
input.short { width: 140px; }
.pick-list { max-height: 40vh; overflow: auto; margin-top: 8px; }
.pick-list li { padding: 2px 0; }
.btn.pick { width: 100%; justify-content: space-between; gap: 8px; text-align: left; flex-wrap: wrap; height: auto; padding: 8px 12px; }
.pick-title { overflow-wrap: anywhere; min-width: 0; }
fieldset.lang { border: 1px solid var(--border); border-radius: 8px; margin: 0 0 10px; padding: 8px 12px 12px; min-width: 0; }
fieldset.lang legend { padding: 0 6px; font-weight: 600; }
fieldset.lang label { display: block; font-weight: 600; margin: 6px 0 4px; }
.warn ul { margin: 4px 0 0; }
.warn li { display: list-item; list-style: disc; margin-left: 18px; }
.mail-head .meta a { font-size: 0.85rem; }
@media (max-width: 480px) {
  input.short { width: 100%; }
  .btn.pick { flex-direction: column; align-items: flex-start; }
}
.brand, .topbar .btn { white-space: nowrap; }
@media (max-width: 480px) {
  .topbar { padding: 8px 12px; gap: 4px; }
  .topbar .btn { padding: 6px 10px; min-height: 40px; }
}
dialog { max-height: calc(100vh - 24px); overflow: auto; }
.actions.tight { margin: 0 0 8px; }
label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 600; }
label.check input { width: auto; margin-top: 4px; }
