/* Memox — M3 blue palette, dark by default */

/* ── Self-hosted fonts ── */

@font-face {
  font-family: 'Hanken Grotesk';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('/static/fonts/hanken-grotesk-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191,
    U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Literata';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/static/fonts/literata-latin-400.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191,
    U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Literata';
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url('/static/fonts/literata-latin-400-italic.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191,
    U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ── Design tokens — dark (default) ── */

:root {
  --bg:              #0f1117;
  --surface:         #1c1e27;
  --border:          #2e3140;
  --text:            #e4e2de;
  --text-secondary:  #b8bdd4;
  --muted:           #8892a4;
  --accent:          #7eb8f7;
  --accent-dim:      rgba(126, 184, 247, 0.15);
  --on-accent:       #051d3a;
  --pill-bg:         #252836;
  --danger:          #ff9193;
  --mark-bg:         #3a3800;
  --shadow-card:     0 2px 12px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.25);
  --shadow-hover:    0 6px 24px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.3);
  --radius:          12px;
  --radius-sm:       6px;
  --mono:            'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
  --sans:            'Hanken Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --serif:           'Literata', Georgia, 'Times New Roman', serif;
  --max-w:           680px;
  --sidebar-w:       220px;
  /* alerts */
  --alert-err-bg:    #2d0f13; --alert-err-border: #6e1c20; --alert-err-text: #f9706f;
  --alert-ok-bg:     #0d2a14; --alert-ok-border:  #1f6535; --alert-ok-text:  #3fb950;
  --alert-info-bg:   #112038; --alert-info-border:#2d5f9e; --alert-info-text:#79b8ff;
}

/* ── Light mode override ── */

@media (prefers-color-scheme: light) {
  :root {
    --bg:              #f5f6fa;
    --surface:         #ffffff;
    --border:          #d8dce8;
    --text:            #1a1c2e;
    --text-secondary:  #4a5068;
    --muted:           #717999;
    --accent:          #2563eb;
    --accent-dim:      rgba(37, 99, 235, 0.1);
    --on-accent:       #ffffff;
    --pill-bg:         #e8eaf2;
    --danger:          #ba1a1a;
    --mark-bg:         rgba(253, 237, 36, 0.35);
    --shadow-card:     0 4px 20px rgba(37, 99, 235, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
    --shadow-hover:    0 8px 28px rgba(37, 99, 235, 0.12), 0 2px 6px rgba(0, 0, 0, 0.06);
    --alert-err-bg:    #ffeef0; --alert-err-border: #ffc1c6; --alert-err-text: #86181d;
    --alert-ok-bg:     #dcffe4; --alert-ok-border:  #acf2bd; --alert-ok-text:  #186932;
    --alert-info-bg:   #ddeeff; --alert-info-border:#79b8ff; --alert-info-text:#032f62;
  }
}

[data-theme="light"] {
  --bg:              #f5f6fa;
  --surface:         #ffffff;
  --border:          #d8dce8;
  --text:            #1a1c2e;
  --text-secondary:  #4a5068;
  --muted:           #717999;
  --accent:          #2563eb;
  --accent-dim:      rgba(37, 99, 235, 0.1);
  --on-accent:       #ffffff;
  --pill-bg:         #e8eaf2;
  --danger:          #ba1a1a;
  --mark-bg:         rgba(253, 237, 36, 0.35);
  --shadow-card:     0 4px 20px rgba(37, 99, 235, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-hover:    0 8px 28px rgba(37, 99, 235, 0.12), 0 2px 6px rgba(0, 0, 0, 0.06);
  --alert-err-bg:    #ffeef0; --alert-err-border: #ffc1c6; --alert-err-text: #86181d;
  --alert-ok-bg:     #dcffe4; --alert-ok-border:  #acf2bd; --alert-ok-text:  #186932;
  --alert-info-bg:   #ddeeff; --alert-info-border:#79b8ff; --alert-info-text:#032f62;
}

[data-theme="dark"] {
  --bg:              #0f1117;
  --surface:         #1c1e27;
  --border:          #2e3140;
  --text:            #e4e2de;
  --text-secondary:  #b8bdd4;
  --muted:           #8892a4;
  --accent:          #7eb8f7;
  --accent-dim:      rgba(126, 184, 247, 0.15);
  --on-accent:       #051d3a;
  --pill-bg:         #252836;
  --danger:          #ff9193;
  --mark-bg:         #3a3800;
  --shadow-card:     0 2px 12px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.25);
  --shadow-hover:    0 6px 24px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.3);
  --alert-err-bg:    #2d0f13; --alert-err-border: #6e1c20; --alert-err-text: #f9706f;
  --alert-ok-bg:     #0d2a14; --alert-ok-border:  #1f6535; --alert-ok-text:  #3fb950;
  --alert-info-bg:   #112038; --alert-info-border:#2d5f9e; --alert-info-text:#79b8ff;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ── */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 3rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar__brand {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
  color: var(--text);
}

.topbar__actions { display: flex; gap: 0.75rem; align-items: center; }

.sidebar {
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  background: var(--surface);
  overflow-y: auto;
}

.sidebar__section { margin-bottom: 1.5rem; }
.sidebar__label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.sidebar__link {
  display: block;
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar__link:hover { background: var(--border); text-decoration: none; }
.sidebar__link.active { background: var(--accent-dim); color: var(--accent); }

.sidebar__link--tag {
  display: flex;
  align-items: center;
  justify-content: space-between;
  overflow: visible;
}

.sidebar__tag-count {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--pill-bg);
  border-radius: 9999px;
  padding: 0.1rem 0.45rem;
  flex-shrink: 0;
  margin-left: 0.35rem;
}
.sidebar__link.active .sidebar__tag-count {
  background: var(--accent-dim);
  color: var(--accent);
}

.sidebar__link--more {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.25rem;
}
.sidebar__link--more:hover { color: var(--accent); }

.main {
  padding: 2rem 2.5rem;
  max-width: calc(var(--max-w) + 5rem);
  overflow-y: auto;
}

/* ── Auth pages (no sidebar) ── */

.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  box-shadow: var(--shadow-card);
}

