/* Margin. Lugnt, mycket luft, innehållet först. Ett typsnitt för gränssnittet
   (systemets), ett för läsningen (en bokstil), en accentfärg. */

:root {
  --bg: #f7f6f3;
  --surface: #fbfaf8;
  --reader: #fffefc;
  --ink: #1d1c1a;
  --ink-2: #57544f;
  --ink-3: #8f8b84;
  --line: #e6e3dd;
  --hover: #efede8;
  --active: #e7e4dd;
  --accent: #b5532c;
  --accent-ink: #fff;
  --focus: #b5532c66;
  --shadow: 0 10px 40px -12px #1d1c1a33;

  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --read: Charter, "Bitstream Charter", "Iowan Old Style", "Sitka Text", Cambria, Georgia, serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --bar: 52px;
  --r: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --surface: #1b1b1a;
    --reader: #1f1f1e;
    --ink: #ecebe7;
    --ink-2: #b1aea7;
    --ink-3: #7c7973;
    --line: #2c2b29;
    --hover: #262624;
    --active: #2f2e2b;
    --accent: #e08a5f;
    --accent-ink: #1b1b1a;
    --focus: #e08a5f66;
    --shadow: 0 10px 40px -12px #0009;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--ui);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
svg circle { fill: currentColor; stroke: none; }

/* ——— Rutorna ——— */

.app {
  display: grid;
  grid-template-columns: 248px minmax(300px, 380px) 1fr;
  height: 100dvh;
}
.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.sources { background: var(--bg); border-right: 1px solid var(--line); }
.list { background: var(--surface); border-right: 1px solid var(--line); }
.reader { background: var(--reader); }
.scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.scroll:focus { outline: none; }

.bar {
  display: flex; align-items: center; gap: 4px;
  height: var(--bar); flex: none;
  padding: 0 10px 0 16px;
  padding-top: env(safe-area-inset-top);
  box-sizing: content-box;
}
.bar.foot { height: 44px; padding-top: 0; padding-bottom: env(safe-area-inset-bottom); border-top: 1px solid var(--line); position: relative; }
.grow { flex: 1; }

.icon {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; padding: 0;
  border: 0; border-radius: var(--r); background: none;
  color: var(--ink-2); text-decoration: none;
}
.icon[aria-pressed="true"] { color: var(--accent); }
.icon[aria-pressed="true"] svg path { fill: currentColor; fill-opacity: .14; }
#toggle-save[aria-pressed="true"] svg path { fill-opacity: 1; }
@media (hover: hover) { .icon:hover { background: var(--hover); color: var(--ink); } }

.back { display: none; }
.wordmark { font-weight: 650; letter-spacing: -.01em; flex: 1; }

body.refreshing #refresh svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { body.refreshing #refresh svg { animation: none; opacity: .5; } }

/* ——— Källor ——— */

#source-list { padding: 4px 8px 16px; }
.group { padding: 4px 0; }
.group + .group { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 8px; }
.src {
  display: flex; align-items: center; gap: 8px;
  min-height: 32px; padding: 0 8px;
  border-radius: 6px; text-decoration: none; color: var(--ink);
}
.src .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src .count { color: var(--ink-3); font-size: 13px; font-variant-numeric: tabular-nums; }
.src.active { background: var(--active); }
@media (hover: hover) { .src:hover:not(.active) { background: var(--hover); } }

.folder-head { display: flex; align-items: center; }
.folder-head .src { flex: 1; min-width: 0; padding-left: 2px; font-weight: 550; }
.fold {
  display: grid; place-items: center; width: 24px; height: 32px; padding: 0;
  border: 0; background: none; color: var(--ink-3);
}
.fold svg { width: 14px; height: 14px; transition: transform .15s; }
.folder.open .fold svg { transform: rotate(90deg); }
.feeds .src { padding-left: 26px; color: var(--ink-2); }
.feeds .src.active { color: var(--ink); }

.fav { width: 16px; height: 16px; border-radius: 3px; flex: none; object-fit: contain; }
.fav.missing { visibility: hidden; position: relative; }
.fav.missing::after { content: ""; visibility: visible; position: absolute; inset: 5px; border-radius: 50%; background: var(--line); }
.err { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: none; }

.status { flex: 1; color: var(--ink-3); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.menu {
  position: absolute; bottom: calc(100% + 6px); right: 8px; z-index: 20;
  min-width: 200px; padding: 6px;
  background: var(--reader); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.menu button {
  display: block; width: 100%; text-align: left;
  padding: 8px 10px; border: 0; border-radius: 6px; background: none;
}
@media (hover: hover) { .menu button:hover { background: var(--hover); } }

/* ——— Lista ——— */

.list .bar { gap: 8px; border-bottom: 1px solid var(--line); }
.scope { flex: 1; min-width: 0; margin: 0; font-size: 15px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.seg { display: inline-flex; padding: 2px; border-radius: 8px; background: var(--hover); flex: none; }
.seg button {
  border: 0; background: none; padding: 3px 10px; border-radius: 6px;
  font-size: 13px; color: var(--ink-2);
}
.seg button[aria-pressed="true"] { background: var(--reader); color: var(--ink); box-shadow: 0 1px 2px #0000001a; }

.feed-note { margin: 0; padding: 8px 16px; font-size: 13px; color: var(--ink-3); border-bottom: 1px solid var(--line); }
.feed-note a { color: var(--ink-2); }
.feed-note .error { color: var(--accent); }
.link { border: 0; background: none; padding: 0; color: var(--ink-2); text-decoration: underline; font-size: inherit; }

.day {
  position: sticky; top: 0; z-index: 1;
  margin: 0; padding: 14px 16px 6px;
  background: var(--surface);
  font-size: 12px; font-weight: 600; letter-spacing: .02em; color: var(--ink-3);
}
.row {
  display: block; padding: 10px 16px 12px;
  text-decoration: none; border-left: 3px solid transparent;
  content-visibility: auto; contain-intrinsic-size: auto 90px;
}
.row + .row { box-shadow: inset 0 1px var(--line); }
.row .meta { display: flex; gap: 8px; font-size: 12px; color: var(--ink-3); margin-bottom: 2px; }
.row .source { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row time { flex: none; font-variant-numeric: tabular-nums; }
.row .title { display: block; font-weight: 600; line-height: 1.3; text-wrap: pretty; }
.row .excerpt {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  margin-top: 3px; font-size: 13.5px; color: var(--ink-2); line-height: 1.4;
}
.row.read .title { font-weight: 450; color: var(--ink-2); }
.row.read .excerpt { color: var(--ink-3); }
.row.saved .meta::before { content: ""; width: 6px; height: 6px; margin: auto 0; border-radius: 50%; background: var(--accent); flex: none; order: -1; }
.row.selected { background: var(--active); border-left-color: var(--accent); }
@media (hover: hover) { .row:hover:not(.selected) { background: var(--hover); } }

.more { padding: 16px; text-align: center; color: var(--ink-3); font-size: 13px; }
.empty { padding: 48px 24px; margin: 0; text-align: center; color: var(--ink-3); }

/* ——— Artikel ——— */

.reader .bar { padding-right: 12px; }
#article { padding: 8px 24px 96px; }
.article { max-width: 40rem; margin: 0 auto; padding-top: 16px; }
.byline { margin: 0 0 10px; color: var(--ink-3); font-size: 13px; }
.article h1 {
  margin: 0 0 24px; font: 700 clamp(24px, 3.2vw, 32px)/1.15 var(--ui); letter-spacing: -.015em; text-wrap: balance;
}
.article h1 a { text-decoration: none; }
@media (hover: hover) { .article h1 a:hover { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 4px; } }
.notice { color: var(--ink-3); font-size: 13px; margin: -12px 0 20px; }
.quiet { color: var(--ink-3); }

.content {
  font: 19px/1.6 var(--read);
  overflow-wrap: break-word; hyphens: auto;
}
.content > :first-child { margin-top: 0; }
.content p, .content ul, .content ol, .content blockquote, .content figure, .content pre, .content table { margin: 0 0 1.05em; }
.content h2, .content h3, .content h4 { font-family: var(--ui); line-height: 1.25; margin: 1.6em 0 .5em; }
.content h2 { font-size: 1.15em; }
.content h3, .content h4 { font-size: 1em; }
.content a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.content img { display: block; max-width: 100%; height: auto; margin: 1.2em auto; border-radius: 4px; }
.content figure { margin-left: 0; margin-right: 0; }
.content figure img { margin-bottom: .4em; }
.content figcaption { font: 13px/1.4 var(--ui); color: var(--ink-3); }
.content blockquote { margin-left: 0; padding-left: 1em; border-left: 2px solid var(--line); color: var(--ink-2); }
.content pre { overflow-x: auto; padding: 12px 14px; border-radius: 6px; background: var(--hover); font: 14px/1.5 var(--mono); }
.content code { font-family: var(--mono); font-size: .85em; }
.content pre code { font-size: inherit; }
.content table { display: block; overflow-x: auto; border-collapse: collapse; font: 14px/1.4 var(--ui); }
.content th, .content td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.content hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }

/* ——— Välkommen, dialog, toast ——— */

.welcome {
  position: fixed; inset: 0; z-index: 30;
  display: grid; place-items: center; padding: 24px;
  background: var(--bg);
}
.welcome-card { max-width: 30rem; }
.welcome-card .wordmark { color: var(--ink-3); margin: 0 0 32px; }
.welcome-card h2 { font: 700 30px/1.15 var(--ui); letter-spacing: -.02em; margin: 0 0 12px; }
.welcome-card p { color: var(--ink-2); margin: 0 0 24px; }
.welcome-card .hint { font-size: 13px; color: var(--ink-3); margin-top: 20px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions button {
  padding: 9px 16px; border-radius: var(--r);
  border: 1px solid var(--line); background: var(--reader); font-weight: 550;
}
.actions .primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }

dialog {
  width: min(28rem, calc(100vw - 32px)); padding: 24px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--reader); color: var(--ink); box-shadow: var(--shadow);
}
dialog::backdrop { background: #0000002e; }
dialog h2 { margin: 0 0 16px; font-size: 18px; }
dialog label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--ink-2); }
dialog input {
  display: block; width: 100%; margin-top: 6px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); font-size: 16px;
}
dialog .actions { justify-content: flex-end; margin-top: 8px; }
dialog .error { color: var(--accent); font-size: 14px; margin: 0 0 12px; }
.choices p { margin: 0 0 8px; font-size: 14px; color: var(--ink-2); }
.choice {
  display: block; width: 100%; text-align: left; margin-bottom: 6px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--surface);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 40;
  transform: translateX(-50%);
  width: max-content; max-width: min(32rem, calc(100vw - 32px));
  display: flex; align-items: center; gap: 14px;
  padding: 10px 14px; border-radius: 10px;
  background: var(--ink); color: var(--bg); box-shadow: var(--shadow); font-size: 14px;
  text-wrap: balance;
}
.toast button { border: 0; background: none; color: var(--accent); font-weight: 650; padding: 0; flex: none; }

/* ——— Mellanbredd: källorna glider in över listan ——— */

@media (max-width: 1023px) {
  .app { grid-template-columns: minmax(300px, 360px) 1fr; }
  .sources {
    position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 10;
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow);
  }
  body.sources-open .sources { transform: none; }
  #to-sources { display: inline-grid; }
}

/* ——— Telefon: en ruta i taget ——— */

@media (max-width: 699px) {
  .app { display: block; }
  .pane { position: fixed; inset: 0; border: 0; }
  .sources { width: auto; transform: none; transition: none; box-shadow: none; }
  body:not([data-pane="sources"]) .sources,
  body:not([data-pane="list"]) .list,
  body:not([data-pane="article"]) .reader { display: none; }
  #to-list { display: inline-grid; }
  .bar { padding-left: 8px; }
  .wordmark { padding-left: 8px; }
  #article { padding: 4px 20px 80px; }
  .article { padding-top: 8px; }
  .content { font-size: 18px; }
  .src { min-height: 40px; }
  .row { padding: 12px 16px 14px; }
}
