:root {
  --blue: #004ac6;
  --blue-deep: #00174b;
  --blue-soft: #dbe1ff;
  --ink: #191c1e;
  --ink-2: #434655;
  --ink-3: #6b6f7c;
  --surface: #f7f9fb;
  --paper: #ffffff;
  --rule: #dfe3e8;
  --red: #ba1a1a;
  --red-soft: #ffdad6;
  --sans: "Public Sans", "Helvetica Neue", Arial, sans-serif;
  --rail-w: 220px;
  --list-w: 380px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
a { color: var(--blue); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.wordmark { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; color: var(--blue-deep); }
.wordmark span { font-weight: 400; color: var(--ink-3); margin-left: 6px; }
.muted { color: var(--ink-3); }
.small { font-size: 12.5px; }

/* Buttons */
.btn {
  border: 1px solid var(--rule);
  background: var(--paper);
  border-radius: 6px;
  padding: 7px 12px;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #003a9c; }
.btn.quiet { background: transparent; }
.btn.danger { color: var(--red); border-color: var(--red-soft); }
.btn.danger:hover { background: var(--red-soft); }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn[disabled] { opacity: 0.6; cursor: default; }

/* Sign in */
.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(380px, 100%);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 28px 28px 24px;
  display: grid;
  gap: 14px;
}
.login-lede { margin: -4px 0 6px; color: var(--ink-2); }
.login-card label { display: grid; gap: 6px; font-weight: 500; }
.login-card input {
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 9px 10px;
  background: var(--surface);
}
.login-card input:focus { border-color: var(--blue); background: var(--paper); outline: none; box-shadow: 0 0 0 3px var(--blue-soft); }
.login-error { margin: 0; color: var(--red); }

/* App frame */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}
.search input {
  width: min(520px, 100%);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 8px 12px;
  background: var(--surface);
}
.search input:focus { border-color: var(--blue); background: var(--paper); outline: none; box-shadow: 0 0 0 3px var(--blue-soft); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.who { color: var(--ink-2); }

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--rail-w) var(--list-w) 1fr;
}