.auth-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}
.auth-card .subtitle {
  color: var(--muted);
  font-size: 0.875rem;
  margin-bottom: 1.75rem;
}

/* ── E2E badge ── */
.e2e-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: 99px;
  padding: 0.3rem 0.85rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 1.5rem;
}

/* ── Landing page ── */
.landing-card { max-width: 480px; }

.landing-title {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: -0.05em;
  margin-bottom: 0.3rem;
  line-height: 1;
}

.landing-tagline {
  font-size: 1.05rem;
  color: var(--muted);
  margin-bottom: 1.25rem;
  line-height: 1.5;
}

.landing-pitch {
  font-size: 0.85rem;
  line-height: 1.7;
  color: var(--muted);
  margin-bottom: 1.75rem;
  border-left: 3px solid var(--border);
  padding-left: 0.85rem;
}

.landing-footer {
  text-align: center;
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 1.5rem;
  opacity: 0.7;
}

/* ── App icons grid (register + 2FA pages) ── */
.app-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  justify-content: center;
  margin: 0.75rem 0 0.25rem;
}

.app-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
  color: var(--muted);
  transition: transform 0.15s, color 0.15s;
}
.app-link:hover { transform: translateY(-3px); color: var(--text); text-decoration: none; }

.app-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  flex-shrink: 0;
}

.app-name {
  font-size: 0.65rem;
  font-weight: 500;
  text-align: center;
  line-height: 1.2;
}

/* Compact row on 2FA confirm page */
.app-grid--compact { gap: 0.6rem; }
.app-grid--compact .app-icon { width: 36px; height: 36px; border-radius: 9px; }
.app-grid--compact .app-name { font-size: 0.6rem; }

/* ── Register step headers ── */
.step-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.85rem;
}

