:root {
  --page: #f5f3ee;
  --surface: #ffffff;
  --surface-subtle: #faf9f6;
  --ink: #171715;
  --ink-soft: #4e4c47;
  --muted: #716e67;
  --accent: #fec107;
  --accent-hover: #eeb400;
  --accent-soft: #fff5cf;
  --border: #e4e0d7;
  --border-strong: #c9c4ba;
  --success: #18764b;
  --success-soft: #e7f5ed;
  --danger: #a82b24;
  --danger-soft: #fbecea;
  --info: #275e8a;
  --info-soft: #eaf3fa;
  --focus: #815f00;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-float: 0 12px 32px rgba(44, 40, 31, .08);
  --font: "Be Vietnam Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 84px; scroll-padding-bottom: 100px; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--page); color: var(--ink); font-family: var(--font); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
a { color: inherit; }
button, input { font: inherit; }
button, a, input, label { touch-action: manipulation; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
input:focus-visible { outline-offset: 0; border-color: var(--focus); }
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 1000; padding: 10px 14px; background: var(--ink); color: #fff; transform: translateY(-150%); }
.skip-link:focus { transform: translateY(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; }
.eyebrow { margin: 0 0 6px; color: var(--muted); font-size: .68rem; line-height: 1.4; font-weight: 800; letter-spacing: .11em; }
.text-link { display: inline-flex; min-height: 44px; align-items: center; color: var(--ink-soft); font-size: .78rem; font-weight: 700; text-underline-offset: 4px; }
.text-link:hover { color: var(--ink); text-decoration-color: var(--accent); text-decoration-thickness: 2px; }

/* Reader */
.reader-page { width: min(1120px, 100%); margin: 0 auto; padding: 38px 24px 72px; }
.reader-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 30px; }
.title-row { display: flex; align-items: center; gap: 13px; }
.title-mark { width: 7px; height: 31px; flex: 0 0 auto; background: var(--accent); }
.reader-header h1 { margin: 0; font-size: clamp(1.6rem, 3vw, 1.9rem); line-height: 1.2; font-weight: 800; letter-spacing: -.035em; text-wrap: balance; }
.reader-subtitle { margin: 8px 0 0 20px; color: var(--muted); font-size: .75rem; line-height: 1.55; }
.reader-admin-link { flex: 0 0 auto; }
.story-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; align-items: stretch; }
.story-card { display: grid; grid-template-rows: auto 1fr; min-width: 0; overflow: hidden; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); }
.story-media { position: relative; display: block; aspect-ratio: 16 / 9; overflow: hidden; background: #ece9e2; }
.story-image { position: relative; z-index: 1; display: block; width: 100%; height: 100%; object-fit: cover; transition: transform 240ms ease; }
.story-media:hover .story-image { transform: scale(1.015); }
.image-fallback { position: absolute; inset: 0; display: grid; align-content: center; justify-items: center; overflow: hidden; color: var(--ink); background: linear-gradient(135deg, #f1ede4 0 49.5%, #ebe6dc 50%); }
.image-fallback::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 8px; background: var(--accent); }
.image-fallback::after { content: ""; position: absolute; width: 220px; height: 220px; border: 1px solid rgba(23, 23, 21, .12); border-radius: 50%; }
.image-fallback b, .image-fallback span { position: relative; z-index: 1; line-height: 1; letter-spacing: .08em; }
.image-fallback b { font-size: clamp(1.5rem, 4vw, 2.2rem); }
.image-fallback span { margin-top: 6px; color: var(--muted); font-size: .72rem; font-weight: 700; }
.story-content { display: grid; grid-template-rows: auto auto 1fr auto; min-height: 310px; padding: 22px 23px 19px; }
.story-category { width: fit-content; margin-bottom: 14px; padding: 6px 9px; background: var(--accent); color: var(--ink); font-size: .625rem; line-height: 1; font-weight: 800; letter-spacing: .035em; }
.story-headline { margin: 0 0 14px; font-size: 1.36rem; line-height: 1.36; font-weight: 700; letter-spacing: -.025em; text-wrap: pretty; }
.story-headline a { color: var(--ink); text-decoration: none; }
.story-headline a:hover { text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 4px; }
.story-summary { margin: 0; padding-bottom: 24px; color: var(--ink-soft); font-size: .875rem; line-height: 1.75; }
.story-footer { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; padding-top: 15px; border-top: 1px solid var(--border); color: var(--muted); font-size: .625rem; line-height: 1.55; font-weight: 600; text-transform: uppercase; }
.story-sources { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.story-footer time { flex: 0 0 auto; white-space: nowrap; }
.reader-loading, .reader-empty { grid-column: 1 / -1; padding: 64px 24px; background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius-md); color: var(--muted); text-align: center; }
.reader-empty-wrap { display: block; }
.reader-empty { max-width: 680px; margin: 72px auto; }
.reader-empty h2 { margin: 18px 0 8px; color: var(--ink); font-size: 1.25rem; }
.reader-empty p { margin: 0; font-size: .875rem; line-height: 1.7; }
.empty-mark { display: block; width: 48px; height: 7px; margin: 0 auto; background: var(--accent); }

/* Shared buttons and inputs */
.button { display: inline-flex; min-height: 44px; align-items: center; justify-content: center; padding: 0 16px; border: 1px solid transparent; border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); font-size: .75rem; font-weight: 800; cursor: pointer; transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease; }
.button:hover:not(:disabled) { border-color: var(--border-strong); }
.button:active:not(:disabled) { filter: brightness(.96); }
.button:disabled { opacity: .48; cursor: not-allowed; }
.button-primary { background: var(--accent); border-color: var(--accent); }
.button-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.button-secondary { border-color: var(--border-strong); }
.button-quiet { min-height: 38px; padding-inline: 12px; background: transparent; }
.button-block { width: 100%; }
input[type="text"], input[type="password"], input[type="number"], input[type="time"] { width: 100%; min-height: 44px; scroll-margin-top: 84px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); font-size: .875rem; }
input:disabled { background: var(--surface-subtle); color: var(--muted); }
input[type="checkbox"], input[type="range"] { accent-color: var(--focus); }
.field { min-width: 0; }
.field > label { display: block; margin-bottom: 7px; font-size: .76rem; font-weight: 700; }
.field-help { margin: 7px 0 0; color: var(--muted); font-size: .68rem; line-height: 1.55; }
.field-error { min-height: 1em; margin: 6px 0 0; color: var(--danger); font-size: .7rem; line-height: 1.45; }
.input-suffix { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
.input-suffix input { grid-area: 1 / 1 / 2 / 3; padding-right: 54px; }
.input-suffix span { grid-area: 1 / 2; z-index: 1; padding-right: 12px; color: var(--muted); font-size: .7rem; pointer-events: none; }

/* Authentication */
.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.auth-shell { width: min(440px, 100%); }
.auth-back { margin-bottom: 16px; }
.auth-card { padding: 34px; background: var(--surface); border: 1px solid var(--border); border-top: 7px solid var(--accent); border-radius: var(--radius-md); box-shadow: var(--shadow-float); }
.auth-card h1 { margin: 0; font-size: 1.65rem; letter-spacing: -.035em; }
.auth-card > p { margin: 10px 0 26px; color: var(--muted); font-size: .8rem; line-height: 1.65; }
.auth-card .field { margin-bottom: 12px; }
.form-message { min-height: 20px; color: var(--danger); font-size: .75rem; line-height: 1.5; }

/* Dashboard shell */
.dashboard-topbar { position: sticky; top: 0; z-index: 20; background: rgba(245, 243, 238, .96); border-bottom: 1px solid var(--border); }
.dashboard-topbar-inner { display: flex; width: min(1320px, 100%); min-height: 64px; margin: 0 auto; padding: 0 24px; align-items: center; justify-content: space-between; gap: 24px; }
.brand { display: inline-flex; min-height: 44px; align-items: center; gap: 10px; color: var(--ink); font-size: .86rem; font-weight: 800; text-decoration: none; }
.brand-mark { width: 6px; height: 24px; background: var(--accent); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.dashboard-layout { display: grid; width: min(1320px, 100%); margin: 0 auto; grid-template-columns: 180px minmax(0, 1fr); gap: 38px; padding: 28px 24px 80px; }
.section-nav { position: sticky; top: 92px; align-self: start; display: grid; gap: 2px; }
.section-nav a { display: flex; min-height: 40px; align-items: center; padding: 0 10px; border-left: 3px solid transparent; color: var(--muted); font-size: .72rem; font-weight: 600; text-decoration: none; }
.section-nav a:hover, .section-nav a:focus-visible { border-left-color: var(--accent); background: var(--surface); color: var(--ink); }
.dashboard-main { min-width: 0; }
.dashboard-hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin: 10px 0 28px; }
.dashboard-hero h1 { margin: 0; font-size: clamp(1.75rem, 3vw, 2.35rem); line-height: 1.18; letter-spacing: -.045em; text-wrap: balance; }
.section-intro { max-width: 680px; margin: 9px 0 0; color: var(--muted); font-size: .82rem; line-height: 1.65; }
.analyze-button { flex: 0 0 auto; min-width: 150px; }
.notice { margin-bottom: 20px; padding: 12px 14px; border: 1px solid; border-radius: var(--radius-sm); font-size: .76rem; line-height: 1.55; }
.notice-success { background: var(--success-soft); border-color: #afd8bf; color: #125a39; }
.notice-error { background: var(--danger-soft); border-color: #e5bab5; color: var(--danger); }
.overview-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.metric-card { min-width: 0; padding: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); }
.metric-card-emphasis { border-top: 4px solid var(--accent); padding-top: 15px; }
.metric-card p { margin: 0 0 12px; color: var(--muted); font-size: .66rem; font-weight: 700; }
.metric-card strong { display: flex; min-height: 27px; align-items: center; gap: 8px; font-size: 1.05rem; line-height: 1.4; font-weight: 750; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metric-card small { display: block; margin-top: 6px; color: var(--muted); font-size: .62rem; line-height: 1.45; }
.panel { scroll-margin-top: 84px; margin-bottom: 18px; padding: 24px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.panel-heading h2 { margin: 0; font-size: 1.05rem; line-height: 1.35; letter-spacing: -.02em; }
.panel-heading p:not(.eyebrow) { max-width: 670px; margin: 7px 0 0; color: var(--muted); font-size: .72rem; line-height: 1.6; }
.split-heading { align-items: center; }
.pipeline-panel { padding-bottom: 20px; }
.pipeline-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.pipeline-grid div { min-width: 0; padding: 13px 15px; border-right: 1px solid var(--border); }
.pipeline-grid div:last-child { border-right: 0; }
.pipeline-grid span { display: block; color: var(--muted); font-size: .62rem; }
.pipeline-grid strong { display: block; margin-top: 5px; font-size: 1.08rem; font-variant-numeric: tabular-nums; }
.latest-error { padding: 8px 10px; background: var(--danger-soft); border-radius: var(--radius-sm); color: var(--danger) !important; }
.form-grid { display: grid; gap: 20px; }
.form-grid-four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.compact-form-grid { width: min(240px, 100%); }
.checkbox-field { display: flex; align-items: flex-start; padding-top: 21px; }
.check-row { display: flex !important; min-height: 44px; margin: 0 !important; align-items: flex-start; gap: 10px; cursor: pointer; }
.check-row input { width: 18px; height: 18px; margin: 2px 0 0; flex: 0 0 auto; }
.check-row b, .check-row small { display: block; }
.check-row small { margin-top: 4px; color: var(--muted); font-size: .65rem; font-weight: 400; line-height: 1.45; }
.switch { display: inline-flex; min-height: 44px; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { position: relative; width: 40px; height: 23px; border: 1px solid var(--border-strong); border-radius: 999px; background: #ddd9d0; transition: background-color 160ms ease; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 15px; height: 15px; border-radius: 50%; background: var(--surface); transition: transform 160ms ease; }
.switch input:checked + span { background: var(--ink); border-color: var(--ink); }
.switch input:checked + span::after { transform: translateX(17px); background: var(--accent); }
.switch input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 3px; }
.switch b { font-size: .72rem; }
.priority-list { min-height: 290px; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.priority-row { display: grid; grid-template-columns: 180px minmax(100px, 1fr) 76px; min-height: 58px; align-items: center; gap: 20px; padding: 8px 14px; border-bottom: 1px solid var(--border); }
.priority-row:last-child { border-bottom: 0; }
.priority-name { display: flex; min-width: 0; align-items: center; gap: 10px; font-size: .75rem; }
.priority-name span { display: grid; width: 25px; height: 25px; place-items: center; background: var(--accent-soft); border-radius: 50%; color: #665000; font-size: .62rem; font-weight: 800; }
.priority-row input[type="number"] { min-height: 38px; text-align: right; font-variant-numeric: tabular-nums; }
.category-grid { display: grid; min-height: 106px; margin: 0; padding: 0; border: 0; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.category-option { display: flex; min-height: 48px; align-items: center; gap: 10px; padding: 0 12px; background: var(--surface-subtle); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: .75rem; font-weight: 600; cursor: pointer; }
.category-option:has(input:checked) { background: var(--accent-soft); border-color: #d9bc50; }
.category-option input { width: 18px; height: 18px; }
.error-summary { margin-bottom: 18px; padding: 18px 20px; background: var(--danger-soft); border: 1px solid #e5bab5; border-left: 5px solid var(--danger); border-radius: var(--radius-sm); }
.error-summary h2 { margin: 0 0 8px; font-size: .9rem; }
.error-summary ul { margin: 0; padding-left: 18px; color: var(--danger); font-size: .72rem; line-height: 1.7; }
.error-summary a { text-underline-offset: 3px; }
.save-bar { position: sticky; bottom: 12px; z-index: 10; display: flex; min-height: 68px; margin: 22px 0 34px; padding: 11px 13px 11px 18px; align-items: center; justify-content: space-between; gap: 20px; background: rgba(255, 255, 255, .97); border: 1px solid var(--border-strong); border-radius: var(--radius-md); box-shadow: var(--shadow-float); }
.save-bar p { margin: 0; color: var(--muted); font-size: .68rem; }
.save-bar > div { display: flex; gap: 9px; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; min-width: 680px; border-collapse: collapse; font-size: .7rem; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
thead th { padding-top: 8px; color: var(--muted); font-size: .62rem; font-weight: 700; white-space: nowrap; }
tbody th { font-weight: 650; }
tbody tr:last-child th, tbody tr:last-child td { border-bottom: 0; }
.numeric { font-variant-numeric: tabular-nums; }
.table-status { display: inline-flex; align-items: center; gap: 7px; font-weight: 650; white-space: nowrap; }
.status-dot { display: inline-block; width: 8px; height: 8px; flex: 0 0 auto; border: 2px solid currentColor; border-radius: 50%; }
.status-idle { color: var(--muted); }
.status-running { color: var(--info); }
.status-success { color: var(--success); }
.status-failed { color: var(--danger); }
.status-running .status-dot, .status-dot.status-running { background: var(--info-soft); animation: pulse 1.6s ease-in-out infinite; }
.status-success .status-dot, .status-dot.status-success { background: var(--success); }
.status-failed .status-dot, .status-dot.status-failed { background: var(--danger); }
.run-error { max-width: 260px; color: var(--danger); overflow-wrap: anywhere; }
.table-empty { padding: 30px; color: var(--muted); text-align: center; }

@keyframes pulse { 50% { opacity: .4; } }

@media (max-width: 1100px) {
  .dashboard-layout { grid-template-columns: 1fr; gap: 18px; }
  .section-nav { position: static; display: flex; margin: -8px 0 4px; padding-bottom: 8px; overflow-x: auto; }
  .section-nav a { flex: 0 0 auto; border-left: 0; border-bottom: 3px solid transparent; }
  .section-nav a:hover, .section-nav a:focus-visible { border-left-color: transparent; border-bottom-color: var(--accent); }
  .form-grid-four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pipeline-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .pipeline-grid div:nth-child(3) { border-right: 0; }
  .pipeline-grid div:nth-child(-n+3) { border-bottom: 1px solid var(--border); }
}

@media (max-width: 800px) {
  .reader-page { padding: 24px 16px 52px; }
  .reader-header { align-items: flex-start; margin-bottom: 22px; }
  .reader-admin-link { margin-top: -8px; }
  .story-grid { grid-template-columns: 1fr; gap: 18px; }
  .story-content { min-height: 285px; padding: 19px; }
  .story-headline { font-size: 1.22rem; line-height: 1.4; }
  .story-summary { font-size: 1rem; line-height: 1.7; }
  .dashboard-topbar-inner, .dashboard-layout { padding-left: 16px; padding-right: 16px; }
  .overview-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .category-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .reader-header { display: block; }
  .reader-admin-link { margin: 10px 0 0 20px; }
  .title-mark { height: 27px; }
  .reader-header h1 { font-size: 1.48rem; }
  .reader-subtitle { font-size: .7rem; }
  .story-content { min-height: 0; }
  .story-footer { align-items: flex-start; flex-direction: column; gap: 5px; }
  .story-sources { white-space: normal; }
  .topbar-actions .text-link { display: none; }
  .dashboard-layout { padding-top: 18px; }
  .dashboard-hero { align-items: stretch; flex-direction: column; }
  .analyze-button { width: 100%; }
  .overview-grid, .form-grid-four, .category-grid { grid-template-columns: 1fr; }
  .panel { padding: 19px 16px; }
  .split-heading { align-items: flex-start; flex-direction: column; }
  .pipeline-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pipeline-grid div { border-bottom: 1px solid var(--border); }
  .pipeline-grid div:nth-child(2n) { border-right: 0; }
  .pipeline-grid div:nth-last-child(-n+2) { border-bottom: 0; }
  .priority-row { grid-template-columns: 1fr 70px; gap: 8px 14px; padding-block: 12px; }
  .priority-name { grid-column: 1 / -1; }
  .save-bar { position: static; align-items: stretch; flex-direction: column; padding: 14px; }
  .save-bar > div { display: grid; }
  .save-bar .button { width: 100%; }
  .auth-card { padding: 28px 22px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
