:root {
  --bg: #0e0f13;
  --panel: #15171d;
  --panel-2: #1b1e26;
  --line: #262a34;
  --text: #e8eaf0;
  --muted: #8a90a0;
  --accent: #e5484d;
  --accent-2: #ff6b70;
  --ok: #3ecf8e;
  --warn: #f5a524;
  --radius: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small-text { font-size: 12px; }
.error { color: var(--accent-2); margin: 8px 0 0; }
.grow { flex: 1; min-width: 0; }

.btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn:hover { border-color: #3a4050; background: #222633; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.danger:hover { border-color: var(--accent); color: var(--accent-2); }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.wide { width: 100%; }
input, select {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
}
input:focus, select:focus { outline: 2px solid #e5484d55; border-color: var(--accent); }

/* login */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px;
  display: grid;
  gap: 12px;
}
.login-card h1 { margin: 0; font-size: 20px; }
.login-card p { margin: 0; }

/* layout */
.app { display: grid; grid-template-columns: 290px 360px 1fr; height: 100%; }
.pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; border-right: 1px solid var(--line); }
.pane:last-child { border-right: 0; }
.sidebar { background: var(--panel); padding: 14px; gap: 12px; }
.brand { display: flex; gap: 10px; align-items: center; }
.logo { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; background: var(--accent); font-size: 18px; }
.status { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.dot.warn { background: var(--warn); }
.dot.err { background: var(--accent); }
.custom { display: grid; gap: 8px; }
.custom-row { display: grid; grid-template-columns: 1fr auto; gap: 6px; }
.custom-row input { width: 100%; }
.sidebar-foot { display: flex; gap: 6px; justify-content: space-between; }

.inbox-list {
  flex: 1; overflow-y: auto; overflow-x: hidden; margin: 0 -6px; padding: 0 6px;
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; align-content: start;
}
.inbox-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; border: 1px solid transparent;
}
.inbox-item:hover { background: var(--panel-2); }
.inbox-item.active { background: var(--panel-2); border-color: var(--line); }
.inbox-item .addr { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox-item .addr small { display: block; color: var(--muted); font-size: 11px; }
.badge { background: var(--accent); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700; padding: 1px 7px; }
.badge.zero { background: transparent; color: var(--muted); font-weight: 400; }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 4px; border-radius: 6px; }
.icon-btn:hover { color: var(--text); background: #2a2f3b; }

.pane-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); min-height: 58px; }
.list .actions { flex-basis: 100%; justify-content: flex-start; }
.title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.back { display: none; }

.message-list { flex: 1; overflow-y: auto; }
.msg {
  padding: 11px 14px; border-bottom: 1px solid var(--line); cursor: pointer;
  display: grid; gap: 2px;
}
.msg:hover { background: var(--panel); }
.msg.active { background: var(--panel-2); }
.msg.fresh { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: #e5484d33; } to { background: transparent; } }
.msg-top { display: flex; gap: 8px; align-items: baseline; }
.msg-from { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.unread .msg-from, .msg.unread .msg-subject { font-weight: 700; }
.msg-time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.msg-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-snippet { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-to { color: var(--muted); font-size: 11px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.chip {
  background: #3ecf8e1f; color: var(--ok); border: 1px solid #3ecf8e55; border-radius: 6px;
  padding: 1px 8px; font: 600 12px ui-monospace, Consolas, monospace; cursor: pointer;
}
.chip:hover { background: #3ecf8e33; }

.empty { color: var(--muted); padding: 40px 20px; text-align: center; }

.viewer-body { flex: 1; overflow-y: auto; display: flex; flex-direction: column; min-height: 0; }
.mail-head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: grid; gap: 4px; }
.mail-head h2 { margin: 0; font-size: 18px; word-break: break-word; }
.kv { display: flex; gap: 8px; font-size: 13px; }
.kv span:first-child { color: var(--muted); min-width: 52px; }
.kv span:last-child { word-break: break-all; }
.tabs { display: flex; gap: 4px; padding: 8px 16px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; align-items: center; }
.tab { background: none; border: 0; padding: 8px 10px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tabs .spacer { flex: 1; }
.tabs label { color: var(--muted); font-size: 12px; display: flex; gap: 6px; align-items: center; cursor: pointer; }
.mail-body { flex: 1; min-height: 240px; padding: 14px 16px; display: flex; }
.mail-body iframe { flex: 1; width: 100%; min-height: 360px; border: 0; background: #fff; border-radius: 8px; }
.mail-body pre { margin: 0; white-space: pre-wrap; word-break: break-word; font: 13px/1.5 ui-monospace, Consolas, monospace; width: 100%; }
.list-links { display: grid; gap: 6px; width: 100%; align-content: start; }
.list-links a { color: var(--accent-2); word-break: break-all; }
.attach { display: flex; gap: 10px; align-items: center; padding: 8px 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: #232734; border: 1px solid var(--line); padding: 9px 16px; border-radius: 10px;
  box-shadow: 0 8px 30px #0008; z-index: 10;
}

@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .pane { display: none; border-right: 0; }
  body[data-view="inboxes"] .sidebar,
  body[data-view="messages"] .list,
  body[data-view="viewer"] .viewer { display: flex; }
  .back { display: inline-block; }
}
