:root {
  --bg: #F6F7F9; --surface: #FFFFFF; --surface-2: #EEF1F5;
  --text: #0F172A; --muted: #475569; --border: #D5DBE5;
  --danger: #B91C1C; --ok: #15803D;
  --primary: #1D4ED8; --on-primary: #FFFFFF;
  --secondary: #0F766E; --on-secondary: #FFFFFF;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
:root[data-theme="dark"] {
  --bg: #0B1220; --surface: #111A2E; --surface-2: #17223A;
  --text: #E6EAF2; --muted: #A3AEC2; --border: #26324D;
  --danger: #F87171; --ok: #4ADE80;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .35);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { line-height: 1.5; font-size: 16px; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
a { color: var(--primary); }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

/* Forms */
.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; }
.field-label { font-size: .85rem; font-weight: 600; }
.field-hint { font-size: .8rem; color: var(--muted); }
input, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: .6rem .7rem; width: 100%;
}
input:focus, select:focus { border-color: var(--primary); }
.row { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

/* Buttons */
.btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 8px;
  border: 1px solid transparent; padding: .6rem 1rem;
  background: var(--primary); color: var(--on-primary);
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.small { padding: .35rem .65rem; font-size: .85rem; }
.btn.block { width: 100%; }

/* Auth */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.auth-card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 2rem; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.15rem; margin-bottom: 1.25rem; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: var(--primary); color: var(--on-primary); font-weight: 800;
  box-shadow: 4px 4px 0 -1px var(--secondary);
}
.tabs { display: flex; gap: .25rem; background: var(--surface-2); padding: .25rem; border-radius: 10px; margin-bottom: 1.25rem; }
.tabs button {
  flex: 1; font: inherit; font-weight: 600; border: 0; background: transparent; color: var(--muted);
  padding: .5rem; border-radius: 8px; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.error { color: var(--danger); font-size: .9rem; margin: 0 0 .75rem; min-height: 1.2em; }
.auth-theme { margin-top: 1.25rem; display: flex; justify-content: center; }

/* App shell */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 1.25rem 1rem; display: flex; flex-direction: column; gap: .25rem;
}
.sidebar .brand { margin-bottom: 1rem; }
.nav a {
  display: block; padding: .6rem .8rem; border-radius: 8px; color: var(--text);
  text-decoration: none; font-weight: 500; border-left: 4px solid transparent;
}
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current="page"] { background: var(--surface-2); border-left-color: var(--secondary); font-weight: 700; }
.sidebar-foot { margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--border); font-size: .9rem; }
.main { padding: 2rem; max-width: 900px; width: 100%; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem; margin-bottom: 1.25rem; box-shadow: var(--shadow);
}
.empty { text-align: center; padding: 3rem 1rem; }
.empty-icon {
  width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 1rem; display: grid; place-items: center;
  background: var(--secondary); color: var(--on-secondary); font-size: 1.6rem;
}

/* Segmented control + swatches */
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: .25rem; gap: .25rem; }
.segmented button {
  font: inherit; font-weight: 600; border: 0; background: transparent; color: var(--muted);
  padding: .45rem .9rem; border-radius: 8px; cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); }
.swatches { display: flex; flex-wrap: wrap; gap: .6rem; margin-bottom: 1rem; }
.swatch {
  width: 44px; height: 44px; border-radius: 50%; border: 3px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border); cursor: pointer; display: grid; place-items: center;
  font-weight: 800; font-size: 1.1rem;
}
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--text); }
.swatch:disabled { opacity: .3; cursor: not-allowed; }

/* Repeaters */
.repeat-item { border: 1px solid var(--border); border-radius: 10px; padding: .85rem; margin-bottom: .75rem; background: var(--surface-2); }
.repeat-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.radio-inline { display: inline-flex; align-items: center; gap: .4rem; font-size: .85rem; }
.radio-inline input { width: auto; }

/* 2FA */
.qr { background: #fff; padding: .5rem; border-radius: 10px; display: inline-block; }
.qr img { display: block; }
.secret { font-family: ui-monospace, Menlo, Consolas, monospace; word-break: break-all; background: var(--surface-2); padding: .5rem; border-radius: 8px; }
.codes { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .4rem; font-family: ui-monospace, Menlo, Consolas, monospace; margin: .75rem 0; }
.codes span { background: var(--surface-2); padding: .35rem .5rem; border-radius: 6px; text-align: center; }
.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: .15rem .5rem; border-radius: 999px; background: var(--secondary); color: var(--on-secondary); }

/* Toasts */
#toasts { position: fixed; bottom: 1rem; right: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 50; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--ok); padding: .7rem 1rem; border-radius: 8px; box-shadow: var(--shadow); }
.toast.err { border-left-color: var(--danger); }

@media (max-width: 780px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; border-right: 0; border-bottom: 1px solid var(--border); padding: .75rem 1rem; }
  .sidebar .brand { margin: 0 .75rem 0 0; }
  .nav { display: flex; gap: .25rem; }
  .nav a { border-left: 0; border-bottom: 3px solid transparent; padding: .4rem .6rem; }
  .nav a[aria-current="page"] { border-bottom-color: var(--secondary); }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0; border: 0; }
  .main { padding: 1.25rem; }
}
.mt { margin-top: 1.25rem; }

/* Inbox */
.address-box { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .5rem 0 1rem; }
.address-box code { background: var(--surface-2); padding: .45rem .7rem; border-radius: 8px; font-size: 1rem; word-break: break-all; }
.msg-list { list-style: none; margin: 0; padding: 0; }
.msg-list li { border-top: 1px solid var(--border); }
.msg-list li:first-child { border-top: 0; }
.msg-item { display: block; width: 100%; text-align: left; font: inherit; color: inherit; background: none; border: 0; padding: .75rem .25rem; cursor: pointer; }
.msg-item:hover { background: var(--surface-2); }
.msg-item .from { font-weight: 600; }
.msg-item.unread .from, .msg-item.unread .subject { font-weight: 800; }
.msg-item .preview { color: var(--muted); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-meta { color: var(--muted); font-size: .85rem; }
.msg-body { white-space: pre-wrap; word-break: break-word; font-family: inherit; background: var(--surface-2); padding: 1rem; border-radius: 8px; max-height: 60vh; overflow: auto; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin: .75rem 0; }
.steps { padding-left: 1.2rem; margin: 0; }
.steps li { margin-bottom: .35rem; }
