/* ============================================================
   Shelf — read-it-later, self-hosted
   Design: warm paper tones, serif reading typography, one accent.
   ============================================================ */

:root {
  --bg: #f6f4ee;
  --surface: #fffefb;
  --surface-2: #efede4;
  --ink: #232920;
  --muted: #6e6a5c;
  --line: #e3dfd3;
  --line-strong: #d3cdba;

  --accent: #2f6b4f;
  --accent-strong: #245740;
  --accent-soft: #e7efe9;
  --accent-ink: #24493a;
  --accent-line: #c3d5c9;

  --gold: #b98a24;
  --danger: #a84a2e;
  --danger-soft: #f6e8e0;

  --radius: 12px;
  --radius-s: 8px;
  --shadow: 0 1px 2px rgba(35, 41, 32, .05), 0 10px 28px rgba(35, 41, 32, .07);
  --shadow-lift: 0 2px 4px rgba(35, 41, 32, .06), 0 14px 34px rgba(35, 41, 32, .12);

  --serif: "Iowan Old Style", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181b;
    --surface: #1d2023;
    --surface-2: #26292d;
    --ink: #e7e4db;
    --muted: #99958a;
    --line: #2c2f34;
    --line-strong: #3a3e44;

    --accent: #5da986;
    --accent-strong: #79c3a0;
    --accent-soft: #21312a;
    --accent-ink: #a9d4bc;
    --accent-line: #33473d;

    --danger: #d97a5b;
    --danger-soft: #37221a;

    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 10px 28px rgba(0, 0, 0, .4);
    --shadow-lift: 0 2px 4px rgba(0, 0, 0, .4), 0 14px 34px rgba(0, 0, 0, .55);
  }
}

/* ---------- base ---------- */

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.icon { flex: none; vertical-align: -2px; }

.container {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 24px 72px;
  flex: 1;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: .8rem;
  padding: 20px 16px 28px;
  border-top: 1px solid var(--line);
}

/* ---------- topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 24px;
  height: 58px;
  display: flex;
  align-items: center;
  gap: 26px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: .01em;
  color: var(--ink);
  text-decoration: none;
}
.brand .icon { color: var(--accent); }

.add-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fdfcf8;
  transition: background .15s, transform .12s;
}
.add-btn:hover { background: var(--accent-strong); transform: scale(1.06); }
.add-btn:active { transform: scale(.97); }

.nav {
  display: flex;
  gap: 4px;
  align-items: center;
  font-size: .93rem;
}

.nav a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  text-decoration: none;
  padding: 7px 12px;
  border-radius: 999px;
  transition: color .15s, background .15s;
}
.nav a:hover { color: var(--ink); background: var(--surface-2); }
.nav a.active { color: var(--accent-ink); background: var(--accent-soft); }
.nav .count {
  font-size: .74rem;
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 999px;
  padding: 1px 7px;
}
.nav a.active .count { background: var(--accent-line); color: var(--accent-ink); }

.search {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  width: 280px;
  max-width: 38vw;
  color: var(--muted);
  transition: border-color .15s, box-shadow .15s;
}
.search:focus-within {
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search input {
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: .92rem;
  width: 100%;
  outline: none;
}
.search input::placeholder { color: var(--muted); }

/* ---------- flashes ---------- */

.flashes {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(560px, calc(100vw - 32px));
}

.flash {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lift);
  border-radius: 10px;
  padding: 11px 16px;
  font-size: .93rem;
  animation: flash-in .25s ease;
  transition: opacity .3s, transform .3s;
}
.flash .icon { color: var(--accent); }
.flash-error { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.flash-error .icon { color: var(--danger); }
.flash.hide { opacity: 0; transform: translateY(-8px); }

@keyframes flash-in {
  from { opacity: 0; transform: translateY(-10px); }
}

/* ---------- add card ---------- */

.add-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 30px;
}

.add-form { display: grid; gap: 10px; }

