:root {
  --bg: #f6f6f4; --panel: #fff; --line: #e3e2de; --text: #1c1c1a; --muted: #6f6e69;
  --accent: #d93a3f; --accent-soft: #fdecec; --hover: #f1f0ec; --code: #f3f2ee; --ok: #1a7f4b;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131312; --panel: #1b1b1a; --line: #2e2e2b; --text: #ecebe7; --muted: #9a988f;
    --accent: #ff6369; --accent-soft: #3a1c1e; --hover: #242422; --code: #232321; --ok: #4cc38a;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
#app { height: 100%; display: flex; flex-direction: column; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 5px 10px; }
button:hover { background: var(--hover); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--accent); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
button:focus-visible, input:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=text], input[type=search], input[type=email], input[type=date] {
  border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 6px 9px; min-width: 0;
}
a { color: var(--accent); }
.muted { color: var(--muted); }
.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 8px; align-items: center; }
.wrap { flex-wrap: wrap; }

header.top { display: flex; align-items: center; gap: 12px; padding: 9px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.logo { font-weight: 800; font-size: 17px; letter-spacing: -0.02em; display: flex; align-items: center; gap: 7px; }
.logo span.zap { background: var(--accent); color: #fff; border-radius: 6px; width: 24px; height: 24px; display: grid; place-items: center; font-size: 14px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; }

main.cols { flex: 1; min-height: 0; display: grid; grid-template-columns: 230px minmax(300px, 420px) 1fr; }
main.cols > section { min-height: 0; display: flex; flex-direction: column; border-right: 1px solid var(--line); }
main.cols > section:last-child { border-right: 0; background: var(--panel); }

.side { padding: 12px 8px; overflow: auto; }
.side h2 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); margin: 6px 8px; font-weight: 600; }
.inbox { display: flex; align-items: center; gap: 6px; padding: 7px 8px; border-radius: 6px; cursor: pointer; width: 100%; border: 0; background: none; text-align: left; }
.inbox:hover { background: var(--hover); }
.inbox.active { background: var(--accent-soft); font-weight: 600; }
.inbox .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--accent); color: #fff; border-radius: 10px; font-size: 11px; font-weight: 700; padding: 0 6px; min-width: 18px; text-align: center; }
.tag { font-size: 10px; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; color: var(--muted); font-weight: 400; }
.side .new { margin: 8px; width: calc(100% - 16px); }

.listhead { padding: 10px 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.listhead h1 { font-size: 15px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.filters label { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); gap: 2px; }
.filters label.check { flex-direction: row; align-items: center; font-size: 13px; color: var(--text); gap: 6px; }
.list { flex: 1; overflow: auto; }
.msg { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: none; padding: 9px 12px 9px 14px; position: relative; }
.msg:hover { background: var(--hover); }
.msg.active { background: var(--accent-soft); }
.msg.unread::before { content: ""; position: absolute; left: 4px; top: 15px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.msg.unread .subject { font-weight: 700; }
.msg .line1 { display: flex; gap: 8px; font-size: 12px; color: var(--muted); }
.msg .line1 .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .subject, .msg .snippet { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .snippet { font-size: 12px; color: var(--muted); }
.empty { padding: 28px 20px; color: var(--muted); text-align: center; }
.listfoot { padding: 6px 12px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }

.detail { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.detail .head { padding: 14px 18px 10px; border-bottom: 1px solid var(--line); }
.detail h1 { font-size: 18px; margin: 0 0 8px; overflow-wrap: anywhere; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; font-size: 13px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; overflow-wrap: anywhere; }
.atts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.att { border: 1px solid var(--line); border-radius: 6px; padding: 4px 9px; text-decoration: none; color: var(--text); font-size: 13px; }
.att:hover { background: var(--hover); }
.tabs { display: flex; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--line); align-items: center; }
.tabs button.tab { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 10px; color: var(--muted); }
.tabs button.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.body { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; }
.body iframe { flex: 1; border: 0; width: 100%; background: #fff; }
.body pre { margin: 0; padding: 16px 18px; white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
table.headers { border-collapse: collapse; width: 100%; font-size: 13px; }
table.headers th { text-align: left; vertical-align: top; padding: 5px 12px 5px 18px; color: var(--muted); font-weight: 500; white-space: nowrap; }
table.headers td { padding: 5px 18px 5px 0; overflow-wrap: anywhere; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
table.headers tr { border-bottom: 1px solid var(--line); }

.setup { padding: 22px; max-width: 620px; }
.setup h2 { font-size: 16px; margin: 0 0 6px; }
pre.code { background: var(--code); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; overflow: auto; font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; margin: 8px 0; }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); padding: 0; width: min(600px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog .inner { padding: 20px 22px; display: flex; flex-direction: column; gap: 16px; }
dialog h2 { margin: 0; font-size: 17px; }
dialog h3 { margin: 0 0 6px; font-size: 13px; }
dialog .share { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
dialog hr { border: 0; border-top: 1px solid var(--line); margin: 0; width: 100%; }

.login { margin: auto; text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 36px 40px; max-width: 400px; display: flex; flex-direction: column; gap: 14px; align-items: center; }
.login .logo { font-size: 26px; }
.login .logo span.zap { width: 34px; height: 34px; font-size: 20px; }
.login a.primary { display: inline-block; background: var(--accent); color: #fff; font-weight: 600; text-decoration: none; padding: 9px 18px; border-radius: 8px; }
.error { color: var(--accent); }

#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 7px 14px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
#toast.show { opacity: 1; }

@media (max-width: 900px) {
  main.cols { grid-template-columns: 1fr; grid-template-rows: auto minmax(220px, 40vh) 1fr; overflow: auto; }
  main.cols > section { border-right: 0; border-bottom: 1px solid var(--line); }
  .side { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px; }
  .side h2 { display: none; }
  .inbox, .side .new { width: auto; margin: 0; }
}
