/* Klartext — News Ticker, v0.3 */

/* ─────────────────────────  THEME TOKENS  ───────────────────────── */

:root[data-theme="dark"], :root {
  --bg: #0d1117;
  --bg-elev: #161b22;
  --bg-elev-2: #1c2330;
  --bg-hover: #1f2632;
  --border: #30363d;
  --border-strong: #444c56;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --text-mute: #6e7681;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --accent-soft: rgba(88, 166, 255, 0.12);
  --new: #2ea043;
  --new-soft: rgba(46, 160, 67, 0.09);
  --new-border: rgba(46, 160, 67, 0.28);
  --warn: #f0883e;
  --important: #f85149;
  --important-soft: rgba(248, 81, 73, 0.18);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-strong: 0 8px 32px rgba(0, 0, 0, 0.45);
  --region-world: #58a6ff;
  --region-usa: #f97583;
  --region-asia: #a371f7;
  --region-africa: #d29922;
  --region-latam: #56d364;
  --region-tech: #79c0ff;
  --region-germany: #8b949e;
  --region-europe: #8b949e;
}

:root[data-theme="light"] {
  --bg: #f6f8fa;
  --bg-elev: #ffffff;
  --bg-elev-2: #f0f3f6;
  --bg-hover: #eaeef2;
  --border: #d0d7de;
  --border-strong: #afb8c1;
  --text: #1f2328;
  --text-dim: #59636e;
  --text-mute: #818b98;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --accent-soft: rgba(9, 105, 218, 0.10);
  --new: #1a7f37;
  --new-soft: rgba(26, 127, 55, 0.10);
  --new-border: rgba(26, 127, 55, 0.32);
  --warn: #bc4c00;
  --important: #cf222e;
  --important-soft: rgba(207, 34, 46, 0.14);
  --shadow: 0 4px 16px rgba(140, 149, 159, 0.25);
  --shadow-strong: 0 8px 32px rgba(140, 149, 159, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

button { font-family: inherit; }

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

/* ─────────────────────────  TOPBAR  ───────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 52px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
}

.brand-logo {
  font-size: 20px;
  filter: drop-shadow(0 0 4px rgba(88, 166, 255, 0.5));
}

.brand-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  background: linear-gradient(135deg, var(--accent), #79b8ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.search-wrap {
  flex: 1;
  max-width: 480px;
}

#search {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

#search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border-strong);
}

.status {
  font-size: 11px;
  color: var(--text-dim);
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg-hover);
  white-space: nowrap;
}

.status.live { color: var(--new); }
.status.error { color: var(--warn); }

.topbar-only-mobile { display: none; }

/* ─────────────────────────  LAYOUT GRID  ───────────────────────── */

.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 0;
  min-height: calc(100vh - 52px - 28px);
}

.layout.with-detail {
  grid-template-columns: 240px 1fr 420px;
}

/* ─────────────────────────  SIDEBAR  ───────────────────────── */

.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 16px 14px;
  overflow-y: auto;
  height: calc(100vh - 52px);
  position: sticky;
  top: 52px;
}

.sidebar-section {
  margin-bottom: 22px;
}

.sidebar-section h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-mute);
  margin: 0 0 8px;
  font-weight: 600;
}

.profile-buttons,
.filter-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.profile-buttons button,
.filter-list button {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.15s;
}

.profile-buttons button:hover,
.filter-list button:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.profile-buttons button.active,
.filter-list button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  padding: 4px 0;
}

.toggle input { cursor: pointer; }

.action-btn {
  display: block;
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  margin-bottom: 6px;
  transition: background 0.15s;
}

.action-btn:hover { background: var(--accent-hover); }

