/* =============================================================
   TOKENS — Design system variables
   ============================================================= */
:root {
  /* Colors — warm stone palette */
  --c-bg:             #fafaf8;
  --c-surface:        #ffffff;
  --c-surface-subtle: #f5f5f4;
  --c-border:         #e7e5e4;
  --c-border-strong:  #d6d3d1;
  --c-text:           #1c1917;
  --c-text-secondary: #57534e;
  --c-text-muted:     #78716c;
  --c-accent:         #c2410c;
  --c-accent-hover:   #9a3412;
  --c-accent-subtle:  #fff7ed;
  --c-unread:         #c2410c;
  --c-success-bg:     #f0fdf4;
  --c-success-text:   #15803d;
  --c-success-border: #bbf7d0;

  /* Spacing */
  --sp-1:  4px;
  --sp-2:  8px;
  --sp-3:  12px;
  --sp-4:  16px;
  --sp-5:  20px;
  --sp-6:  24px;
  --sp-8:  32px;
  --sp-10: 40px;
  --sp-12: 48px;

  /* Typography */
  --font:      system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "Fira Code", monospace;
  --text-xs:   0.75rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.25rem;
  --text-2xl:  1.5rem;
  --text-3xl:  1.875rem;
  --lh-tight:   1.3;
  --lh-snug:    1.45;
  --lh-normal:  1.6;
  --lh-relaxed: 1.75;

  /* UI */
  --radius-sm: 4px;
  --radius:    6px;
  --radius-lg: 10px;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / .06);
  --shadow:    0 1px 3px rgb(0 0 0 / .10), 0 1px 2px rgb(0 0 0 / .06);
  --transition: 150ms ease;

  /* Layout */
  --sidebar-w:  220px;
  --nav-h:      48px;
  --reading-max: 680px;
}


/* =============================================================
   BASE — Reset + global typography
   ============================================================= */
*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: var(--lh-normal);
  color: var(--c-text);
  background: var(--c-bg);
}

h1, h2, h3, h4, h5, h6 {
  margin: 0 0 var(--sp-3);
  line-height: var(--lh-tight);
  font-weight: 600;
  color: var(--c-text);
}

h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }

p { margin: 0 0 var(--sp-4); }
p:last-child { margin-bottom: 0; }

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

ul, ol { margin: 0; padding-left: var(--sp-6); }
li { margin-bottom: var(--sp-1); }

hr {
  border: none;
  border-top: 1px solid var(--c-border);
  margin: var(--sp-6) 0;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}


/* =============================================================
   FORMS — Inputs & buttons
   ============================================================= */
input[type="text"],
input[type="url"],
input[type="email"],
input[type="password"] {
  display: block;
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  font: inherit;
  font-size: var(--text-sm);
  color: var(--c-text);
  background: var(--c-surface);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
input[type="text"]:focus,
input[type="url"]:focus,
input[type="email"]:focus,
input[type="password"]:focus {
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px rgb(194 65 12 / .12);
}

label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--c-text-secondary);
  margin-bottom: var(--sp-1);
}

button,
.btn,
input[type="submit"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  color: #fff;
  background: var(--c-accent);
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--transition), box-shadow var(--transition);
}
button:hover,
.btn:hover,
input[type="submit"]:hover {
  background: var(--c-accent-hover);
  color: #fff;
  text-decoration: none;
}
button:focus-visible,
.btn:focus-visible,
input[type="submit"]:focus-visible {
  outline: 2px solid var(--c-accent);
  outline-offset: 2px;
}

.btn-ghost,
button.btn-ghost {
  color: var(--c-text-secondary);
  background: transparent;
  border-color: var(--c-border-strong);
}
.btn-ghost:hover,
button.btn-ghost:hover {
  background: var(--c-surface-subtle);
  color: var(--c-text);
}

.btn-sm {
  padding: var(--sp-1) var(--sp-3);
  font-size: var(--text-xs);
}

.field { display: flex; flex-direction: column; }


/* =============================================================
   NAV
   ============================================================= */
nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  height: var(--nav-h);
  padding: 0 var(--sp-6);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  box-shadow: var(--shadow-sm);
}

.nav-brand {
  font-size: var(--text-base);
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--c-text);
  text-decoration: none;
  margin-right: auto;
}
.nav-brand:hover { text-decoration: none; color: var(--c-text); }

nav a:not(.nav-brand) {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--c-text-secondary);
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}
nav a:not(.nav-brand):hover {
  color: var(--c-text);
  background: var(--c-surface-subtle);
  text-decoration: none;
}

/* Sign-out button styled as a nav link */
nav form { display: inline; }
#sign-out-button {
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--c-text-muted);
  background: none;
  border: none;
  padding: var(--sp-1) var(--sp-2);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}
#sign-out-button:hover {
  color: var(--c-text);
  background: var(--c-surface-subtle);
}


/* =============================================================
   LAYOUT — Sidebar + main grid
   ============================================================= */
#layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: calc(100vh - var(--nav-h));
  transition: grid-template-columns 0.2s ease;
}

