/* 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%; }

/* --- icons (inline Lucide SVG) --- */
.icon { display: inline-flex; align-items: center; justify-content: center; vertical-align: -0.14em; line-height: 0; }
.icon svg { width: 1em; height: 1em; display: block; }
.icon.spin svg { animation: km-spin 0.7s linear infinite; }
@keyframes km-spin { to { transform: rotate(360deg); } }
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: 10px; }
.account-dot.on svg { fill: currentColor; }
.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;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
}
.nav-item .icon { font-size: 18px; flex-shrink: 0; }
.nav-item .nav-label { flex: 1; }
.nav-item:hover { background: var(--panel-2); }
.nav-item.active { background: var(--accent-soft); font-weight: 600; }
/* each section gets its own colour, so the sidebar is scannable at a glance */
.nav-item[data-view="in"] .icon       { color: #5b6cff; }
.nav-item[data-view="all"] .icon      { color: #22b8cf; }
.nav-item[data-view="sent"] .icon     { color: #12b886; }
.nav-item[data-view="draft"] .icon    { color: #f59f00; }
.nav-item[data-view="outbox"] .icon   { color: #fd7e14; }
.nav-item[data-view="contact"] .icon  { color: #7048e8; }
.nav-item[data-view="settings"] .icon { color: #868e96; }
.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); }

/* --- avatars (coloured initial discs) --- */
.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  flex-shrink: 0;
  user-select: none;
}
.avatar.lg { width: 46px; height: 46px; font-size: 19px; }
/* a small verified check tucked into the corner of a reading-pane avatar */
.avatar-wrap { position: relative; display: inline-flex; flex-shrink: 0; }
.avatar-badge {
  position: absolute; right: -3px; bottom: -3px;
  width: 18px; height: 18px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--panel);
  color: var(--ok);
  font-size: 13px;
}
.who-domain { color: var(--muted); font-weight: 400; }

/* --- message list --- */
.list { overflow-y: auto; border-right: 1px solid var(--line); background: var(--panel); }
.msg-row {
  position: relative;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.msg-row:hover { background: var(--panel-2); }
.msg-row.selected { background: var(--accent-soft); }
.msg-row.unread::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent);
}
.msg-main { flex: 1; min-width: 0; }
.msg-row-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.msg-who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-who strong { font-weight: 600; }
.msg-row.unread .msg-who strong { font-weight: 700; }
.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 states: vertically centered in their column, so the two line up. */
.empty, .reading-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  height: 100%;
  padding: 20px;
  text-align: center;
  color: var(--muted);
}
.empty .icon, .reading-empty .icon { font-size: 34px; opacity: 0.4; }

/* --- reading pane --- */
/* Same surface as the list — the reading pane is where you read, so it gets
   the clean panel background, not the app's grey chrome colour. */
.reading { overflow-y: auto; background: var(--panel); display: flex; flex-direction: column; }
/* A sticky action bar, Mimestream-style — actions stay reachable while reading. */
.read-toolbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; gap: 6px;
  padding: 10px 26px;
  border-bottom: 1px solid var(--line);
  background: var(--panel); /* solid fallback where color-mix/backdrop aren't supported */
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(8px);
  backdrop-filter: saturate(1.4) blur(8px);
}
.read-head { padding: 22px 26px 8px; }
.read-subject { margin: 0 0 18px; font-size: 23px; font-weight: 650; letter-spacing: -0.01em; line-height: 1.25; }
.sender-row { display: flex; align-items: center; gap: 12px; }
.sender-meta { flex: 1; min-width: 0; }
.sender-line { display: flex; align-items: baseline; gap: 10px; }
.sender-name { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sender-name strong { font-weight: 600; }
.sender-date { margin-left: auto; color: var(--muted); font-size: 12px; flex-shrink: 0; }
.sender-sub { color: var(--muted); font-size: 13px; margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* keymail's signature: a calm trust badge in plain words, never "crypto". */
.trust-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.trust-pill.ok  { color: var(--ok);  background: color-mix(in srgb, var(--ok) 14%, transparent); }
.trust-pill.bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, transparent); }

.read-body {
  padding: 8px 26px 40px;
  max-width: 720px;
  line-height: 1.6;
  font-size: 14.5px;
}
.read-body .body-line { white-space: pre-wrap; word-wrap: break-word; min-height: 1.6em; }
.body-link { color: var(--accent); text-decoration: none; word-break: break-word; }
.body-link:hover { text-decoration: underline; }
.body-quote {
  margin: 4px 0; padding: 2px 0 2px 14px;
  border-left: 3px solid var(--line);
  color: var(--muted);
}
.body-quote .body-quote { border-left-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }

/* --- 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-link { color: var(--accent); text-decoration: none; }
.sender-link:hover { text-decoration: underline; }
.btn.btn-icon { padding: 4px 11px; }

/* --- contacts --- */
.contact-row { display: flex; align-items: center; gap: 12px; padding: 10px 6px; border-bottom: 1px solid var(--line); cursor: pointer; border-radius: 8px; }
.contact-row:hover { background: var(--panel-2); }
.contact-main { flex: 1; min-width: 0; }
.contact-addr { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-addr strong { font-weight: 600; }
.contact-count { font-size: 12px; }
.contact-write { color: var(--muted); opacity: 0; }
.contact-row:hover .contact-write { opacity: 1; }
.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); }
/* ghost: a borderless toolbar button that only fills in on hover */
.btn.ghost { border-color: transparent; background: transparent; display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.ghost.danger:hover { background: color-mix(in srgb, var(--bad) 14%, transparent); }
.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; }

/* --- home / passkey sign-in --- */
.home-card { max-width: 430px; }
.home-tagline { color: var(--muted); margin: 8px 0 20px; line-height: 1.5; }
.home-name { display: flex; align-items: baseline; gap: 2px; justify-content: center; margin-bottom: 16px; }
.home-name .text-input { text-align: right; max-width: 170px; }
.home-at { color: var(--muted); }
.home-actions { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.home-btn { min-width: 260px; }
.home-status { min-height: 1.2em; color: var(--muted); font-size: 13px; margin: 14px 0 4px; }
.home-status.error { color: var(--bad); }
.home-hint { display: block; margin-top: 10px; color: var(--muted); font-size: 12px; line-height: 1.5; text-align: left; }
.home-hint > span { display: block; margin-top: 6px; }
.home-switch { color: var(--muted); font-size: 13px; margin-top: 20px; }
.home-link { color: var(--accent); text-decoration: none; font-weight: 600; }
.home-link:hover { text-decoration: underline; }

/* --- 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;
}

/* --- undo send bar (bottom-left) --- */
#undo-bar {
  position: fixed;
  left: 22px; bottom: 22px;
  display: flex; align-items: center; gap: 12px;
  background: var(--text); color: var(--bg);
  padding: 9px 10px 9px 14px;
  border-radius: 12px;
  font-size: 13px;
  z-index: 30;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.28);
  animation: undo-in 0.24s ease-out;
}
@keyframes undo-in { from { transform: translateY(14px); opacity: 0; } }
#undo-bar .icon { font-size: 16px; opacity: 0.85; }
.undo-msg { white-space: nowrap; }
.undo-track { width: 84px; height: 4px; background: rgba(255, 255, 255, 0.22); border-radius: 2px; overflow: hidden; }
.undo-fill { height: 100%; width: 100%; background: var(--bg); }
.undo-btn.btn { background: transparent; border: none; color: #a9b6ff; font-weight: 700; padding: 4px 8px; }
.undo-btn.btn:hover { background: rgba(255, 255, 255, 0.12); }

@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; }
}
