:root {
  --bg: #f5f5f2;
  --surface: #ffffff;
  --text: #17181a;
  --muted: #62656b;
  --border: #e2e2dd;
  --accent: #15803d;
  --accent-soft: #dcfce7;
  --danger: #b91c1c;

  --c-finance: #1d4ed8;
  --c-geopolitics: #b45309;
  --c-ai: #7c3aed;
  --c-commodities: #a16207;
  --c-stocks: #15803d;

  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101113;
    --surface: #18191c;
    --text: #ececea;
    --muted: #9a9ca1;
    --border: #2a2c30;
    --accent: #4ade80;
    --accent-soft: #14301f;
    --danger: #f87171;
    --c-finance: #93b4ff;
    --c-geopolitics: #fbbf6b;
    --c-ai: #c4a5ff;
    --c-commodities: #facc15;
    --c-stocks: #4ade80;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #101113;
  --surface: #18191c;
  --text: #ececea;
  --muted: #9a9ca1;
  --border: #2a2c30;
  --accent: #4ade80;
  --accent-soft: #14301f;
  --danger: #f87171;
  --c-finance: #93b4ff;
  --c-geopolitics: #fbbf6b;
  --c-ai: #c4a5ff;
  --c-commodities: #facc15;
  --c-stocks: #4ade80;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

/* ---------- Barra in alto ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 8px; color: var(--accent); }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: -0.01em; color: var(--text); }
.updated { margin: 0 0 0 auto; color: var(--muted); font-size: 13px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

/* ---------- Filtri ---------- */

.container { max-width: 1180px; margin: 0 auto; padding: 16px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] .count { color: inherit; opacity: .7; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }

.search {
  flex: 1 1 220px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
}
.search input {
  flex: 1;
  min-width: 0;
  padding: 8px 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
}

select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

/* ---------- Notizie ---------- */

.feed {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 270px), 1fr));
  gap: 14px;
}

.story {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

/* Card grande in apertura: copertina accanto al testo su schermi larghi */
.story--lead { grid-column: 1 / -1; }
.story--lead .story-title { font-size: 21px; }
@media (min-width: 760px) {
  .story--lead { flex-direction: row; }
  .story--lead .cover-link { flex: 0 0 56%; }
  .story--lead .cover { height: 100%; min-height: 280px; }
  .story--lead .story-body { padding: 20px 22px; }
}

.cover-link { display: block; text-decoration: none; }
.cover {
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--border);
}
.cover img { display: block; width: 100%; height: 100%; object-fit: cover; }

.cover--empty {
  display: grid;
  place-items: center;
  padding: 16px;
  --tag-color: var(--muted);
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--tag-color) 28%, var(--surface)),
    color-mix(in srgb, var(--tag-color) 8%, var(--surface)));
}
.cover--empty span {
  color: var(--tag-color);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-align: center;
}
.cover--finance { --tag-color: var(--c-finance); }
.cover--geopolitics { --tag-color: var(--c-geopolitics); }
.cover--ai { --tag-color: var(--c-ai); }
.cover--commodities { --tag-color: var(--c-commodities); }
.cover--stocks { --tag-color: var(--c-stocks); }

.story-body { display: flex; flex-direction: column; gap: 6px; padding: 12px 14px 14px; }

.story-tags { display: flex; flex-wrap: wrap; gap: 6px; }

.story-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  margin-top: auto;
  color: var(--muted);
  font-size: 13px;
}
.story-meta .publisher { color: var(--text); font-weight: 600; }

.tag {
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--tag-color);
  background: color-mix(in srgb, var(--tag-color) 14%, transparent);
}
.tag--finance { --tag-color: var(--c-finance); }
.tag--geopolitics { --tag-color: var(--c-geopolitics); }
.tag--ai { --tag-color: var(--c-ai); }
.tag--commodities { --tag-color: var(--c-commodities); }
.tag--stocks { --tag-color: var(--c-stocks); }

.story-title { margin: 0; font-size: 16.5px; line-height: 1.35; font-weight: 650; }
.story-title a { text-decoration: none; }
.story-title a:hover { text-decoration: underline; }
.story-title a:visited { color: var(--muted); }

.story-excerpt { margin: 0; color: var(--muted); font-size: 14px; }

.story-sources { margin: 0; font-size: 13px; color: var(--muted); }
.story-sources .badge {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 7px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.story-sources a { color: var(--text); }

.empty { grid-column: 1 / -1; padding: 40px 0; text-align: center; color: var(--muted); }

.more-wrap { display: flex; justify-content: center; margin: 16px 0; }
.ghost-btn {
  padding: 8px 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

/* ---------- Fonti ---------- */

.sources-footer { margin-top: 32px; color: var(--muted); font-size: 13px; }
.sources-footer summary { cursor: pointer; color: var(--text); font-weight: 600; }
.sources-table { width: 100%; margin-top: 12px; border-collapse: collapse; }
.sources-table th, .sources-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.sources-table td:nth-child(4) { font-variant-numeric: tabular-nums; }
.status-ok { color: var(--accent); }
.status-err { color: var(--danger); }
.status-wait { color: var(--muted); }
.sources-note { margin-top: 16px; }

@media (max-width: 640px) {
  .updated { display: none; }
  .brand { margin-right: auto; }
  .sources-table th:nth-child(2), .sources-table td:nth-child(2),
  .sources-table th:nth-child(3), .sources-table td:nth-child(3) { display: none; }
  select { flex: 1 1 40%; }
}