.add-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 4px 6px 4px 14px;
  color: var(--muted);
  transition: border-color .15s, box-shadow .15s;
}
.add-row:focus-within {
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.add-row input {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: .95rem;
  padding: 8px 0;
  outline: none;
  min-width: 0;
}
.add-row input::placeholder { color: var(--muted); }
.add-row-tags input { font-size: .88rem; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-size: .9rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
  padding: 8px 14px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, border-color .15s, transform .06s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fdfcf8;
  font-weight: 600;
}
.btn-accent:hover { background: var(--accent-strong); border-color: var(--accent-strong); }

.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }

.btn-ghost { border-color: transparent; color: var(--muted); background: transparent; }
.btn-ghost:hover { color: var(--ink); background: var(--surface-2); }

.btn-starred { color: var(--gold); border-color: color-mix(in srgb, var(--gold) 40%, var(--line)); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 7px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background .13s, color .13s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.is-starred { color: var(--gold); }
.icon-btn-danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- list header & chips ---------- */

.list-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 18px;
  margin-bottom: 18px;
}

.list-title {
  font-family: var(--serif);
  font-size: 1.5rem;
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.list-count {
  font-family: var(--sans);
  font-size: .82rem;
  font-weight: 500;
  color: var(--muted);
  background: var(--surface-2);
  padding: 2px 10px;
  border-radius: 999px;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .82rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  text-decoration: none;
  transition: border-color .15s, color .15s;
}
.chip:hover { color: var(--ink); border-color: var(--line-strong); }
.chip-active { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-ink); }
.chip-toggle-on { background: color-mix(in srgb, var(--gold) 14%, var(--surface)); border-color: color-mix(in srgb, var(--gold) 40%, var(--line)); color: var(--gold); }
.chip-x { color: inherit; text-decoration: none; font-size: 1rem; line-height: 1; padding: 0 2px; }
.chip-x:hover { color: var(--danger); }

/* ---------- cards ---------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 16px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 18px 14px;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lift);
  border-color: var(--line-strong);
}

.card-top { display: flex; align-items: center; gap: 10px; }

.favicon {
  width: 32px;
  height: 32px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  font-size: .88rem;
  font-weight: 700;
  background: hsl(var(--h) 30% 86%);
  color: hsl(var(--h) 45% 28%);
}
.card-src { display: flex; flex-direction: column; min-width: 0; }
.card-domain {
  font-size: .85rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-meta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: .78rem;
  color: var(--muted);
}

.card-title {
  font-family: var(--serif);
  font-size: 1.22rem;
  line-height: 1.32;
  font-weight: 700;
  margin: 0;
}
.card-title a {
  color: var(--ink);
  text-decoration: none;
}
.card-title a:hover { color: var(--accent-strong); text-decoration: underline; text-underline-offset: 3px; }

.card-excerpt {
  margin: 0;
  color: var(--muted);
  font-size: .9rem;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-tags { display: flex; flex-wrap: wrap; gap: 6px; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: .78rem;
  padding: 3px 11px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  border: 1px solid transparent;
  text-decoration: none;
  transition: background .13s, color .13s;
}
.tag:hover { background: var(--accent); color: #fdfcf8; }

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.card-date { font-size: .78rem; color: var(--muted); }
.card-actions { display: flex; gap: 2px; }

/* ---------- pager ---------- */

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 26px;
}
.pager-info { color: var(--muted); font-size: .88rem; }

/* ---------- empty states ---------- */

.empty {
  text-align: center;
  padding: 72px 20px;
  color: var(--muted);
}
.empty-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  background: var(--accent-soft);
  color: var(--accent);
}
.empty h2 {
  font-family: var(--serif);
  color: var(--ink);
  margin: 0 0 8px;
  font-size: 1.4rem;
}
.empty p { margin: 0 auto; max-width: 46ch; }

/* ---------- tags page ---------- */

.page-narrow { max-width: 760px; }
.page-title {
  font-family: var(--serif);
  font-size: 1.6rem;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 22px;
}
.tag-cloud { display: flex; flex-wrap: wrap; gap: 10px; }
.tag-big { font-size: .92rem; padding: 7px 16px; }
.tag-count {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border-radius: 999px;
  font-size: .74rem;
  padding: 1px 7px;
}

/* ---------- article view ---------- */

.article-wrap {
  max-width: 780px;
  margin: 0 auto;
}