/* Collapsed */
#layout:has(#sidebar-toggle:checked) {
  grid-template-columns: 0 1fr;
}

#sidebar {
  position: sticky;
  top: var(--nav-h);
  height: calc(100vh - var(--nav-h));
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  padding-bottom: var(--sp-6);
  transition: padding var(--transition), border-color var(--transition);
}
#layout:has(#sidebar-toggle:checked) #sidebar {
  padding: 0;
  border-right-color: transparent;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: var(--sp-3) var(--sp-3) 0;
}

#sidebar h3 {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--c-text-muted);
  padding: var(--sp-4) var(--sp-4) var(--sp-1);
  margin: 0;
  white-space: nowrap;
}
#sidebar ul { list-style: none; padding: 0; margin: 0; }
#sidebar li a {
  display: block;
  padding: var(--sp-2) var(--sp-4);
  font-size: var(--text-sm);
  color: var(--c-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background var(--transition), color var(--transition);
}
#sidebar li a:hover {
  background: var(--c-surface-subtle);
  color: var(--c-text);
  text-decoration: none;
}
.sidebar-footer {
  padding: var(--sp-4) var(--sp-4) 0;
  border-top: 1px solid var(--c-border);
  margin-top: var(--sp-4);
}
.sidebar-footer a {
  font-size: var(--text-sm);
  color: var(--c-text-muted);
}

/* Toggle button shared styles */
.sidebar-collapse-btn,
.sidebar-expand-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  font-size: var(--text-sm);
  line-height: 1;
  color: var(--c-text-muted);
  background: transparent;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  transition: background var(--transition), color var(--transition);
}
.sidebar-collapse-btn:hover,
.sidebar-expand-btn:hover {
  background: var(--c-surface-subtle);
  color: var(--c-text);
}

/* Expand button lives in main — hidden by default, shown when sidebar collapsed */
.sidebar-expand-btn { display: none; }
#layout:has(#sidebar-toggle:checked) .sidebar-expand-btn { display: inline-flex; }
#layout:has(#sidebar-toggle:checked) .sidebar-collapse-btn { display: none; }

/* Main article list */
#article-list { overflow-y: auto; }

.article-list-header {
  display: flex;
  align-items: center;
  padding: var(--sp-2) var(--sp-4);
  border-bottom: 1px solid var(--c-border);
  background: var(--c-surface);
  position: sticky;
  top: var(--nav-h);
  z-index: 10;
  min-height: 40px;
}


/* =============================================================
   ARTICLES INDEX — Dense list
   ============================================================= */
.article-row {
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5) var(--sp-3) var(--sp-6);
  border-bottom: 1px solid var(--c-border);
  background: var(--c-surface);
  position: relative;
  transition: background var(--transition);
}
.article-row:hover { background: var(--c-surface-subtle); }

/* Unread dot */
.article-row.unread::before {
  content: "";
  position: absolute;
  left: var(--sp-2);
  top: 50%;
  transform: translateY(-50%);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c-unread);
}

.article-row .article-title-link {
  flex: 1;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--c-text);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.article-row .article-title-link:hover {
  color: var(--c-accent);
  text-decoration: none;
}
.article-row.read .article-title-link {
  color: var(--c-text-muted);
  font-weight: 400;
}

.feed-name,
.pub-date {
  font-size: var(--text-xs);
  color: var(--c-text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.pub-date {
  font-variant-numeric: tabular-nums;
  min-width: 38px;
  text-align: right;
}

/* Pagination (Pagy) */
.pagy-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--sp-1);
  padding: var(--sp-5) var(--sp-4);
}
.pagy-nav a,
.pagy-nav .current,
.pagy-nav .disabled {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 var(--sp-2);
  font-size: var(--text-sm);
  border-radius: var(--radius-sm);
}
.pagy-nav a {
  color: var(--c-text-secondary);
  border: 1px solid var(--c-border);
  transition: background var(--transition);
}
.pagy-nav a:hover {
  background: var(--c-surface-subtle);
  text-decoration: none;
}
.pagy-nav .current {
  background: var(--c-accent);
  color: #fff;
  font-weight: 600;
  border: 1px solid transparent;
}
.pagy-nav .disabled {
  color: var(--c-border-strong);
}


/* =============================================================
   ARTICLE SHOW — Reading view
   ============================================================= */
.article-show {
  max-width: var(--reading-max);
  margin: 0 auto;
  padding: var(--sp-8) var(--sp-6) var(--sp-12);
}

.back-link {
  display: inline-block;
  font-size: var(--text-sm);
  color: var(--c-text-muted);
  margin-bottom: var(--sp-5);
}
.back-link:hover { color: var(--c-accent); text-decoration: none; }

