:root {
  color-scheme: light dark;
  --bg: #071126;
  --rail: #061c38;
  --panel: #0e203a;
  --text: #ecf7f5;
  --muted: #91a9b6;
  --accent: #54e2bd;
  --accent-ink: #061c2d;
  --service-bg: #0d3a47;
  --service-border: #398f84;
  --danger: #ff6b6b;
  --border: #1f3b52;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f7f7;
    --rail: #e7f3f1;
    --panel: #ffffff;
    --text: #102c38;
    --muted: #5d727b;
    --accent: #087e69;
    --accent-ink: #ffffff;
    --service-bg: #d9efeb;
    --service-border: #78afa7;
    --border: #cfe0df;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, sans-serif;
}
.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}
.service-rail {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: calc(1.2rem + env(safe-area-inset-top)) 1rem 1rem;
  background: var(--rail);
  border-right: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.15rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}
.brand img { border-radius: 10px; }
.rail-label, .eyebrow {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}
.rail-label { margin: 2rem 0 0.5rem 0.65rem; }
.service-tile {
  display: flex;
  width: 100%;
  gap: 0.75rem;
  align-items: center;
  padding: 0.75rem;
  text-align: left;
  background: var(--service-bg);
  color: var(--text);
  border: 1px solid var(--service-border);
}
.service-tile small { display: block; margin-top: 0.1rem; color: var(--muted); }
.service-glyph {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 900;
  letter-spacing: -0.08em;
}
.workspace {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 0 1.25rem calc(2rem + env(safe-area-inset-bottom));
}
.workspace-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: calc(1.25rem + env(safe-area-inset-top)) 0 1rem;
}
h1 { font-size: 1.45rem; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 1rem; margin: 0 0 0.75rem; }
.eyebrow { margin: 0 0 0.1rem; }
.header-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.5rem; }
section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.15rem;
  margin-bottom: 1rem;
  box-shadow: 0 18px 50px rgb(0 0 0 / 10%);
}
/* An author rule for a bare element beats the user-agent's [hidden] rule, so `label { display:
   block }` kept showing the confirm-passphrase field the unlock view hides. Unlocking an existing
   vault then looked like creating a new one. */
[hidden] { display: none !important; }
label { display: block; margin-bottom: 0.75rem; color: var(--muted); font-size: 0.85rem; }
input, textarea, select {
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
button {
  padding: 0.55rem 0.9rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}
button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--border); }
button.danger { background: var(--danger); }
.row { display: flex; gap: 0.5rem; align-items: center; }
.row > input, .row > select { flex: 1; }
.hint { color: var(--muted); font-size: 0.8rem; }
#status {
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}
#status.error { color: var(--danger); }
#entries { list-style: none; margin: 0.75rem 0 0; padding: 0; }
#entries li {
  border-top: 1px solid var(--border);
  padding: 0.6rem 0.15rem;
}
#entries li:first-child { border-top: none; }
.entry-head { display: flex; justify-content: space-between; align-items: center; cursor: pointer; }
.entry-name { font-weight: 600; }
.entry-sub { color: var(--muted); font-size: 0.8rem; }
.scope-badge {
  font-size: 0.7rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
}
.legal-links {
  display: flex;
  justify-content: center;
  gap: 1rem;
  padding: 0.25rem 0 1rem;
  color: var(--muted);
  font-size: 0.8rem;
}
.legal-links a, .legal-content a { color: var(--accent); }
.legal-page {
  width: min(760px, calc(100% - 2rem));
  margin: 0 auto;
  padding: calc(1.5rem + env(safe-area-inset-top)) 0 calc(2rem + env(safe-area-inset-bottom));
}
.legal-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 750;
}
.legal-header img { border-radius: 10px; }
.legal-content h1 { font-size: clamp(1.75rem, 5vw, 2.5rem); }
.legal-content h2 { margin-top: 1.75rem; font-size: 1.15rem; }
.legal-content li + li { margin-top: 0.45rem; }
.legal-updated { color: var(--muted); }
.legal-callout {
  border-left: 4px solid var(--accent);
  padding: 0.25rem 1rem;
  background: var(--service-bg);
  border-radius: 0 10px 10px 0;
}
.entry-detail { margin-top: 0.6rem; display: grid; gap: 0.4rem; }
.field-row { display: flex; gap: 0.5rem; align-items: center; font-size: 0.9rem; }
.field-row .k { color: var(--muted); width: 5.5rem; flex-shrink: 0; font-size: 0.8rem; }
.field-row .v { flex: 1; overflow-wrap: anywhere; font-family: ui-monospace, monospace; }
.field-row button { padding: 0.2rem 0.55rem; font-size: 0.75rem; }