.article-topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}
.article-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.archived-note {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: var(--radius-s);
  font-size: .88rem;
  padding: 10px 14px;
  margin-bottom: 20px;
}
.archived-note a { color: var(--accent-ink); }

.article {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(22px, 5vw, 52px);
}

.article-header h1 {
  font-family: var(--serif);
  font-size: clamp(1.6rem, 3.4vw, 2.15rem);
  line-height: 1.22;
  margin: 0 0 14px;
}

.article-meta {
  color: var(--muted);
  font-size: .88rem;
  margin: 0 0 20px;
}
.article-src { color: var(--muted); text-decoration: none; border-bottom: 1px dotted var(--line-strong); }
.article-src:hover { color: var(--accent); }

.tags-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  margin-bottom: 30px;
}
.tags-current { display: flex; flex-wrap: wrap; gap: 6px; }
.tags-none { color: var(--muted); font-size: .86rem; }
.tags-form { display: flex; gap: 8px; }
.tags-form input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: .9rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 8px 12px;
  transition: border-color .15s, box-shadow .15s;
}
.tags-form input:focus {
  outline: none;
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.article-body {
  font-family: var(--serif);
  font-size: 1.075rem;
  line-height: 1.78;
  color: var(--ink);
  overflow-wrap: break-word;
}

.article-body p { margin: 0 0 1.15em; }
.article-body h1, .article-body h2, .article-body h3,
.article-body h4, .article-body h5, .article-body h6 {
  font-family: var(--serif);
  line-height: 1.3;
  margin: 1.8em 0 .6em;
}
.article-body h1 { font-size: 1.6em; }
.article-body h2 { font-size: 1.45em; }
.article-body h3 { font-size: 1.25em; }
.article-body h4, .article-body h5, .article-body h6 { font-size: 1.1em; }
.article-body a { color: var(--accent-strong); }
.article-body img {
  max-width: 100%;
  height: auto;
  border-radius: 10px;
  margin: 1.4em 0;
}
.article-body figure { margin: 1.6em 0; }
.article-body figcaption {
  font-family: var(--sans);
  font-size: .83rem;
  color: var(--muted);
  margin-top: 6px;
  text-align: center;
}
.article-body blockquote {
  margin: 1.4em 0;
  padding: 2px 0 2px 1.2em;
  border-left: 3px solid var(--accent-line);
  color: var(--muted);
  font-style: italic;
}

/* Callout boxes — rebuilt from div.NOTE / div.TIP / bootstrap alerts.
   Each type sets --co-accent and --co-bg; shared layout below. */
.article-body blockquote[data-callout] {
  --co-accent: var(--accent);
  --co-bg: var(--accent-soft);
  position: relative;
  margin: 1.5em 0;
  padding: 13px 18px 13px 46px;
  background: var(--co-bg);
  border: 1px solid color-mix(in srgb, var(--co-accent) 25%, var(--line));
  border-left: 3px solid var(--co-accent);
  border-radius: 10px;
  color: var(--ink);
  font-style: normal;
}
.article-body blockquote[data-callout]::before {
  position: absolute;
  left: 17px;
  top: 15px;
  font-size: .95rem;
  line-height: 1.5;
  color: var(--co-accent);
}
.article-body blockquote[data-callout="note"]::before     { content: "\2139\FE0F"; }  /* ⓘ */
.article-body blockquote[data-callout="tip"]::before      { content: "\1F4A1"; }      /* 💡 */
.article-body blockquote[data-callout="warning"]::before  { content: "\26A0\FE0F"; }  /* ⚠️ */
.article-body blockquote[data-callout="caution"]::before  { content: "\26A0\FE0F"; }  /* ⚠️ */
.article-body blockquote[data-callout="important"]::before { content: "\2757"; }      /* ❗ */

.article-body blockquote[data-callout="note"] {
  --co-accent: #4468c4; --co-bg: color-mix(in srgb, #4468c4 7%, var(--surface));
}
.article-body blockquote[data-callout="tip"] {
  --co-accent: #2f7d4f; --co-bg: color-mix(in srgb, #2f7d4f 7%, var(--surface));
}
.article-body blockquote[data-callout="warning"] {
  --co-accent: #b07d1a; --co-bg: color-mix(in srgb, #b07d1a 8%, var(--surface));
}
.article-body blockquote[data-callout="caution"] {
  --co-accent: #c0552f; --co-bg: color-mix(in srgb, #c0552f 7%, var(--surface));
}
.article-body blockquote[data-callout="important"] {
  --co-accent: #7a4fb0; --co-bg: color-mix(in srgb, #7a4fb0 7%, var(--surface));
}

.article-body blockquote[data-callout] > p:first-child {
  font-family: var(--sans);
  font-weight: 600;
  font-size: .9rem;
  color: var(--co-accent);
  margin: 0 0 .35em;
}
.article-body blockquote[data-callout] > p:last-child { margin-bottom: 0; }
.article-body pre {
  font-family: var(--mono);
  font-size: .88em;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  overflow-x: auto;
  line-height: 1.5;
}
.article-body code {
  font-family: var(--mono);
  font-size: .88em;
  background: var(--surface-2);
  border-radius: 5px;
  padding: .1em .35em;
}
.article-body pre code { background: none; padding: 0; }
.article-body ul, .article-body ol { padding-left: 1.5em; margin: 0 0 1.15em; }
.article-body li { margin-bottom: .4em; }
.article-body hr { border: 0; border-top: 1px solid var(--line); margin: 2em auto; width: 60%; }
.article-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.4em 0;
  font-family: var(--sans);
  font-size: .9em;
}
.article-body th, .article-body td {
  border: 1px solid var(--line);
  padding: 7px 11px;
  text-align: left;
}
.article-body th { background: var(--surface-2); }
.article-body mark { background: color-mix(in srgb, var(--gold) 22%, transparent); padding: 0 .15em; }