.article-show h1 {
  font-size: var(--text-2xl);
  line-height: var(--lh-snug);
  margin-bottom: var(--sp-3);
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-1) var(--sp-4);
  font-size: var(--text-sm);
  color: var(--c-text-muted);
  margin-bottom: var(--sp-4);
}
.article-meta a {
  color: var(--c-text-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.article-meta a:hover { color: var(--c-accent); }

/* Read status action */
#article-read-status form { display: inline; }
#article-read-status { margin-bottom: var(--sp-5); }

#article-content {
  font-size: var(--text-base);
  line-height: var(--lh-relaxed);
}
#article-content p { margin-bottom: var(--sp-5); }
#article-content p:last-child { margin-bottom: 0; }


/* =============================================================
   SUMMARY TABS — Pure CSS radio-based tab system
   ============================================================= */
#summary-section {
  margin-top: var(--sp-8);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.summary-section-heading {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--c-text-muted);
  padding: var(--sp-3) var(--sp-5);
  margin: 0;
  background: var(--c-surface-subtle);
  border-bottom: 1px solid var(--c-border);
}

#summary-tabs {
  display: flex;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
}

.tab-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-3) var(--sp-2);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--c-text-muted);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  margin-bottom: -1px;
  user-select: none;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}
.tab-btn:hover {
  color: var(--c-text);
  background: var(--c-surface-subtle);
}

/* Active tab highlight per checked radio */
#summary-section:has(#tab-tldr:checked) [for="tab-tldr"],
#summary-section:has(#tab-bullets:checked) [for="tab-bullets"],
#summary-section:has(#tab-tweet_thread:checked) [for="tab-tweet_thread"],
#summary-section:has(#tab-podcast_script:checked) [for="tab-podcast_script"] {
  color: var(--c-accent);
  border-bottom-color: var(--c-accent);
}

/* All panels hidden */
.summary-panel { display: none; }

/* Show the active panel */
#summary-section:has(#tab-tldr:checked) #panel-tldr,
#summary-section:has(#tab-bullets:checked) #panel-bullets,
#summary-section:has(#tab-tweet_thread:checked) #panel-tweet_thread,
#summary-section:has(#tab-podcast_script:checked) #panel-podcast_script {
  display: block;
}

.summary-panel-inner {
  padding: var(--sp-5) var(--sp-6);
  background: var(--c-surface);
}

/* Summary content (from _summary.html.erb) */
.summary { }
.summary h3 { display: none; } /* Label shown by tab instead */
.summary-content {
  font-size: var(--text-sm);
  line-height: var(--lh-relaxed);
  color: var(--c-text);
}
.summary-content p:last-child { margin-bottom: 0; }

.summary-meta {
  font-size: var(--text-xs);
  color: var(--c-text-muted);
  margin-top: var(--sp-5);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--c-border);
}

/* Placeholder + generate form */
.summary-placeholder-box {
  text-align: center;
  padding: var(--sp-10) var(--sp-6);
}
.summary-placeholder-box p {
  font-size: var(--text-sm);
  color: var(--c-text-muted);
  margin-bottom: var(--sp-4);
}

/* Generating state */
.generating {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--text-sm);
  color: var(--c-text-muted);
  padding: var(--sp-10) var(--sp-6);
  justify-content: center;
}

.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--c-border-strong);
  border-top-color: var(--c-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }


/* =============================================================
   FEEDS PAGE
   ============================================================= */
.feeds-page {
  max-width: 820px;
  margin: 0 auto;
  padding: var(--sp-8) var(--sp-6) var(--sp-12);
}
.feeds-page h1 { margin-bottom: var(--sp-6); }

.add-feed-form {
  display: flex;
  gap: var(--sp-3);
  align-items: flex-end;
  padding: var(--sp-5);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  margin-bottom: var(--sp-8);
}
.add-feed-form .field { flex: 1; }
.add-feed-form label { margin-bottom: var(--sp-1); }
.add-feed-form input[type="url"] { width: 100%; }

.feeds-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.feeds-table thead tr {
  border-bottom: 1px solid var(--c-border);
  background: var(--c-surface-subtle);
}
.feeds-table th {
  padding: var(--sp-3);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--c-text-muted);
  text-align: left;
}
.feeds-table td {
  padding: var(--sp-3);
  border-bottom: 1px solid var(--c-border);
  vertical-align: middle;
  color: var(--c-text-secondary);
}
.feeds-table tr:last-child td { border-bottom: none; }
.feeds-table .feed-name-cell {
  font-weight: 500;
  color: var(--c-text);
}

.category-form {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
}
.category-form input[type="text"] {
  width: auto;
  min-width: 110px;
  font-size: var(--text-xs);
  padding: var(--sp-1) var(--sp-2);
}

.actions-cell {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
}
.actions-cell form { display: inline; }

/* =============================================================
   FLASH MESSAGES
   ============================================================= */
.flash-container {
  padding: 0 var(--sp-6);
}
#notice {
  margin: var(--sp-3) 0;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  background: var(--c-success-bg);
  color: var(--c-success-text);
  border: 1px solid var(--c-success-border);
}
#alert {
  margin: var(--sp-3) 0;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  background: var(--c-accent-subtle);
  color: var(--c-accent);
  border: 1px solid #fed7aa;
}
