/* ================================================
   news.css — News Design System
   ================================================ */

/* ------------------------------------------------
   Font Faces
   ------------------------------------------------ */

@font-face {
  font-family: 'Source Serif 4';
  src: url('fonts/source-serif-4/source-serif-4-latin.woff2') format('woff2');
  font-style: normal;
  font-weight: 300 900;
  font-display: swap;
}

@font-face {
  font-family: 'Source Serif 4';
  src: url('fonts/source-serif-4/source-serif-4-latin-italic.woff2') format('woff2');
  font-style: italic;
  font-weight: 300 900;
  font-display: swap;
}

@font-face {
  font-family: 'IBM Plex Sans';
  src: url('fonts/ibm-plex-sans/ibm-plex-sans-latin.woff2') format('woff2');
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
}

@font-face {
  font-family: 'IBM Plex Sans';
  src: url('fonts/ibm-plex-sans/ibm-plex-sans-400-italic.woff2') format('woff2');
  font-style: italic;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: 'IBM Plex Mono';
  src: url('fonts/ibm-plex-mono/ibm-plex-mono-400.woff2') format('woff2');
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: 'IBM Plex Mono';
  src: url('fonts/ibm-plex-mono/ibm-plex-mono-500.woff2') format('woff2');
  font-style: normal;
  font-weight: 500;
  font-display: swap;
}

/* ------------------------------------------------
   Design Tokens — Light Theme
   ------------------------------------------------ */

:root {
  /* Surfaces */
  --bg: #fcfbf9;
  --surface: #ffffff;

  /* Text */
  --text: #1a1a1a;
  --text-muted: #6b6b6b;
  --text-faint: #a0a0a0;

  /* Borders */
  --border: #e5e5e5;
  --border-strong: #cccccc;

  /* Accent */
  --accent: #1a365d;
  --accent-hover: #142a4a;

  /* Semantic */
  --red: #b91c1c;
  --green: #166534;
  --amber: #b45309;

  /* Typography */
  --font-headline: 'Source Serif 4', Georgia, serif;
  --font-body: 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

  /* Type Scale */
  --text-xs:   0.75rem;
  --text-sm:   0.85rem;
  --text-base: 1rem;
  --text-lg:   1.2rem;
  --text-xl:   1.4rem;
  --text-2xl:  1.6rem;
  --text-3xl:  2rem;
  --text-4xl:  2.5rem;

  /* Spacing */
  --sp-1:  0.25rem;
  --sp-2:  0.5rem;
  --sp-3:  0.75rem;
  --sp-4:  1rem;
  --sp-5:  1.25rem;
  --sp-6:  1.5rem;
  --sp-7:  1.75rem;
  --sp-8:  2rem;
  --sp-9:  2.25rem;
  --sp-10: 2.5rem;
  --sp-11: 2.75rem;
  --sp-12: 3rem;
  --sp-13: 3.25rem;
  --sp-14: 3.5rem;
  --sp-15: 3.75rem;
  --sp-16: 4rem;

  /* Layout */
  --max-width:      42rem;
  --max-width-wide: 56rem;
  --radius:    3px;
  --radius-lg: 4px;
}

/* ------------------------------------------------
   Design Tokens — Dark Theme
   ------------------------------------------------ */

:root[data-theme="dark"] {
  --bg: #141414;
  --surface: #1c1c1c;

  --text: #e8e6e1;
  --text-muted: #8a8a8a;
  --text-faint: #505050;

  --border: #2a2a2a;
  --border-strong: #3a3a3a;

  --accent: #5b8cbd;
  --accent-hover: #4a7bac;

  --red: #dc4444;
  --green: #34d399;
  --amber: #f59e0b;
}

/* ------------------------------------------------
   Responsive Scaling
   ------------------------------------------------ */

html {
  font-size: 100%;
}

@media (min-width: 768px) {
  html {
    font-size: 106.25%;
  }
}

@media (min-width: 1200px) {
  html {
    font-size: 112.5%;
  }
}

/* ------------------------------------------------
   Reset
   ------------------------------------------------ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0;
}

p {
  margin: 0;
}

img, svg {
  display: block;
  max-width: 100%;
}

a {
  color: inherit;
}

/* ------------------------------------------------
   Theme Transition
   ------------------------------------------------ */

.theme-transitioning,
.theme-transitioning *,
.theme-transitioning *::before,
.theme-transitioning *::after {
  transition:
    background-color 220ms ease,
    color 220ms ease,
    border-color 220ms ease,
    box-shadow 220ms ease !important;
}