.step-number {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.step-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.step-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

/* ── QR code wrapper ── */
.qr-large {
  display: flex;
  justify-content: center;
  margin: 1.25rem 0;
}
.qr-large img {
  width: 200px;
  height: 200px;
  border-radius: var(--radius);
  border: 4px solid var(--bg);
  box-shadow: 0 0 0 1px var(--border);
}

/* ── OTP input ── */
.otp-input {
  text-align: center;
  font-size: 1.75rem;
  font-family: var(--mono);
  font-weight: 600;
  letter-spacing: 0.35em;
  padding: 0.6rem 1rem;
}

/* ── Settings danger zone ── */
.settings-danger {
  border-color: var(--danger);
}
.settings-danger h2 {
  color: var(--danger);
}

/* ── Forms ── */

.form-group { margin-bottom: 1.25rem; }

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
textarea,
select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--sans);
  font-size: 0.9rem;
  transition: border-color 0.15s;
  outline: none;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

textarea {
  font-family: var(--mono);
  font-size: 0.875rem;
  resize: vertical;
  line-height: 1.7;
}

/* ── Buttons ── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, opacity 0.15s;
  text-decoration: none;
  background: none;
  color: var(--text);
}
.btn:hover { text-decoration: none; }

.btn-primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn-primary:hover { opacity: 0.88; }

.btn-secondary { background: var(--surface); border-color: var(--border); }
.btn-secondary:hover { background: var(--border); }

.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { opacity: 0.88; }

.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }
.btn-full { width: 100%; justify-content: center; }

/* ── Theme toggle ── */

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 1.75rem;
  padding: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: none;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.theme-toggle:hover { color: var(--text); border-color: var(--muted); background: var(--surface); }
.theme-toggle svg { display: block; }

[data-theme="dark"]  .theme-toggle__moon { display: none; }
[data-theme="light"] .theme-toggle__sun  { display: none; }

/* ── Alerts ── */

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 1.25rem;
}
.alert-error   { background: var(--alert-err-bg);  border: 1px solid var(--alert-err-border);  color: var(--alert-err-text); }
.alert-success { background: var(--alert-ok-bg);   border: 1px solid var(--alert-ok-border);   color: var(--alert-ok-text); }
.alert-info    { background: var(--alert-info-bg); border: 1px solid var(--alert-info-border); color: var(--alert-info-text); }

/* ── Note cards ── */

.notes-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.timeline-label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  padding-top: 1.5rem;
}
.timeline-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
  opacity: 0.6;
}
.notes-grid > .timeline-label:first-child {
  padding-top: 0;
}

.note-card {
  display: block;
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.15s;
  color: var(--text);
}
.note-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
  border-color: var(--accent);
  text-decoration: none;
}

.note-card__title {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 0.3rem;
  color: var(--text);
}

.note-card__meta {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.4rem;
}

.tag {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  background: var(--pill-bg);
  border: none;
  border-radius: 9999px;
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--muted);
}
.tag:hover { color: var(--accent); background: var(--accent-dim); text-decoration: none; }
.tag.active { background: var(--accent-dim); color: var(--accent); }

/* ── Concordance view ── */

.concordance {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.concordance-card {
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}

.concordance-card__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.6rem;
}

.concordance-card__title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}
.concordance-card__title:hover { color: var(--accent); text-decoration: none; }

.concordance-card__date {
  font-size: 0.72rem;
  color: var(--muted);
  flex-shrink: 0;
}

.concordance-card__snippet {
  font-family: var(--serif);
  font-size: 0.9rem;
  line-height: 1.65;
  color: var(--text-secondary);
  border-left: 2px solid var(--border);
  padding-left: 0.75rem;
  margin-top: 0.35rem;
}

mark.tag-mention {
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: 3px;
  padding: 0.05em 0.25em;
  font-weight: 600;
}

/* ── Tag browser (/notes/tags) ── */

.tag-browser {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  padding-top: 0.5rem;
}

.tag-browser__item {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9999px;
  box-shadow: var(--shadow-card);
  transition: border-color 0.15s, box-shadow 0.15s;
  text-decoration: none;
}
.tag-browser__item:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-hover);
  text-decoration: none;
}

.tag-browser__name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
}

.tag-browser__count {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--pill-bg);
  border-radius: 9999px;
  padding: 0.1rem 0.45rem;
}