/* ---------- Notifications service ---------- */
.service-tile + .service-tile { margin-top: 0.5rem; }
.service-tile:not([aria-current]) { background: transparent; border-color: var(--border); }
.unread-badge {
  margin-left: auto;
  min-width: 1.5rem;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.72rem;
  font-weight: 800;
  text-align: center;
}
#notif-status {
  padding: 0.5rem 0.75rem;
  margin: 0 0 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}
#notif-status.error { color: var(--danger); }
.notif-toolbar { justify-content: space-between; }
.inline-check { display: flex; align-items: center; gap: 0.4rem; margin: 0; }
.inline-check input { width: auto; margin: 0; }
#notif-list, #notif-devices { list-style: none; margin: 0.75rem 0 0; padding: 0; }
.notif-card {
  border-top: 1px solid var(--border);
  padding: 0.75rem 0.15rem;
}
.notif-card:first-child { border-top: none; }
.notif-card.dismissed { opacity: 0.55; }
.notif-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; }
.notif-title { font-weight: 650; overflow-wrap: anywhere; }
.notif-when { color: var(--muted); font-size: 0.75rem; white-space: nowrap; }
.notif-body { margin: 0.3rem 0 0; overflow-wrap: anywhere; }
.notif-meta { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; align-items: center; }
.notif-app { color: var(--muted); font-size: 0.78rem; }
.device-badge {
  font-size: 0.7rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
}
.notif-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.6rem; }
.notif-actions button { padding: 0.25rem 0.6rem; font-size: 0.78rem; }
.notif-empty { color: var(--muted); padding: 0.6rem 0.15rem; }
.notif-section-title { margin-top: 1.6rem; }
.device-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-top: 1px solid var(--border);
  padding: 0.55rem 0.15rem;
}
.device-row:first-child { border-top: none; }
.device-name { font-weight: 600; }
.device-seen { color: var(--muted); font-size: 0.78rem; margin-left: auto; }
.device-row button { padding: 0.2rem 0.55rem; font-size: 0.75rem; }
/* The enrollment token is a device credential shown once, so it must be fully
   readable and selectable rather than clipped to the panel width. */
.token {
  margin: 0.5rem 0;
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-family: ui-monospace, monospace;
  font-size: 0.75rem;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  user-select: all;
}
.notif-danger { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; margin-top: 1.75rem; }

/* The TOTP setup key, shown only when asked for. It is the permanent factor, so
   it is laid out to be read and copied exactly rather than skimmed. */
.totp-setup {
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.totp-setup .hint { margin: 0 0 0.5rem; }
.totp-setup .field-row { align-items: center; }
.totp-setup code.v {
  font-family: ui-monospace, monospace;
  font-size: 0.75rem;
  overflow-wrap: anywhere;
  user-select: all;
}

/* clipboard */
#clip-status {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
}
#clip-status.error { color: var(--danger); }
.clip-toolbar { flex-wrap: wrap; gap: 0.5rem; }
#clip-send-text { width: 100%; resize: vertical; font-family: inherit; }
#clip-list, #clip-devices { list-style: none; margin: 0.75rem 0 0; padding: 0; }
.clip-card {
  border-top: 1px solid var(--border);
  padding: 0.75rem 0.15rem;
}
.clip-card:first-child { border-top: none; }
.clip-card.newest { background: var(--bg); border-radius: 8px; padding-inline: 0.5rem; }
.clip-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; flex-wrap: wrap; }
.clip-when { color: var(--muted); font-size: 0.75rem; white-space: nowrap; margin-left: auto; }
/* A clip is text as it was copied: line breaks and indentation are part of it,
   and a wall of it must wrap rather than push the page sideways. */