/* Address rail */
.rail {
  border-right: 1px solid var(--rule);
  padding: 12px 8px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.rail-item {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 7px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.rail-item:hover { background: #eceff3; }
.rail-item.active { background: var(--blue-soft); color: var(--blue-deep); font-weight: 600; }
.rail-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-count { color: var(--ink-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.rail-item.active .rail-count { color: var(--blue-deep); }
.rail-count.unread { color: var(--blue); font-weight: 600; }
.rail-foot { margin-top: auto; padding: 12px 10px 4px; display: grid; gap: 10px; border-top: 1px solid var(--rule); }
.toggle { display: flex; gap: 8px; align-items: center; cursor: pointer; }

/* Message list */
.list { border-right: 1px solid var(--rule); overflow: auto; background: var(--paper); display: flex; flex-direction: column; }
.list-items { flex: 1; }
.item {
  width: 100%;
  display: grid;
  grid-template-columns: 14px 1fr auto;
  column-gap: 10px;
  padding: 11px 14px 11px 10px;
  border: 0;
  border-bottom: 1px solid var(--rule);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.item:hover { background: var(--surface); }
.item.active { background: var(--blue-soft); }
.dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; background: transparent; }
.item.unread .dot { background: var(--blue); }
.item-main { min-width: 0; }
.item-from { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.unread .item-from, .item.unread .item-subject { font-weight: 700; }
.item-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-to { color: var(--ink-3); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { text-align: right; color: var(--ink-3); font-size: 12px; white-space: nowrap; display: grid; gap: 4px; }
.clip { display: inline-block; padding: 0 6px; border-radius: 4px; background: var(--surface); border: 1px solid var(--rule); }
.list-foot { padding: 10px; display: flex; justify-content: center; }
.empty { padding: 40px 24px; text-align: center; }
.empty p { margin: 0 0 6px; }

/* Reader */
.reader { overflow: auto; padding: 20px 28px 40px; background: var(--surface); }
.reader-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.reader-actions { display: flex; gap: 8px; }
.back { display: none; }
.subject { font-size: 22px; font-weight: 600; line-height: 1.25; margin: 0 0 12px; letter-spacing: -0.01em; max-width: 46em; }
.route { display: grid; gap: 4px; margin-bottom: 16px; }
.route-line { display: grid; grid-template-columns: 76px 1fr; gap: 10px; }
.route-k { color: var(--ink-3); }
.route-line .addr { color: var(--ink-2); }
.route-line strong { font-weight: 600; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.attachment {
  display: inline-flex; gap: 8px; align-items: center;
  padding: 7px 10px; border: 1px solid var(--rule); border-radius: 6px; background: var(--paper);
  color: var(--ink); text-decoration: none;
}
.attachment:hover { border-color: var(--blue); }
.attachment .sz { color: var(--ink-3); font-size: 12px; }
.body-tools { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; background: var(--paper); }
.seg-btn { border: 0; background: transparent; padding: 5px 11px; cursor: pointer; font-size: 12.5px; }
.seg-btn.active { background: var(--blue-soft); color: var(--blue-deep); font-weight: 600; }
.html-frame { width: 100%; min-height: 240px; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); }
.text-body {
  white-space: pre-wrap; word-wrap: break-word; margin: 0;
  padding: 16px 18px; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper);
  font: inherit; max-width: 80ch;
}
.headers { margin-top: 18px; }
.headers summary { cursor: pointer; color: var(--ink-2); }
.headers pre { font-size: 12px; white-space: pre-wrap; word-break: break-all; background: var(--paper); border: 1px solid var(--rule); border-radius: 8px; padding: 12px; }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 9px 14px; border-radius: 6px; font-size: 13px;
}

/* Narrow screens: rail collapses to a row, list and reader stack */
@media (max-width: 960px) {
  .topbar { grid-template-columns: auto 1fr auto; }
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .rail { flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--rule); padding: 8px; }
  .rail-item { width: auto; }
  .rail-foot { margin: 0 0 0 auto; padding: 0 4px; border: 0; grid-auto-flow: column; align-items: center; }
  .list { border-right: 0; }
  .reader { padding: 16px; }
  .app.reading .list { display: none; }
  .app:not(.reading) .reader { display: none; }
  .back { display: inline-block; }
  .who { display: none; }
}
@media (prefers-reduced-motion: no-preference) {
  .item, .rail-item, .btn { transition: background-color 120ms ease, border-color 120ms ease; }
}

/* Sent folder entry sits after the addresses */
.rail-sent { margin-top: 8px; border-top: 1px solid var(--rule); border-radius: 0 0 6px 6px; padding-top: 10px; }

/* Compose */
.compose-backdrop {
  position: fixed; inset: 0; background: rgba(25, 28, 30, 0.45);
  display: grid; place-items: center; padding: 20px; z-index: 20;
}
.compose {
  width: min(720px, 100%); max-height: 100%; overflow: auto;
  background: var(--paper); border-radius: 10px; border: 1px solid var(--rule);
  padding: 18px 20px 16px; display: grid; gap: 10px;
}
.compose-head { display: flex; justify-content: space-between; align-items: center; }
.compose-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.compose .row { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 8px; }
.compose .row span { color: var(--ink-3); }
.compose input, .compose textarea {
  border: 1px solid var(--rule); border-radius: 6px; padding: 8px 10px; background: var(--surface); width: 100%;
}
.compose input:focus, .compose textarea:focus { border-color: var(--blue); background: var(--paper); outline: none; box-shadow: 0 0 0 3px var(--blue-soft); }
.compose textarea { resize: vertical; min-height: 160px; }
.compose-files { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.file-btn { display: inline-block; }
.file-list { display: flex; gap: 6px; flex-wrap: wrap; }
.file-chip { display: inline-flex; gap: 6px; align-items: center; padding: 4px 8px; border: 1px solid var(--rule); border-radius: 6px; font-size: 12.5px; }
.file-chip button { border: 0; background: none; cursor: pointer; color: var(--ink-3); padding: 0 2px; }
.compose-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.item.sent .item-from::before { content: "To "; color: var(--ink-3); font-weight: 400; }
#notify-btn.on { color: var(--blue-deep); background: var(--blue-soft); border-color: var(--blue-soft); }
@media (max-width: 960px) {
  #notify-btn { display: none; }
  .compose .row { grid-template-columns: 1fr; }
}

/* Settings + category */
.type-row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.compose select { border: 1px solid var(--rule); border-radius: 6px; padding: 8px 10px; background: var(--surface); }
.settings section { display: grid; gap: 8px; padding-bottom: 6px; border-bottom: 1px solid var(--rule); }
.settings section:last-of-type { border-bottom: 0; }
.settings h3 { margin: 4px 0 2px; font-size: 14px; font-weight: 600; }
.settings .row select { width: 100%; }
.sig-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start; }
.sig-row textarea { min-height: 70px; }
.compliance { display: grid; gap: 6px; }
.check { display: grid; grid-template-columns: 18px 1fr; gap: 8px; align-items: start; }
.check .mark { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; }
.check.ok .mark { background: var(--green, #1f6b3a); }
.check.fail .mark { background: var(--red); }
.check.warn .mark { background: var(--amber, #a8690e); }
.check .detail { color: var(--ink-3); font-size: 12.5px; word-break: break-word; }
.compliance-summary { font-weight: 600; }
.compliance-summary.ok { color: #1f6b3a; }
.compliance-summary.fail { color: var(--red); }
.cat { display: inline-block; padding: 0 6px; border-radius: 4px; background: var(--blue-soft); color: var(--blue-deep); font-size: 11px; }
:root { --green: #1f6b3a; --amber: #a8690e; }
.compose input[type="checkbox"] { width: auto; margin: 0; }
.settings .toggle { justify-content: flex-start; }
