/* keymail — looks, feels, smells like email. */

:root {
  color-scheme: light dark;
  --bg: light-dark(#f4f4f2, #14161a);
  --panel: light-dark(#ffffff, #1c1f25);
  --panel-2: light-dark(#fafaf8, #22262d);
  --text: light-dark(#1b1d21, #e8e9eb);
  --muted: light-dark(#6b7280, #9aa1ab);
  --line: light-dark(#e4e4e0, #2c313a);
  --accent: light-dark(#3f51b5, #8c9eff);
  --accent-soft: light-dark(#eef0fb, #262c3f);
  --ok: light-dark(#1a7f37, #4ade80);
  --warn: light-dark(#b45309, #fbbf24);
  --bad: light-dark(#b91c1c, #f87171);
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
/* The `hidden` attribute must win over author `display` rules. Elements like
   #locked and #app set `display:flex` via an ID selector, which outranks the
   UA sheet's `[hidden]{display:none}` — so without this, toggling `hidden` in
   JS does nothing and the locked card paints on top of a claimed inbox. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}

/* --- top bar --- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.wordmark { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }
.wordmark-accent { color: var(--accent); }
#search {
  flex: 1;
  max-width: 560px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
#search:focus { outline: 2px solid var(--accent); border-color: transparent; }
.me {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  position: relative;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius);
  user-select: none;
}
.me:hover { background: var(--panel-2); }
.me-caret { font-size: 10px; }
.account-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 240px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
  padding: 6px;
  z-index: 25;
}
.account-item, .account-action {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
}
.account-item:hover, .account-action:hover { background: var(--panel-2); }
.account-item.current { font-weight: 600; cursor: default; }
.account-dot { color: var(--accent); font-size: 11px; }
.account-sep { height: 1px; background: var(--line); margin: 6px 4px; }
.account-action { color: var(--muted); }
.account-action.danger { color: var(--bad); }

/* --- layout --- */
#app { display: flex; flex-direction: column; height: 100vh; }
.layout {
  display: grid;
  grid-template-columns: 180px minmax(280px, 420px) 1fr;
  flex: 1;
  min-height: 0;
}
.layout.wide { grid-template-columns: 180px 1fr 0; }
.layout.wide .reading { display: none; }

/* --- sidebar --- */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 10px;
  border-right: 1px solid var(--line);
}
#compose-btn { margin-bottom: 12px; }
.nav-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 12px;
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
}
.nav-item:hover { background: var(--panel-2); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.badge {
  background: var(--accent);
  color: white;
  border-radius: 10px;
  padding: 0 7px;
  font-size: 11px;
  line-height: 18px;
}
.badge.bad { background: var(--bad); }
.badge:empty { display: none; }
.sidebar-foot { margin-top: auto; padding: 10px 12px; font-size: 12px; color: var(--muted); }

/* --- message list --- */
.list { overflow-y: auto; border-right: 1px solid var(--line); background: var(--panel); }
.msg-row {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.msg-row:hover { background: var(--panel-2); }
.msg-row.selected { background: var(--accent-soft); }
.msg-row-top { display: flex; justify-content: space-between; gap: 8px; }
.msg-who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-row.unread .msg-who::before {
  content: "";
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 6px;
}
.msg-date { color: var(--muted); font-size: 12px; flex-shrink: 0; }
.msg-subject { margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-row.unread .msg-subject { font-weight: 600; }
.msg-snippet { color: var(--muted); font-size: 12px; margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* --- reading pane --- */
.reading { overflow-y: auto; padding: 20px 26px; background: var(--bg); }
.reading-empty { color: var(--muted); text-align: center; margin-top: 80px; }
.read-head h2 { margin: 0 0 10px; font-size: 20px; }
.read-meta { color: var(--muted); font-size: 13px; display: grid; gap: 2px; }
.sig.ok { color: var(--ok); }
.sig.bad { color: var(--bad); font-weight: 700; }
.read-actions { margin: 14px 0; display: flex; gap: 8px; }
.read-body {
  font: inherit;
  white-space: pre-wrap;
  word-wrap: break-word;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  line-height: 1.55;
}

/* --- outbox --- */
.outbox-row { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.outbox-state { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.state-mining .outbox-state { color: var(--warn); }
.state-failed .outbox-state { color: var(--bad); }
.mine-info { margin-top: 6px; font-size: 13px; }
.mine-bar {
  margin-top: 6px;
  height: 6px;
  background: var(--line);
  border-radius: 3px;
  overflow: hidden;
}
.mine-fill {
  height: 100%;
  background: var(--warn);
  transition: width 0.5s linear;
}
.mine-note { font-size: 12px; margin-top: 4px; }
.outbox-error { color: var(--bad); font-size: 13px; margin-top: 6px; }

/* --- panels (senders, settings) --- */
.panel { max-width: 640px; padding: 24px; }
.panel h2 { margin-top: 0; }
.panel h3 { margin: 22px 0 6px; }
.senders-table { width: 100%; border-collapse: collapse; margin: 10px 0; }
.senders-table th {
  text-align: left; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); padding: 6px 8px;
}
.senders-table td { padding: 8px; border-top: 1px solid var(--line); }
.sender-actions { display: flex; gap: 6px; justify-content: flex-end; }
.state-pill {
  padding: 2px 10px; border-radius: 10px; font-size: 12px;
  background: var(--panel-2); border: 1px solid var(--line);
}
.state-pill.state-trusted { color: var(--ok); border-color: var(--ok); }
.state-pill.state-proven { color: var(--accent); border-color: var(--accent); }
.state-pill.state-blocked { color: var(--bad); border-color: var(--bad); }
.pretrust { display: flex; gap: 8px; margin-top: 14px; }
.pow-slider { width: 100%; margin: 10px 0 6px; accent-color: var(--accent); }
.pow-readout { margin-bottom: 8px; }
.dns-rec { background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px; overflow-x: auto; }

/* --- buttons, inputs --- */
.btn {
  font: inherit;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 3px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.text-input {
  font: inherit;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
}
.text-input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.mono { font-family: var(--mono); }
.small { font-size: 12px; }
.muted { color: var(--muted); }
.error { color: var(--bad); }

/* --- compose modal --- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex; align-items: center; justify-content: center;
  z-index: 20;
}
.modal {
  width: min(680px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--panel);
  border-radius: 14px;
  padding: 20px 22px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
  display: flex; flex-direction: column; gap: 6px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal label { font-size: 12px; color: var(--muted); margin-top: 6px; }
.compose-body { font: inherit; resize: vertical; }
textarea.compose-body {
  width: 100%; padding: 10px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); color: var(--text);
  line-height: 1.5;
}
.compose-price { font-size: 13px; min-height: 18px; margin-top: 6px; }
.compose-status { flex: 1; font-size: 13px; color: var(--warn); }
.modal-foot { display: flex; align-items: center; gap: 10px; margin-top: 10px; }

/* --- claim page / locked --- */
.claim-body, #locked {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
}
.claim-card {
  max-width: 460px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 34px 38px;
  text-align: center;
}
.claim-card h1 { letter-spacing: -0.02em; }
.claim-note { color: var(--muted); font-size: 13px; line-height: 1.5; }
.claim-detail { color: var(--warn); font-size: 13px; margin: 8px 0; }
#claim-go { margin: 12px 0 6px; }
.claim-alt { margin: 0 0 12px; }
.locked-actions { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; align-items: center; }
.locked-actions .btn { min-width: 220px; }

/* --- toast --- */
#toast {
  position: fixed;
  bottom: 22px; left: 50%;
  transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 30;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 64px 1fr 0; }
  .layout .reading { display: none; }
  .nav-item { justify-content: center; font-size: 12px; }
  .sidebar-foot { display: none; }
}