.action-btn-light {
  display: block;
  width: 100%;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.action-btn-light:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.sidebar-stats {
  margin-top: auto;
  font-size: 11px;
  color: var(--text-mute);
  line-height: 1.5;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

#stats { white-space: pre-line; }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 39;
}
.sidebar-backdrop.hidden { display: none; }

/* ─────────────────────────  STREAM  ───────────────────────── */

.stream {
  padding: 14px 18px 80px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

#ticker {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#ticker:focus { outline: none; }

.time-group {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-mute);
  font-weight: 600;
  margin: 14px 0 4px;
  padding: 4px 6px 4px 12px;
  border-left: 2px solid var(--border-strong);
  position: sticky;
  top: 52px;
  background: var(--bg);
  z-index: 5;
}

.time-group:first-child { margin-top: 4px; }

.live-banner {
  position: sticky;
  top: 52px;
  z-index: 6;
  background: var(--accent);
  color: #fff;
  padding: 8px 14px;
  border-radius: 6px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  box-shadow: var(--shadow);
  animation: slide-down 0.3s ease-out;
}
.live-banner.hidden { display: none; }
.live-banner button {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.live-banner button:hover { background: rgba(255, 255, 255, 0.28); }

@keyframes slide-down {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ─────────────────────────  ARTICLE CARD  ───────────────────────── */

.article {
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 3px solid var(--region-world);
  border-radius: 8px;
  padding: 12px 14px 12px 14px;
  display: grid;
  grid-template-columns: 88px 1fr;
  grid-template-rows: auto auto auto;
  grid-template-areas:
    "thumb title"
    "thumb summary"
    "thumb meta";
  gap: 4px 14px;
  align-items: start;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.article:hover {
  border-color: var(--border-strong);
  background: var(--bg-hover);
  transform: translateX(1px);
}

.article.no-thumb {
  grid-template-columns: 1fr;
  grid-template-areas:
    "title"
    "summary"
    "meta";
}

.article.focused {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.article.read {
  opacity: 0.65;
}

.article.read .title a { color: var(--text-dim); }

.article.new {
  animation: flash 1.4s ease-out;
}

@keyframes flash {
  0%   { background: rgba(46, 160, 67, 0.20); }
  100% { background: var(--bg-elev); }
}

.article.showing-de {
  background: var(--new-soft);
  border-color: var(--new-border);
}

.article.showing-de:hover {
  background: rgba(46, 160, 67, 0.16);
  border-color: rgba(46, 160, 67, 0.55);
}

/* "Gelesen": grauer Hintergrund, persistiert via localStorage. Wins over showing-de tint. */
.article.read,
.article.read.showing-de {
  background: var(--bg-elev-2);
}

.article.read:hover,
.article.read.showing-de:hover {
  background: var(--bg-hover);
  opacity: 0.85;
}

/* Region color via left border-strip */
.article.region-world   { border-left-color: var(--region-world); }
.article.region-usa     { border-left-color: var(--region-usa); }
.article.region-asia    { border-left-color: var(--region-asia); }
.article.region-africa  { border-left-color: var(--region-africa); }
.article.region-latam   { border-left-color: var(--region-latam); }
.article.region-tech    { border-left-color: var(--region-tech); }
.article.region-germany { border-left-color: var(--region-germany); }
.article.region-europe  { border-left-color: var(--region-europe); }

/* Importance highlights */
.article.important-medium {
  border-color: var(--warn);
  box-shadow: 0 0 0 1px rgba(240, 136, 62, 0.22);
}

.article.important-high {
  border-color: var(--important);
  border-width: 1px;
  box-shadow: 0 0 0 1px var(--important), 0 0 16px var(--important-soft);
}

.article.important-high:hover {
  box-shadow: 0 0 0 1px var(--important), 0 0 22px rgba(248, 81, 73, 0.32);
}

.article.important-high.showing-de {
  border-color: var(--important);
}

.imp-icon {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 11px;
  line-height: 1;
  filter: drop-shadow(0 0 3px rgba(0, 0, 0, 0.5));
  pointer-events: none;
}

.thumb {
  grid-area: thumb;
  width: 88px;
  height: 88px;
  border-radius: 6px;
  background: var(--bg-elev-2);
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-mute);
  font-size: 22px;
}

.thumb.broken::after {
  content: "📰";
  opacity: 0.4;
}

.title {
  grid-area: title;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  margin: 0;
  padding-right: 26px; /* room for imp-icon */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.title a { color: inherit; text-decoration: none; }
.title a:hover { color: var(--accent); }

.summary {
  grid-area: summary;
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.article.showing-de .summary {
  -webkit-line-clamp: 4;
}

.meta {
  grid-area: meta;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-mute);
  flex-wrap: wrap;
}

.meta .src {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-dim);
}

.favicon {
  width: 14px;
  height: 14px;
  border-radius: 2px;
  background: var(--bg-elev-2);
  flex-shrink: 0;
  vertical-align: middle;
}

.flag-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  line-height: 1;
  padding: 1px 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}

.flag-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--accent);
  transform: scale(1.06);
}

.flag-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.de-source-badge {
  display: inline-block;
  font-size: 10px;
  color: var(--warn);
  background: rgba(240, 136, 62, 0.12);
  border: 1px solid rgba(240, 136, 62, 0.3);
  padding: 0 6px;
  border-radius: 3px;
  letter-spacing: 0.3px;
}

/* ─────────────────────────  DETAIL PANE  ───────────────────────── */

.detail-pane {
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  padding: 16px 18px 80px;
  overflow-y: auto;
  height: calc(100vh - 52px);
  position: sticky;
  top: 52px;
}

.detail-pane.hidden { display: none; }

.detail-close {
  float: right;
  margin-left: 8px;
}

.detail-title {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
  margin: 0 0 12px;
  color: var(--text);
}

.detail-meta {
  font-size: 11px;
  color: var(--text-mute);
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.detail-image {
  width: 100%;
  max-height: 240px;
  object-fit: cover;
  border-radius: 6px;
  margin-bottom: 14px;
  background: var(--bg-elev-2);
}

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

.detail-actions .action-btn,
.detail-actions .action-btn-light {
  width: auto;
  flex: 0 0 auto;
  margin-bottom: 0;
}

.detail-section {
  margin-bottom: 18px;
}

.detail-section h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-mute);
  margin: 0 0 6px;
  font-weight: 600;
}