.empty-extract {
  text-align: center;
  color: var(--muted);
  background: var(--bg);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-s);
  padding: 28px 20px;
}
.empty-extract p { margin: .3em 0; }

/* ---------- auth pages (login / mfa / setup) ---------- */

.auth-card {
  max-width: 400px;
  margin: 7vh auto 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 34px 32px 30px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
}
.auth-brand .icon { color: var(--accent); }
.auth-brand h1 {
  font-family: var(--serif);
  font-size: 1.7rem;
  margin: 0;
}

.auth-sub {
  color: var(--muted);
  font-size: .93rem;
  margin: 8px 0 22px;
  line-height: 1.5;
}

.auth-form { display: flex; flex-direction: column; gap: 6px; }
.auth-form label {
  font-size: .85rem;
  font-weight: 600;
  color: var(--ink);
  margin-top: 10px;
}
.label-hint { font-weight: 400; color: var(--muted); font-size: .8rem; }
.auth-form input:not([type=checkbox]) {
  font: inherit;
  font-size: .95rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 10px 12px;
  transition: border-color .15s, box-shadow .15s;
}
.auth-form input:focus {
  outline: none;
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.auth-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .86rem;
  color: var(--muted);
  margin: 14px 0 16px;
  cursor: pointer;
}
.auth-form .btn-block { justify-content: center; width: 100%; padding: 11px; }
.code-input {
  text-align: center;
  font-size: 1.35rem !important;
  letter-spacing: .45em;
  font-family: var(--mono);
}
.auth-resend { text-align: center; margin-top: 14px; }

/* ---------- settings ---------- */

.settings-wrap { max-width: 860px; }

.settings-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
  margin-bottom: 18px;
}
.settings-card h2 {
  font-family: var(--serif);
  font-size: 1.25rem;
  margin: 0 0 6px;
}
.settings-card h3 { font-size: 1rem; margin: 20px 0 8px; }
.settings-hint { color: var(--muted); font-size: .88rem; line-height: 1.55; }
.warn-text { color: var(--danger); font-weight: 600; }
.ok-text { color: var(--accent-strong); font-weight: 600; }