/* ------------------------------------------------
   Animations
   ------------------------------------------------ */

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

/* ------------------------------------------------
   Layout
   ------------------------------------------------ */

.container {
  max-width: var(--max-width);
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--sp-6);
  padding-right: var(--sp-6);
}

.container--wide {
  max-width: var(--max-width-wide);
}

/* ------------------------------------------------
   Typography Utilities
   ------------------------------------------------ */

.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }
.text-accent { color: var(--accent); }

.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }

.label {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.mono { font-family: var(--font-mono); }

.display {
  font-family: var(--font-headline);
  font-weight: 600;
}

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

/* ------------------------------------------------
   Site Header
   ------------------------------------------------ */

.site-header {
  border-bottom: 1px solid var(--border-strong);
  padding: var(--sp-5) 0;
}

.site-header .container {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.brand {
  font-family: var(--font-body);
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.site-header-meta {
  font-size: var(--text-sm);
  font-weight: 300;
  color: var(--text-muted);
}

.site-header-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.btn-theme {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-1) var(--sp-3);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.btn-theme:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-theme:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
}

.btn-theme .theme-label-light { display: inline; }
.btn-theme .theme-label-dark  { display: none; }

:root[data-theme="dark"] .btn-theme .theme-label-light { display: none; }
:root[data-theme="dark"] .btn-theme .theme-label-dark  { display: inline; }

/* ------------------------------------------------
   Story Component
   ------------------------------------------------ */

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

.story {
  padding: var(--sp-5) 0;
  border-top: 1px solid var(--border);
}

.story:first-child {
  border-top: none;
  padding-top: 0;
}

.story-sources {
  font-size: var(--text-sm);
  color: var(--text-faint);
  display: flex;
  gap: 0.15rem;
  flex-wrap: wrap;
  margin-bottom: var(--sp-1);
}

.story-sources a {
  color: var(--text-faint);
  text-decoration: none;
  transition: color 0.15s;
}

.story-sources a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.story-sources .sep {
  color: var(--border-strong);
}

.story-headline {
  font-family: var(--font-headline);
  font-size: var(--text-lg);
  line-height: 1.3;
  font-weight: 600;
  margin-bottom: var(--sp-2);
}

.story-headline a {
  color: var(--text);
  text-decoration: none;
  transition: color 0.15s;
}

.story-headline a:hover {
  color: var(--accent);
}

.story-summary {
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text-muted);
  max-width: 40em;
}

/* ------------------------------------------------
   Edition Navigation
   ------------------------------------------------ */

.edition-nav {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-top: var(--sp-8);
  margin-top: var(--sp-8);
  border-top: 1px solid var(--border);
}

.edition-nav a {
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}

.edition-nav a:hover {
  color: var(--accent);
}

/* ------------------------------------------------
   Page Header (Desk)
   ------------------------------------------------ */

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--sp-8);
}

.page-header-title {
  font-family: var(--font-body);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text);
}

.page-header-actions {
  display: flex;
  gap: var(--sp-3);
}

/* ------------------------------------------------
   Buttons
   ------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1;
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
}

.btn:disabled,
.btn.htmx-request {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.btn--primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn--secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn--secondary:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--surface);
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}

.btn--ghost:hover:not(:disabled) {
  background: var(--surface);
  color: var(--text);
}

.btn--danger {
  background: transparent;
  color: var(--red);
  border-color: var(--red);
}

.btn--danger:hover:not(:disabled) {
  background: var(--red);
  color: #ffffff;
}

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

.btn--lg {
  font-size: var(--text-base);
  padding: var(--sp-3) var(--sp-6);
}

/* ------------------------------------------------
   Status Badges
   ------------------------------------------------ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.badge::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.badge--running { color: var(--green); }
.badge--running::before {
  background: var(--green);
  animation: pulse 2.6s ease-in-out infinite;
}

.badge--stopped { color: var(--amber); }
.badge--stopped::before {
  background: var(--amber);
}

.badge--error { color: var(--red); }
.badge--error::before {
  background: var(--red);
}

/* ------------------------------------------------
   Tables
   ------------------------------------------------ */

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  text-align: left;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border-strong);
}