.clip-body {
  margin: 0.4rem 0 0;
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 16rem;
  overflow-y: auto;
}
.clip-body.unreadable { color: var(--muted); font-style: italic; }
.clip-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.6rem; }
.clip-actions button { padding: 0.25rem 0.6rem; font-size: 0.78rem; }
.clip-empty { color: var(--muted); padding: 0.6rem 0.15rem; }

/* contacts */
#contacts-status {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
}
#contacts-status.error { color: var(--danger); }
.contacts-toolbar { gap: 0.5rem; flex-wrap: wrap; }
.contacts-toolbar input[type="search"] { flex: 1; min-width: 8rem; }
/* The three views are one control, so the selected one has to be obvious at a
   glance rather than inferred from what is on screen below it. */
.tab {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
  width: auto;
}
.tab.selected { color: var(--fg); border-color: var(--accent); background: var(--bg); }
#contacts-list, #contacts-sources { list-style: none; margin: 0.75rem 0 0; padding: 0; }
.contact-card {
  border-top: 1px solid var(--border);
  padding: 0.75rem 0.15rem;
}
.contact-card:first-child { border-top: none; }
.contact-card.archived { opacity: 0.75; }
.contact-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; }
.contact-name { font-weight: 650; overflow-wrap: anywhere; }
.contact-org { color: var(--muted); font-size: 0.78rem; text-align: right; }
.contact-addresses { list-style: none; margin: 0.3rem 0 0; padding: 0; font-size: 0.85rem; }
.contact-addresses li { overflow-wrap: anywhere; }
.contact-meta { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; align-items: center; }
.contact-also { color: var(--muted); font-size: 0.78rem; }
.source-badge {
  font-size: 0.7rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
}
.contact-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.6rem; }
.contact-actions button { padding: 0.25rem 0.6rem; font-size: 0.78rem; width: auto; }
.contact-empty, .contact-note { color: var(--muted); padding: 0.6rem 0.15rem; }
/* A merge question is a comparison, so the two candidates sit side by side:
   deciding "same person" by scrolling between two rows is how the wrong answer
   gets given. */
.contact-question { border-top: 1px solid var(--border); padding: 0.85rem 0.15rem; }
.contact-question:first-child { border-top: none; }
.question-asked { margin: 0 0 0.6rem; font-size: 0.85rem; }
.question-sides { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0.6rem; }
.question-side {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
}
.question-side small { color: var(--muted); overflow-wrap: anywhere; }