/* ── Note cards — preview line ── */

.note-card__preview {
  font-size: 0.8rem;
  margin-top: 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* ── Note detail ── */

.note-toolbar {
  margin-bottom: 1.75rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border);
}

.note-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.6rem;
}

.note-body {
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.85;
  max-width: var(--max-w);
}
.note-body h1, .note-body h2, .note-body h3 { margin: 1.5em 0 0.5em; font-weight: 600; }
.note-body p { margin-bottom: 1em; }
.note-body ul, .note-body ol { margin: 0 0 1em 1.5em; }
.note-body li { margin-bottom: 0.25em; }
.note-body blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1em;
  color: var(--muted);
  margin: 1em 0;
}
.note-body pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1em;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.85em;
  margin-bottom: 1em;
}
.note-body code {
  font-family: var(--mono);
  font-size: 0.875em;
  background: var(--surface);
  padding: 0.1em 0.3em;
  border-radius: 3px;
}
.note-body pre code { background: none; padding: 0; }
.note-body table { width: 100%; border-collapse: collapse; margin-bottom: 1em; }
.note-body th, .note-body td {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  text-align: left;
}
.note-body th { background: var(--surface); font-weight: 600; }

/* ── Wikilinks ── */

.wikilink { color: var(--accent); }
.wikilink.broken { color: var(--muted); text-decoration: dashed underline; cursor: help; }

/* ── Backlinks / outbound panel ── */

.links-panel {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.links-panel h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

/* ── Editor ── */

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.editor-tabs {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  flex-shrink: 0;
}

.editor-tab {
  padding: 0.28rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 500;
  background: var(--bg);
  color: var(--muted);
  border: none;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.editor-tab + .editor-tab { border-left: 1px solid var(--border); }

.editor-tab.is-active {
  background: var(--accent);
  color: #fff;
}

.editor-tab:hover:not(.is-active) {
  background: var(--surface);
  color: var(--text);
}

.editor-pane-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  flex: 1;
}

.editor-toolbar__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.editor-save-status {
  font-size: 0.78rem;
  color: var(--muted);
  transition: opacity 0.5s;
  min-width: 4rem;
  text-align: right;
}

.editor-save-status.is-error { color: var(--danger); }

.editor-layout {
  height: calc(100vh - 9rem);
  display: flex;
  flex-direction: column;
}

#editor-pane,
#preview-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.editor-textarea {
  flex: 1;
  resize: none;
  font-family: var(--mono);
  font-size: 0.9rem;
  line-height: 1.75;
}

.preview-pane {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ── Topbar search button ── */

.topbar__search {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  border-color: var(--border);
  min-width: 100px;
  justify-content: space-between;
}
.topbar__search:hover { color: var(--text); border-color: var(--muted); }
.topbar__search-label { font-size: 0.8rem; }
.topbar__search-kbd {
  font-size: 0.68rem;
  padding: 0.1rem 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--sans);
  color: var(--muted);
  line-height: 1.4;
}
.topbar__username { display: none; }
@media (min-width: 640px) { .topbar__username { display: inline; } }

/* ── Global search modal ── */

#search-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: flex-start;
  justify-content: center;
  padding-top: min(10vh, 80px);
}
#search-modal.is-open { display: flex; }

.sm-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: sm-fade-in 0.12s ease;
}

.sm-dialog {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 580px;
  margin: 0 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  animation: sm-slide-in 0.14s ease;
}

@keyframes sm-fade-in  { from { opacity: 0 } to { opacity: 1 } }
@keyframes sm-slide-in { from { opacity: 0; transform: translateY(-8px) } to { opacity: 1; transform: none } }

.sm-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--border);
}
.sm-icon { font-size: 1.1rem; color: var(--muted); flex-shrink: 0; }
.sm-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 0.95rem 0;
  font-size: 1rem;
  color: var(--text);
  outline: none;
  font-family: var(--sans);
}
.sm-input::placeholder { color: var(--muted); }
.sm-esc {
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  font-family: var(--sans);
  flex-shrink: 0;
}

