:root {
  color-scheme: light dark;
  --paper: #f7f3ea;
  --surface: #fffdf8;
  --sidebar: #efe9dc;
  --ink: #26211b;
  --muted: #6d6456;
  --line: #ddd5c4;
  --accent: #1f6f6b;
  --accent-ink: #ffffff;
  --accent-soft: #d9ebe7;
  --topic: #1f6f6b;
  --topic-bg: #dcece9;
  --company: #8a4b12;
  --company-bg: #f4e4cf;
  --alert: #a4322a;
  --hover: rgba(70, 55, 30, .07);
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1b1a17;
    --surface: #211f1b;
    --sidebar: #171613;
    --ink: #ece6da;
    --muted: #a1998a;
    --line: #38342c;
    --accent: #66bdb3;
    --accent-ink: #10201e;
    --accent-soft: #233a37;
    --topic: #7fcec5;
    --topic-bg: #223734;
    --company: #e6b57e;
    --company-bg: #3b2d1d;
    --alert: #ee8d84;
    --hover: rgba(255, 245, 225, .07);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--paper); color: var(--ink); font: 14px/1.45 var(--ui); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
[hidden] { display: none !important; }

.app { display: grid; grid-template-columns: 264px minmax(320px, 400px) 1fr; height: 100dvh; }

/* Sidebar */
.sidebar { background: var(--sidebar); border-right: 1px solid var(--line); overflow-y: auto; padding: 16px 10px 24px; }
.brand { display: flex; align-items: center; gap: 9px; padding: 2px 8px 14px; font: 600 19px/1.2 var(--serif); }
.brand img { width: 22px; height: 22px; }
.nav-section { margin-top: 18px; }
.nav-heading { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 3px 8px; color: var(--muted); font-size: 11px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; }
.nav-add { border: 0; background: none; color: var(--muted); border-radius: 5px; font-size: 16px; line-height: 1; width: 26px; height: 26px; }
.nav-add:hover { background: var(--hover); color: var(--ink); }
.nav-empty { padding: 2px 8px 4px; color: var(--muted); font-size: 12.5px; }
.nav-row { display: flex; align-items: center; border-radius: 6px; }
.nav-row:hover { background: var(--hover); }
.nav-row.active { background: var(--accent-soft); }
.nav-item { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; border: 0; background: none; padding: 5px 4px 5px 8px; text-align: left; }
.nav-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-row.active .nav-name { font-weight: 600; }
.nav-count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.nav-warn { color: var(--alert); font-weight: 700; }
.nav-edit { border: 0; background: none; color: var(--muted); width: 26px; height: 26px; border-radius: 5px; opacity: 0; flex: none; }
.nav-row:hover .nav-edit, .nav-edit:focus-visible { opacity: 1; }
.nav-edit:hover { background: var(--hover); color: var(--ink); }