tbody td {
  font-size: var(--text-sm);
  color: var(--text);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:hover {
  background: color-mix(in srgb, var(--accent) 3%, transparent);
}

tbody tr[data-href] {
  cursor: pointer;
}

/* ------------------------------------------------
   Cards
   ------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
}

.card--sm { padding: var(--sp-4); }

.card--flat {
  background: var(--bg);
}

/* ------------------------------------------------
   Form Components
   ------------------------------------------------ */

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.form-label,
label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.form-hint {
  font-size: var(--text-sm);
  color: var(--text-faint);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="url"],
select,
textarea {
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-2) var(--sp-3);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
}

input.is-error {
  border-color: var(--red);
}

/* ------------------------------------------------
   Notices
   ------------------------------------------------ */

.notice {
  padding: var(--sp-4) var(--sp-5);
  border-left: 3px solid var(--border-strong);
  background: var(--surface);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: var(--text-sm);
}

.notice--error   { border-left-color: var(--red); }
.notice--warning { border-left-color: var(--amber); }
.notice--success { border-left-color: var(--green); }
.notice--info    { border-left-color: var(--accent); }

/* ------------------------------------------------
   Empty State
   ------------------------------------------------ */

.empty-state {
  text-align: center;
  padding: var(--sp-16) var(--sp-6);
}

.empty-state-title {
  font-family: var(--font-body);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--sp-2);
}

.empty-state-body {
  font-size: var(--text-base);
  color: var(--text-muted);
}

/* ------------------------------------------------
   Site Nav
   ------------------------------------------------ */

.site-nav {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: var(--sp-4);
}

.site-nav a {
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}

.site-nav a:hover,
.site-nav a.active {
  color: var(--text);
}

.site-nav a.active {
  text-decoration: underline;
  text-underline-offset: 0.25em;
}

/* ------------------------------------------------
   Edition Header
   ------------------------------------------------ */

.edition-header {
  padding: var(--sp-8) 0 var(--sp-6);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-2);
}

.edition-label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: var(--sp-2);
}

.edition-title {
  font-family: var(--font-body);
  font-size: var(--text-3xl);
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin-bottom: var(--sp-2);
}

.edition-meta {
  font-size: var(--text-sm);
  font-weight: 300;
  color: var(--text-muted);
}

/* ------------------------------------------------
   Story Entrance Animation
   ------------------------------------------------ */

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.story {
  animation: rise 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.story:nth-child(1)  { animation-delay: 0.03s; }
.story:nth-child(2)  { animation-delay: 0.07s; }
.story:nth-child(3)  { animation-delay: 0.11s; }
.story:nth-child(4)  { animation-delay: 0.15s; }
.story:nth-child(5)  { animation-delay: 0.19s; }
.story:nth-child(6)  { animation-delay: 0.23s; }
.story:nth-child(7)  { animation-delay: 0.27s; }
.story:nth-child(8)  { animation-delay: 0.31s; }
.story:nth-child(9)  { animation-delay: 0.35s; }
.story:nth-child(10) { animation-delay: 0.39s; }

/* ------------------------------------------------
   Footer
   ------------------------------------------------ */

.site-footer {
  border-top: 1px solid var(--border);
  padding: var(--sp-8) 0;
  margin-top: var(--sp-12);
}

.site-footer .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.footer-credit {
  font-size: var(--text-sm);
  color: var(--text-faint);
}

.footer-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
}

/* ------------------------------------------------
   Site Main
   ------------------------------------------------ */

.site-main {
  padding-top: var(--sp-8);
  padding-bottom: var(--sp-16);
}

/* ------------------------------------------------
   Cluster Component
   ------------------------------------------------ */

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

.cluster {
  padding: var(--sp-5) 0;
  border-top: 1px solid var(--border);
}

.cluster:first-child {
  border-top: none;
  padding-top: 0;
}

.cluster-headline {
  font-family: var(--font-headline);
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
  margin-bottom: var(--sp-3);
}

.cluster-sources {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.cluster-source a {
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}

.cluster-source a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.cluster-source .source-name {
  font-weight: 500;
  color: var(--text-faint);
}

/* ------------------------------------------------
   Filter Bar
   ------------------------------------------------ */

.filter-bar {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
  margin-bottom: var(--sp-6);
}

.filter-btn {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 500;
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
  text-decoration: none;
}

.filter-btn:hover {
  background: var(--surface);
  color: var(--text);
}

.filter-btn.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

/* ------------------------------------------------
   Article Table
   ------------------------------------------------ */

.article-table td a {
  color: var(--text);
  text-decoration: none;
}

.article-table td a:hover {
  text-decoration: underline;
}

/* ------------------------------------------------
   Story Time
   ------------------------------------------------ */

.story-time {
  color: var(--text-faint);
  margin-left: var(--sp-2);
}