.settings-form { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.settings-form label {
  font-size: .86rem;
  font-weight: 600;
  margin-top: 8px;
}
.settings-form input:not([type=checkbox]):not([type=radio]),
.settings-form textarea {
  font: inherit;
  font-size: .92rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 9px 12px;
}
.settings-form textarea { font-family: var(--mono); font-size: .84rem; resize: vertical; }
.settings-form input:focus, .settings-form textarea:focus {
  outline: none;
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.settings-form .btn { align-self: flex-start; margin-top: 12px; }

.field-row { display: flex; gap: 14px; flex-wrap: wrap; }
.field-row > div { flex: 1; min-width: 240px; display: flex; flex-direction: column; gap: 6px; }

.mfa-options {
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 12px 16px 14px;
  margin: 14px 0 4px;
}
.mfa-options legend { font-size: .86rem; font-weight: 600; padding: 0 6px; }
.radio-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: .9rem;
  padding: 6px 0;
  cursor: pointer;
}
.radio-row input { margin-top: 3px; }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.inline-form input {
  flex: 1;
  min-width: 220px;
  font: inherit;
  font-size: .92rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 9px 12px;
}

.settings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
  margin: 14px 0;
}
.settings-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  font-size: .8rem;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
}
.settings-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.settings-table tr:last-child td { border-bottom: 0; }

.totp-setup {
  margin-top: 18px;
  padding: 16px 18px;
  background: var(--bg);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-s);
}
.totp-setup h3 { margin-top: 0; }
.totp-secret {
  font-family: var(--mono);
  font-size: 1.05rem;
  letter-spacing: .12em;
  background: var(--surface-2);
  padding: 6px 12px;
  border-radius: 6px;
  user-select: all;
}
.totp-uri { font-size: .78rem; overflow-wrap: anywhere; }

/* ---------- read/unread state ---------- */

.card.is-read { opacity: .68; }
.card.is-read .card-title a { color: var(--muted); }
.card.is-read:hover { opacity: 1; }
.read-flag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: var(--accent-strong);
  font-weight: 600;
}
.icon-btn-read.is-read-btn { color: var(--accent-strong); }
.icon-btn-read:hover { color: var(--accent-strong); }
.btn-read { color: var(--accent-strong); border-color: var(--accent-line); background: var(--accent-soft); }

/* ---------- article stats panel ---------- */

.stats-panel {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 13px;
  margin: 0 0 30px;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.stat {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  min-width: 0;
}
.stat-wide { grid-column: span 2; }
.stat-value {
  font-family: var(--serif);
  font-size: 1.22rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.25;
}
.stat-label {
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
}
.stat-sub { font-size: .74rem; color: var(--muted); overflow-wrap: anywhere; }

@media (max-width: 640px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-wide { grid-column: span 2; }
}

/* ---------- add dialog / add page ---------- */

.add-dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lift);
  padding: 22px 24px;
  width: min(480px, calc(100vw - 32px));
}
.add-dialog::backdrop {
  background: rgba(20, 24, 20, .45);
  backdrop-filter: blur(2px);
}

.dialog-head {
  display: flex;
  align-items: center;
  gap: 9px;
}
.dialog-head .icon { color: var(--accent); }
.dialog-head h2 {
  font-family: var(--serif);
  font-size: 1.3rem;
  margin: 0;
  flex: 1;
}
.dialog-close {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 8px;
}
.dialog-close:hover { color: var(--ink); background: var(--surface-2); }
.dialog-sub {
  color: var(--muted);
  font-size: .87rem;
  margin: 4px 0 10px;
}
.dialog-form label { font-size: .84rem; font-weight: 600; margin-top: 8px; }
.dialog-form input[type=url] {
  font: inherit;
  font-size: .93rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 10px 12px;
}
.dialog-form input[type=url]:focus {
  outline: none;
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* ---------- tag editor ---------- */

.tag-editor { position: relative; flex: 1; min-width: 0; }

.te-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 5px 9px;
  min-height: 40px;
  cursor: text;
  transition: border-color .15s, box-shadow .15s;
}
.tag-editor:focus-within .te-box {
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.te-input {
  flex: 1;
  min-width: 150px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: .92rem;
  padding: 6px 3px;
  outline: none;
}
.te-input::placeholder { color: var(--muted); }

.te-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: .8rem;
  font-weight: 600;
  padding: 3px 5px 3px 12px;
  border-radius: 999px;
  background: color-mix(in srgb, hsl(var(--h) 55% 45%) 15%, var(--surface));
  color: color-mix(in srgb, hsl(var(--h) 55% 45%) 78%, var(--ink));
  border: 1px solid color-mix(in srgb, hsl(var(--h) 55% 45%) 38%, var(--line));
  max-width: 100%;
}
.te-chip-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.te-x {
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 2px 7px;
  border-radius: 999px;
  color: inherit;
  opacity: .6;
  transition: opacity .12s, background .12s;
}
.te-x:hover { opacity: 1; background: color-mix(in srgb, currentColor 15%, transparent); }