/* Article list */
.list-pane { position: relative; display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--line); }
.list-header { padding: 14px 14px 8px; border-bottom: 1px solid var(--line); }
.list-title-row { display: flex; align-items: center; gap: 8px; }
.list-title-row h2 { flex: 1; min-width: 0; font: 600 20px/1.2 var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; cursor: pointer; }
.check input, .article-check { accent-color: var(--accent); margin: 0; width: 15px; height: 15px; cursor: pointer; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 5px 11px; font-size: 13px; white-space: nowrap; text-decoration: none; color: var(--ink); display: inline-block; }
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-quiet { border-color: transparent; background: none; color: var(--muted); padding: 5px 7px; font-size: 12.5px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--alert); }
.icon-btn { border: 0; background: none; font-size: 17px; width: 30px; height: 30px; border-radius: 6px; }
.icon-btn:hover { background: var(--hover); }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.segmented button { border: 0; background: none; padding: 3px 10px; font-size: 12.5px; color: var(--muted); }
.segmented button[aria-pressed="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }

.articles { flex: 1; overflow-y: auto; min-height: 0; }
.article-row { display: grid; grid-template-columns: 34px 1fr; border-bottom: 1px solid var(--line); }
.article-row.active { background: var(--accent-soft); }
.article-row:not(.active):hover { background: var(--hover); }
.article-select { display: flex; justify-content: center; padding-top: 13px; cursor: pointer; }
.article-open { border: 0; background: none; text-align: left; padding: 10px 12px 10px 0; min-width: 0; width: 100%; }
.article-meta { display: flex; gap: 6px; color: var(--muted); font-size: 12px; }
.article-feed { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.article-date { margin-left: auto; flex: none; }
.article-title { margin: 2px 0 3px; font: 600 15px/1.3 var(--serif); }
.article-snippet { color: var(--muted); font-size: 12.5px; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
.article-row.is-read .article-title { font-weight: 400; color: var(--muted); }
.article-row.is-read .article-snippet { display: none; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.tag { border-radius: 4px; padding: 0 6px; font-size: 11.5px; line-height: 1.6; background: var(--topic-bg); color: var(--topic); }
.tag.company { background: var(--company-bg); color: var(--company); }
.load-more { display: block; margin: 12px auto; }
.empty { padding: 32px 22px; color: var(--muted); text-align: center; }
.empty h3 { color: var(--ink); font: 600 18px/1.3 var(--serif); margin-bottom: 6px; }
.empty .actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 14px; }
.export-bar { display: flex; align-items: center; gap: 8px; padding: 9px 12px; background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -4px 12px rgba(0, 0, 0, .06); }
.export-bar span { flex: 1; font-weight: 600; font-size: 13px; }

/* Reader */
.reader-pane { overflow-y: auto; min-width: 0; background: var(--paper); }
.reader-inner { max-width: 680px; margin: 0 auto; padding: 26px 32px 64px; }
.reader-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 20px; }
.reader-title { font: 600 29px/1.2 var(--serif); margin-bottom: 8px; }
.reader-title a { color: inherit; text-decoration: none; }
.reader-title a:hover { text-decoration: underline; }
.reader-meta { color: var(--muted); font-size: 13px; }
.reader-body { margin-top: 20px; font: 17px/1.62 var(--serif); overflow-wrap: anywhere; }
.reader-body img { max-width: 100%; height: auto; }
.reader-body a { color: var(--accent); }
.reader-body pre { overflow-x: auto; padding: 10px; background: var(--hover); border-radius: 6px; font-size: 14px; }
.reader-body blockquote { margin-left: 0; padding-left: 14px; border-left: 3px solid var(--line); color: var(--muted); }
.reader-body table { border-collapse: collapse; display: block; overflow-x: auto; }
.reader-body td, .reader-body th { border: 1px solid var(--line); padding: 4px 8px; }
.reader-note { margin-top: 24px; color: var(--muted); font-size: 13px; }
.reader-empty { display: flex; align-items: center; justify-content: center; height: 100%; padding: 24px; color: var(--muted); text-align: center; }
kbd { border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; font: 12px var(--ui); }
.back { display: none; }

/* Dialog */
dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); width: min(470px, calc(100vw - 32px)); padding: 20px; }
dialog::backdrop { background: rgba(20, 15, 8, .45); }
dialog h2 { font: 600 20px/1.25 var(--serif); margin-bottom: 12px; }
.field { display: block; margin-top: 12px; }
.field > span { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 3px; }
.field input[type="text"], .field input[type="url"], .field select { width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.steps { margin: 0; padding-left: 20px; color: var(--muted); font-size: 13px; }
.steps a { color: var(--accent); }
.form-error { color: var(--alert); margin-top: 10px; font-size: 13px; }
.dialog-actions { display: flex; align-items: center; gap: 8px; margin-top: 18px; }
.dialog-actions .spacer { flex: 1; }
.link-btn { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; font-size: inherit; }
.field input[type="file"] { width: 100%; }
.import-failures { margin: 10px 0; padding: 0; list-style: none; max-height: 40vh; overflow-y: auto; }
.import-failures li { padding: 7px 0; border-top: 1px solid var(--line); }
.import-failures li > * { display: block; }
.feed-url { word-break: break-all; color: var(--muted); font-size: 12.5px; }

.toast { position: fixed; left: 50%; top: 14px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; background: var(--ink); color: var(--paper); padding: 8px 14px; border-radius: 8px; font-size: 13px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); z-index: 10; max-width: calc(100vw - 32px); }
.toast button { border: 0; background: none; color: inherit; font-weight: 700; text-decoration: underline; padding: 0; }

.only-narrow { display: none; }

@media (max-width: 1040px) {
  .app { grid-template-columns: 230px minmax(0, 1fr); }
  .reader-pane { display: none; }
  body[data-pane="reader"] .reader-pane { display: block; }
  body[data-pane="reader"] .list-pane { display: none; }
  .back { display: inline-block; }
}
@media (max-width: 700px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .only-narrow { display: inline-block; }
  .sidebar { display: none; border-right: 0; }
  body[data-pane="sidebar"] .sidebar { display: block; }
  body[data-pane="sidebar"] .list-pane { display: none; }
  .nav-edit { opacity: 1; }
  .reader-inner { padding: 16px 16px 48px; }
  .reader-title { font-size: 25px; }
}

/* ---------- AI summaries ---------- */
.summary { margin: 18px 0 4px; padding: 12px 14px; background: var(--accent-soft); border-radius: 8px; }
.summary-label { font-size: 12px; font-weight: 600; color: var(--muted); }
.summary-text { margin-top: 4px; font: 16px/1.5 var(--serif); }
.summary .link-btn { margin-top: 6px; font-size: 12.5px; }

/* ---------- Account ---------- */
.account { margin-top: 22px; padding: 12px 8px 4px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.account-email { overflow-wrap: anywhere; }
.account-actions { display: flex; gap: 12px; margin-top: 6px; }
.people { margin: 4px 0 14px; padding: 0; list-style: none; }
.people li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }

/* ---------- Login ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: min(380px, 100%); padding: 26px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.login-card .brand { padding: 0 0 12px; }
.login-card p { margin-bottom: 16px; color: var(--muted); }
.login-card .form-error { margin: 12px 0 0; color: var(--alert); }