.detail-summary,
.detail-fulltext {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
}

.detail-fulltext {
  color: var(--text-dim);
  max-height: 60vh;
  overflow-y: auto;
  border-left: 2px solid var(--border);
  padding-left: 10px;
}

.detail-loading {
  color: var(--text-mute);
  font-size: 12px;
  padding: 12px 0;
  font-style: italic;
}

/* ─────────────────────────  EMPTY / FOOTER  ───────────────────────── */

.empty {
  text-align: center;
  color: var(--text-mute);
  padding: 60px 20px;
  font-style: italic;
}

.empty .reset-link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  font-style: normal;
  margin-left: 4px;
}

.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  padding: 5px 16px;
  font-size: 10px;
  color: var(--text-mute);
  text-align: right;
  height: 28px;
  z-index: 30;
}

.brand-mini { color: var(--text-mute); letter-spacing: 0.3px; }

/* ─────────────────────────  OVERLAYS  ───────────────────────── */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(13, 17, 23, 0.74);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: overlay-fade-in 0.15s ease-out;
}

:root[data-theme="light"] .overlay {
  background: rgba(140, 149, 159, 0.5);
}

.overlay.hidden { display: none; }

.overlay-box {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 26px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-strong);
  max-width: 80vw;
}

.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

.overlay-text {
  font-size: 14px;
  color: var(--text);
  text-align: center;
  line-height: 1.4;
  max-width: 60ch;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes overlay-fade-in { from { opacity: 0 } to { opacity: 1 } }

.help-box {
  align-items: stretch;
  min-width: 320px;
  padding: 22px 28px;
}

.help-box h2 {
  margin: 0 0 12px;
  font-size: 16px;
  text-align: center;
}

.help-table {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: 14px;
}

.help-table th,
.help-table td {
  text-align: left;
  padding: 5px 10px;
  font-size: 12.5px;
  border-bottom: 1px solid var(--border);
}

.help-table th {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  color: var(--accent);
  font-weight: 600;
  width: 90px;
}

.help-table td {
  color: var(--text-dim);
}

/* ─────────────────────────  RESPONSIVE  ───────────────────────── */

@media (max-width: 1199px) {
  .layout, .layout.with-detail {
    grid-template-columns: 220px 1fr;
  }
  .detail-pane {
    position: fixed;
    top: 52px;
    right: 0;
    bottom: 0;
    width: min(420px, 90vw);
    z-index: 40;
    box-shadow: var(--shadow-strong);
  }
}

@media (max-width: 768px) {
  .topbar { padding: 6px 10px; gap: 8px; height: 48px; }
  .brand-name { font-size: 16px; }
  .topbar-only-mobile { display: inline-flex; }
  .search-wrap { flex: 1; max-width: none; }
  #help-btn, #theme-btn { display: none; }

  .layout, .layout.with-detail {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    top: 48px;
    bottom: 0;
    left: 0;
    width: 270px;
    z-index: 41;
    transform: translateX(-100%);
    transition: transform 0.2s ease-out;
    box-shadow: var(--shadow-strong);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .stream {
    padding: 10px 14px 80px;
  }
  .article {
    grid-template-columns: 64px 1fr;
    padding: 10px 12px;
    gap: 4px 10px;
  }
  .article.no-thumb { grid-template-columns: 1fr; }
  .thumb { width: 64px; height: 64px; }
  .title { font-size: 13.5px; }
  .summary { -webkit-line-clamp: 2; }
  .article.showing-de .summary { -webkit-line-clamp: 3; }
  .time-group { top: 48px; }
  .live-banner { top: 48px; }
}

/* ─────────────────────────  UTILS  ───────────────────────── */

.hidden { display: none !important; }