.sm-body {
  max-height: 58vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sm-hint {
  padding: 1.5rem 1rem;
  color: var(--muted);
  font-size: 0.875rem;
  text-align: center;
}
.sm-error {
  padding: 1.5rem 1rem;
  color: var(--danger);
  font-size: 0.875rem;
  text-align: center;
}

.sm-list { list-style: none; margin: 0; padding: 0; }

.sm-item {
  display: block;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  transition: background 0.08s;
}
.sm-list li:last-child .sm-item { border-bottom: none; }
.sm-item:hover, .sm-item.is-active {
  background: var(--surface);
  text-decoration: none;
}

.sm-item-title {
  font-weight: 500;
  font-size: 0.9rem;
  margin-bottom: 0.2rem;
}
.sm-item-snippet {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.sm-item-meta {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 0.25rem;
}
.sm-item mark,
.sm-item-title mark,
.sm-item-snippet mark {
  background: var(--mark-bg);
  color: var(--text);
  border-radius: 2px;
  padding: 0 1px;
}

/* ── QR code ── */

/* ── Registration 2FA — authenticator app suggestions ── */
.auth-apps {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
}
.auth-apps__label {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.auth-apps__list {
  list-style: none;
  font-size: 0.82rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.qr-wrapper { text-align: center; margin: 1.5rem 0; }
.qr-wrapper img { max-width: 200px; border-radius: var(--radius); }

.recovery-codes {
  font-family: var(--mono);
  font-size: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  columns: 2;
  margin: 1rem 0;
}
.recovery-codes li { margin-bottom: 0.35rem; list-style: none; }

/* ── Settings ── */

.settings-section {
  margin-bottom: 2.5rem;
}
.settings-section h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.85rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}
.settings-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 0;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
}
.settings-label {
  width: 160px;
  flex-shrink: 0;
  color: var(--muted);
  font-size: 0.82rem;
}
.security-notice {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  font-size: 0.85rem;
  line-height: 1.6;
}
.security-notice ul {
  margin: 0.5rem 0 0 1.25rem;
}
.security-notice li { margin-bottom: 0.35rem; }

/* ── Admin table ── */

.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table th, .data-table td {
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.data-table th {
  background: var(--surface);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.data-table tr:hover td { background: var(--surface); }

.badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 99px;
  font-size: 0.7rem;
  font-weight: 600;
}
.badge-green { background: var(--alert-ok-bg); color: var(--alert-ok-text); }
.badge-red   { background: var(--alert-err-bg); color: var(--alert-err-text); }
.badge-blue  { background: var(--accent-dim); color: var(--accent); }

/* ── Page header ── */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}
.page-header h1 { font-size: 1.35rem; font-weight: 700; }

/* ── Utility ── */

.text-muted { color: var(--muted); }
.text-sm    { font-size: 0.85rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.flex { display: flex; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }

/* ── Divider ── */

hr.divider { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

/* ── Responsive ── */

@media (max-width: 640px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 1.25rem 1rem; }
  .topbar__search-kbd { display: none; }
  .topbar__search { min-width: auto; }
  #search-modal { padding-top: 0; }
  .sm-dialog { margin: 0; border-radius: 0 0 calc(var(--radius) * 2) calc(var(--radius) * 2); }
}

/* ── Delete confirmation modal ── */

#del-modal { position:fixed; inset:0; z-index:1000; display:flex; align-items:center; justify-content:center; }
#del-modal[hidden] { display:none; }
.del-backdrop { position:fixed; inset:0; background:rgba(0,0,0,.45); backdrop-filter:blur(3px); -webkit-backdrop-filter:blur(3px); animation:sm-fade-in .12s ease; }
.del-dialog { position:relative; z-index:1; width:100%; max-width:380px; margin:0 1rem; background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); box-shadow:0 24px 64px rgba(0,0,0,.35); padding:1.5rem; animation:sm-slide-in .14s ease; }
.del-heading { font-weight:600; margin:0 0 .4rem; }
.del-body { margin:0 0 1.5rem; }
.del-actions { display:flex; gap:.5rem; justify-content:flex-end; }