/* messages */
#msg-status {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
}
#msg-status.error { color: var(--danger); }
.msg-panes { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); gap: 1rem; align-items: start; }
.msg-pane { min-width: 0; }
.msg-toolbar { gap: 0.5rem; }
.msg-toolbar input { flex: 1; }
#msg-threads { list-style: none; margin: 0.75rem 0 0; padding: 0; }
.msg-thread-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.6rem;
  align-items: center;
  padding: 0.6rem 0.5rem;
  border-top: 1px solid var(--border);
  cursor: pointer;
}
.msg-thread-row:first-child { border-top: none; }
.msg-thread-row.open { background: var(--service-bg); border-radius: 10px; }
.msg-kind { font-size: 1.05rem; }
.msg-thread-name { font-weight: 650; overflow-wrap: anywhere; }
.msg-thread-preview {
  color: var(--muted);
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-thread-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 0.25rem; color: var(--muted); font-size: 0.75rem; }
.msg-empty { color: var(--muted); padding: 0.6rem 0.15rem; }
.msg-thread-head { display: flex; align-items: center; gap: 0.6rem; }
.msg-thread-head small { display: block; color: var(--muted); font-size: 0.78rem; }
#msg-thread-list {
  list-style: none;
  margin: 0.75rem 0;
  padding: 0.25rem;
  /* The conversation scrolls inside itself so the reply box stays put. */
  max-height: 58vh;
  overflow-y: auto;
}
.msg-bubble {
  max-width: min(80%, 34rem);
  margin: 0.4rem 0;
  padding: 0.5rem 0.7rem;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
}
.msg-bubble.out { margin-left: auto; background: var(--service-bg); border-color: var(--service-border); }
.msg-body { overflow-wrap: anywhere; white-space: pre-wrap; }
.msg-meta { margin-top: 0.25rem; color: var(--muted); font-size: 0.72rem; }
.msg-sender { margin-bottom: 0.15rem; color: var(--muted); font-size: 0.72rem; font-weight: 650; }
.msg-bubble { cursor: pointer; }
.msg-reactions { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.3rem; }
.msg-reaction { padding: 0 0.4rem; border: 1px solid var(--border); border-radius: 999px; background: var(--panel); font-size: 0.8rem; line-height: 1.5; }
.msg-reaction.mine { border-color: var(--service-border); }
.msg-reaction.pending { opacity: 0.55; }
.msg-reaction.failed { border-color: #e5484d; }
.msg-react-picker { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.4rem; }
.msg-react-picker button { padding: 0.1rem 0.4rem; border: 1px solid var(--border); border-radius: 999px; background: transparent; font-size: 1.1rem; line-height: 1.4; }
.msg-react-picker button.mine { border-color: var(--service-border); background: var(--service-bg); }
.msg-attachment { display: block; margin-top: 0.4rem; font-size: 0.8rem; }
.msg-attachment.pending { color: var(--muted); }
.msg-attachment-image { max-width: 100%; border-radius: 10px; }
#form-msg-reply .row { gap: 0.5rem; }
#form-msg-reply input { flex: 1; }


@media (max-width: 720px) {
  /* A phone-width page that scrolls sideways is always a layout mistake, not a
     feature: the header leaves the screen and the person cannot tell whether
     they broke something. */
  html, body { overflow-x: hidden; }
  .app-shell { display: block; }
  .service-rail {
    position: static;
    display: flex;
    height: auto;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-width: 0;
    padding: calc(0.7rem + env(safe-area-inset-top)) 1rem 0.7rem;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .brand img { width: 34px; height: 34px; border-radius: 8px; }
  .rail-label { display: none; }
  /* The rail scrolls itself rather than pushing the page sideways. With three
     services the tiles fit a phone; the fourth did not, and the overflow moved
     the whole body — so the workspace slid out from under the header the moment
     anyone reached for a later service. */
  .service-rail nav {
    display: flex;
    gap: 0.5rem;
    margin-left: auto;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .service-rail nav::-webkit-scrollbar { display: none; }
  .service-tile { width: auto; padding: 0.4rem 0.6rem; flex: 0 0 auto; }
  .service-tile + .service-tile { margin-top: 0; }
  .service-tile small, .service-glyph { display: none; }
  .device-seen { width: 100%; margin-left: 0; }
  .workspace { padding-inline: 1rem; }
  .workspace-header { padding-top: 1rem; }
  .eyebrow { display: none; }
  .field-row { align-items: flex-start; flex-wrap: wrap; }
  .field-row .k { width: 100%; }
  /* One column on a phone: opening a conversation replaces the list rather than
     squeezing both into the width. */
  .msg-panes { grid-template-columns: minmax(0, 1fr); }
  #view-messages.thread-open #msg-list-pane { display: none; }
  #msg-thread-list { max-height: 52vh; }
}