.te-dropdown {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  right: 0;
  z-index: 60;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: var(--shadow-lift);
  max-height: 260px;
  overflow-y: auto;
  padding: 5px;
}
.te-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: .88rem;
  color: var(--ink);
  padding: 7px 11px;
  border-radius: 7px;
  cursor: pointer;
}
.te-item:hover, .te-item.active { background: var(--accent-soft); }
.te-item-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.te-item-uses { margin-left: auto; color: var(--muted); font-size: .74rem; flex: none; }
.te-item-new {
  flex: none;
  font-size: .72rem;
  font-weight: 700;
  color: var(--accent-ink);
  background: var(--accent-soft);
  border-radius: 5px;
  padding: 2px 7px;
}
.te-empty { padding: 9px 11px; color: var(--muted); font-size: .85rem; }

/* editor inside the compact add-form row: no double borders */
.add-row .te-box { background: transparent; border: 0; padding: 0; min-height: 0; box-shadow: none; }

/* ---------- event log ---------- */

.log-table { display: flex; flex-direction: column; gap: 8px; margin: 12px 0 16px; }
.log-row {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 9px 13px;
  font-size: .88rem;
}
.log-row.log-error { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.log-row.log-warn { border-color: color-mix(in srgb, var(--gold) 45%, var(--line)); }
.log-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}
.log-level {
  font-family: var(--mono);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .08em;
  border-radius: 5px;
  padding: 2px 7px;
}
.badge-info { background: var(--accent-soft); color: var(--accent-ink); }
.badge-warn { background: color-mix(in srgb, var(--gold) 16%, transparent); color: var(--gold); }
.badge-error { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.log-time { color: var(--muted); font-size: .78rem; min-width: 74px; }
.log-event {
  font-family: var(--mono);
  font-size: .76rem;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 5px;
  padding: 1px 7px;
}
.log-msg { flex: 1; min-width: 200px; overflow-wrap: anywhere; }
.log-row details { margin-top: 6px; }
.log-row summary {
  cursor: pointer;
  color: var(--muted);
  font-size: .8rem;
  user-select: none;
}
.log-row summary:hover { color: var(--ink); }
.log-url {
  font-family: var(--mono);
  font-size: .8rem;
  color: var(--accent-strong);
  margin: 6px 0 0;
  overflow-wrap: anywhere;
}
.log-details {
  font-family: var(--mono);
  font-size: .74rem;
  line-height: 1.45;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  margin: 8px 0 0;
  overflow-x: auto;
  white-space: pre-wrap;
  max-height: 320px;
  overflow-y: auto;
}
.log-compact { margin: 10px 0 14px; }
.log-chip-error.chip-active { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); border-color: var(--danger); color: var(--danger); }
.log-chip-warn.chip-active { background: color-mix(in srgb, var(--gold) 14%, var(--surface)); border-color: var(--gold); color: var(--gold); }

.logout-form { margin-left: 4px; }
.logout-form .btn { padding: 7px 12px; font-size: .85rem; color: var(--muted); }
.logout-form .btn:hover { color: var(--ink); }

/* ---------- responsive ---------- */

@media (max-width: 760px) {
  .topbar-inner { gap: 10px; padding: 0 16px; }
  .search { max-width: none; width: auto; flex: 1; }
  .nav { font-size: .88rem; }
  .nav a { padding: 6px 8px; }
  .container { padding: 18px 16px 48px; }
  .cards { grid-template-columns: 1fr; }
  .add-row-tags { flex-wrap: wrap; }
  .article-actions { width: 100%; }
  .tags-form { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
