:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f1f3f6; --border: #e3e6eb;
  --text: #16181d; --muted: #6b7280; --accent: #4f46e5; --accent-ink: #ffffff; --accent-soft: #eef0ff;
  --green: #16a34a; --green-soft: #dcfce7; --green-ink: #166534; --red: #dc2626; --red-soft: #fee2e2;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --surface: #171a21; --surface-2: #1e222b; --border: #2a2f3a;
    --text: #e8eaef; --muted: #9aa3b2; --accent: #818cf8; --accent-ink: #0f1115; --accent-soft: #232646;
    --green: #4ade80; --green-soft: #14321f; --green-ink: #86efac; --red: #f87171; --red-soft: #3b1a1a;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 Inter, -apple-system, system-ui, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; font-weight: 700; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 600; margin: 28px 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
code, kbd { font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.container { max-width: 900px; margin: 0 auto; padding: 24px 16px 64px; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px max(16px, calc((100vw - 900px) / 2 + 16px)); background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); font-size: 16px; }
.brand:hover { text-decoration: none; }
.logo { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-size: 15px; }
.logo.big { width: 48px; height: 48px; font-size: 24px; border-radius: 14px; margin: 0 auto 12px; }
nav { display: flex; align-items: center; gap: 14px; }
nav a:not(.btn) { color: var(--muted); font-weight: 500; }
nav a.active { color: var(--text); }
nav form { margin: 0; }
.linkish { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: 0; }
.linkish:hover { color: var(--text); }

/* buttons + inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 9px;
  border: 1px solid transparent; font: 600 14px Inter, system-ui, sans-serif; cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; filter: brightness(1.05); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-gmail { background: var(--green-soft); color: var(--green-ink); border-color: transparent; }
.btn[hidden] { display: none; }
input { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; padding: 10px 12px; outline: none; }
input:focus, .editor:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.alert { background: var(--red-soft); color: var(--red); padding: 10px 12px; border-radius: 9px; font-size: 14px; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; padding: 32px 28px; text-align: center; }
.login label { text-align: left; margin-top: 18px; }
.login .btn { margin-top: 14px; }
.login .alert { margin-top: 14px; text-align: left; }

/* list */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 0; }
.search input { width: 260px; max-width: 100%; }
.list { overflow: hidden; }
.row { display: flex; align-items: center; gap: 14px; padding: 14px 18px; color: var(--text); border-top: 1px solid var(--border); }
.row:first-child { border-top: 0; }
.row:hover { background: var(--surface-2); text-decoration: none; }
.dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--border); }
.dot.on { background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-subject { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-to { color: var(--muted); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-status { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.row-time { color: var(--muted); font-size: 12.5px; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.pill-self { background: var(--accent-soft); color: var(--accent); }
.switch { display: inline-flex; align-items: center; gap: 8px; background: none; border: 0; padding: 0; color: var(--muted); font: 500 13px Inter, system-ui, sans-serif; cursor: pointer; }
.switch:hover { color: var(--text); }
.switch-track { position: relative; width: 30px; height: 18px; border-radius: 999px; background: var(--border); transition: background .15s; }
.switch-thumb { position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch[aria-checked="true"] .switch-track { background: var(--green); }
.switch[aria-checked="true"] .switch-thumb { transform: translateX(12px); }
.pill-open { background: var(--green-soft); color: var(--green-ink); }
.empty { padding: 40px 24px; text-align: center; }
.empty p { margin: 4px 0; }
.empty .btn { margin-top: 14px; }
.empty-emoji { font-size: 36px; }

/* detail */
.back { display: inline-block; margin-bottom: 14px; font-size: 14px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat { padding: 16px; }
.stat-num { font-size: 22px; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 13px; }
.timeline { display: flex; flex-direction: column; gap: 10px; }
.open { padding: 14px 18px; }
.open.ignored { opacity: .55; }
.open-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px 16px; margin: 0; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 0; font-size: 14px; overflow-wrap: anywhere; }
.note { margin: 10px 0 0; font-size: 13px; color: var(--muted); }
details { margin-top: 8px; font-size: 13px; color: var(--muted); }
details summary { cursor: pointer; }
.ua { display: block; margin-top: 6px; white-space: normal; overflow-wrap: anywhere; }
.message { display: block; width: 100%; min-height: 160px; padding: 18px; background: #fff; }

.proxy-tag { text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--accent); margin-left: 6px; }
.head-actions { display: flex; gap: 8px; }
.all-data { margin-top: 12px; }
.all-data > summary { font-weight: 600; color: var(--accent); }
.data-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px 24px; margin-top: 12px; }
.data-grid .wide { grid-column: 1 / -1; }
.data-grid h3 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.kv { width: 100%; border-collapse: collapse; font-size: 13px; color: var(--text); }
.kv th { text-align: left; font-weight: 500; color: var(--muted); padding: 4px 12px 4px 0; vertical-align: top; white-space: nowrap; width: 1%; }
.kv td { padding: 4px 0; overflow-wrap: anywhere; }
.kv tr + tr th, .kv tr + tr td { border-top: 1px solid var(--border); }
.kv.mono td, .kv.mono th { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; }
.raw { margin: 0; padding: 12px; background: var(--surface-2); border-radius: 8px; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text); overflow-x: auto; }

/* compose */
.compose { padding: 6px 18px 18px; }
.field-row { display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border); }
.field-row label { width: 64px; margin: 0; color: var(--muted); font-weight: 500; font-size: 14px; }
.field-row input { border: 0; padding: 14px 0; border-radius: 0; background: transparent; }
.field-row input:focus { box-shadow: none; }
.toolbar { display: flex; flex-wrap: wrap; gap: 4px; padding: 10px 0; align-items: center; }
.toolbar button { background: none; border: 1px solid transparent; border-radius: 7px; padding: 5px 9px; font: 13px Inter, system-ui, sans-serif; color: var(--text); cursor: pointer; }
.toolbar button:hover { background: var(--surface-2); }
.toolbar .sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }
.editor { min-height: 280px; padding: 14px; border: 1px solid var(--border); border-radius: 9px; outline: none; overflow-wrap: anywhere; }
.editor:empty::before { content: attr(data-placeholder); color: var(--muted); }
.editor ul, .editor ol { padding-left: 22px; }
.compose-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.help { padding: 16px 20px; margin-top: 16px; font-size: 14px; }
.help p { margin: 6px 0; }

/* toast */
#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 10px; font-weight: 500; font-size: 14px;
  transition: all .2s; max-width: calc(100vw - 32px); z-index: 20; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--red); color: #fff; }

@media (max-width: 600px) {
  .stats { grid-template-columns: 1fr; }
  .row { padding: 12px 14px; }
  .search, .search input { width: 100%; }
  nav { gap: 10px; }
  .switch { font-size: 0; gap: 0; }
  .kv th { white-space: normal; width: 38%; }
  .head-actions { width: 100%; }
}
