/* ===== Themes =====
 * Auswahl per Cookie "isp_theme" (siehe app.js / Inline-Script im <head>).
 * Kein data-theme = "auto": Grün hell bzw. Dunkel je nach Systemeinstellung.
 * Jedes Theme setzt nur Tokens – alle Komponenten verwenden ausschliesslich var(--…).
 */
:root,
:root[data-theme="green"] {
  --bg: #f3f6f3; --bg-grad: radial-gradient(1200px 600px at 10% -10%, #e3f1e4 0%, transparent 60%);
  --card: #ffffff; --card-2: #f1f7f1; --text: #1c2a1e; --muted: #5f6f61; --line: #dbe7dc;
  --accent: #2e7d32; --accent-2: #66bb6a; --accent-soft: #e8f5e9; --on-accent: #ffffff;
  --rain: #2563eb; --warn: #b45309; --warn-soft: #fef3c7; --bad: #b91c1c; --bad-soft: #fee2e2; --ok: #15803d;
  --shadow: 0 1px 2px rgba(16, 60, 20, .06), 0 4px 16px rgba(16, 60, 20, .06);
  color-scheme: light;
}
:root[data-theme="white"] {
  --bg: #fafafa; --bg-grad: none;
  --card: #ffffff; --card-2: #f4f4f5; --text: #18181b; --muted: #71717a; --line: #e7e7ea;
  --accent: #18181b; --accent-2: #a1a1aa; --accent-soft: #f1f1f3; --on-accent: #ffffff;
  --rain: #2563eb; --warn: #b45309; --warn-soft: #fef3c7; --bad: #dc2626; --bad-soft: #fee2e2; --ok: #16a34a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 2px 10px rgba(0, 0, 0, .04);
  color-scheme: light;
}
:root[data-theme="blue"] {
  --bg: #eef3fa; --bg-grad: radial-gradient(1200px 600px at 90% -10%, #dbe7fb 0%, transparent 60%);
  --card: #ffffff; --card-2: #f0f5fd; --text: #0f1b2d; --muted: #5a6b82; --line: #d9e3f2;
  --accent: #1d4ed8; --accent-2: #60a5fa; --accent-soft: #e3edfd; --on-accent: #ffffff;
  --rain: #0284c7; --warn: #b45309; --warn-soft: #fef3c7; --bad: #b91c1c; --bad-soft: #fee2e2; --ok: #15803d;
  --shadow: 0 1px 2px rgba(15, 40, 90, .06), 0 4px 16px rgba(15, 40, 90, .07);
  color-scheme: light;
}
:root[data-theme="sand"] {
  --bg: #f3ede1; --bg-grad: radial-gradient(1200px 600px at 10% -10%, #efe3cb 0%, transparent 60%);
  --card: #fbf7ef; --card-2: #f3ecdf; --text: #33291d; --muted: #7a6a55; --line: #e6dccb;
  --accent: #a0521c; --accent-2: #d49a5f; --accent-soft: #f5e6d3; --on-accent: #ffffff;
  --rain: #2f6f9f; --warn: #a16207; --warn-soft: #f7ebc6; --bad: #b42318; --bad-soft: #f8dcd6; --ok: #4d7c0f;
  --shadow: 0 1px 2px rgba(60, 40, 10, .06), 0 4px 16px rgba(60, 40, 10, .06);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0e1410; --bg-grad: radial-gradient(1200px 600px at 10% -10%, #14241a 0%, transparent 60%);
  --card: #151d17; --card-2: #1b261d; --text: #e3ece4; --muted: #93a596; --line: #26352a;
  --accent: #7cc47f; --accent-2: #4caf50; --accent-soft: #1d3320; --on-accent: #0e1410;
  --rain: #60a5fa; --warn: #fbbf24; --warn-soft: #3b2f0e; --bad: #f87171; --bad-soft: #3b1414; --ok: #4ade80;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0e1410; --bg-grad: radial-gradient(1200px 600px at 10% -10%, #14241a 0%, transparent 60%);
    --card: #151d17; --card-2: #1b261d; --text: #e3ece4; --muted: #93a596; --line: #26352a;
    --accent: #7cc47f; --accent-2: #4caf50; --accent-soft: #1d3320; --on-accent: #0e1410;
    --rain: #60a5fa; --warn: #fbbf24; --warn-soft: #3b2f0e; --bad: #f87171; --bad-soft: #3b1414; --ok: #4ade80;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="midnight"] {
  --bg: #0a1020; --bg-grad: radial-gradient(1200px 600px at 90% -10%, #13224a 0%, transparent 60%);
  --card: #10192e; --card-2: #16213b; --text: #e2e8f5; --muted: #8b99b5; --line: #1f2c4a;
  --accent: #7fb0ff; --accent-2: #3b82f6; --accent-soft: #172a52; --on-accent: #0a1020;
  --rain: #7dd3fc; --warn: #fbbf24; --warn-soft: #3a2d0c; --bad: #f87171; --bad-soft: #3a1520; --ok: #4ade80;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 6px 20px rgba(0, 0, 0, .3);
  color-scheme: dark;
}
:root[data-theme="nord"] {
  --bg: #2e3440; --bg-grad: none;
  --card: #353c4a; --card-2: #3b4252; --text: #eceff4; --muted: #a3adbf; --line: #444c5e;
  --accent: #88c0d0; --accent-2: #5e81ac; --accent-soft: #3c4d5c; --on-accent: #2e3440;
  --rain: #81a1c1; --warn: #ebcb8b; --warn-soft: #4a4636; --bad: #e0828a; --bad-soft: #4c3a42; --ok: #a3be8c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .2), 0 4px 16px rgba(0, 0, 0, .18);
  color-scheme: dark;
}
:root[data-theme="black"] {
  --bg: #000000; --bg-grad: none;
  --card: #0b0b0c; --card-2: #151517; --text: #ededed; --muted: #8a8a8f; --line: #202023;
  --accent: #f5f5f5; --accent-2: #6b6b70; --accent-soft: #1c1c1f; --on-accent: #000000;
  --rain: #67e8f9; --warn: #facc15; --warn-soft: #2a2408; --bad: #f87171; --bad-soft: #2a0f0f; --ok: #4ade80;
  --shadow: none;
  color-scheme: dark;
}
:root { --radius: 14px; --gap: 14px; }

/* ===== Base ===== */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left));
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h2 { font-size: 15px; margin: 0; font-weight: 650; letter-spacing: .01em; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 6px; font-weight: 600; }
code, kbd { font: 12px ui-monospace, SFMono-Regular, Consolas, monospace; background: var(--card-2); border: 1px solid var(--line); border-radius: 5px; padding: 0 4px; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; word-break: break-all; }
.loading { color: var(--muted); font-style: italic; }
.error { color: var(--bad); }
[hidden] { display: none !important; }

/* ===== Header ===== */
.top { display: flex; align-items: center; justify-content: space-between; max-width: 1400px; margin: 0 auto 12px; gap: 12px; }
.clock { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.time { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); letter-spacing: -.02em; }
.date { color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 8px; }
.pill { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.pill.off { background: var(--bad-soft); color: var(--bad); }

/* ===== Grid ===== */
.grid {
  max-width: 1400px; margin: 0 auto;
  display: grid; gap: var(--gap);
  grid-template-columns: 1fr;
  grid-auto-flow: row dense;
}
@media (min-width: 720px)  { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .span-2 { grid-column: span 2; } }
@media (min-width: 1100px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } .span-2 { grid-column: span 2; } }
.span-all { grid-column: 1 / -1; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px; min-width: 0; position: relative;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; min-height: 30px; }
.head-actions { display: flex; gap: 4px; }
.foot { margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.foot-main { max-width: 1400px; margin: 18px auto 0; font-size: 12px; color: var(--muted); text-align: center; }

/* ===== Buttons / inputs ===== */
.btn, .icon-btn {
  font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--card-2); color: var(--text);
  border-radius: 10px; transition: background .15s, border-color .15s;
}
.btn { padding: 9px 14px; }
.btn:hover, .icon-btn:hover { border-color: var(--accent-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.icon-btn { width: 32px; height: 32px; display: inline-grid; place-items: center; padding: 0; font-size: 15px; color: var(--text); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-2) 25%, transparent); }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

/* ===== Search ===== */
.search-card { padding: 16px; }
#search { display: flex; gap: 8px; }
#q { flex: 1; font-size: 17px; padding: 12px 16px; border-radius: 999px; }
#search .btn { border-radius: 999px; padding: 0 20px; }
.engines { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.engine {
  font: inherit; font-size: 13px; cursor: pointer; padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card-2); color: var(--text);
}
.engine:hover { border-color: var(--accent-2); }
.engine.is-default { background: var(--accent-soft); border-color: var(--accent-2); color: var(--accent); font-weight: 600; }
.hint { margin: 8px 0 0; font-size: 12px; color: var(--muted); }
@media (max-width: 600px) { .hint { display: none; } #search .btn { padding: 0 14px; } }

/* ===== Inline search / dropdown ===== */
.inline-search { position: relative; margin-bottom: 10px; }
.inline-search input { width: 100%; }
.dropdown { list-style: none; margin: 4px 0 0; padding: 4px; position: absolute; left: 0; right: 0; z-index: 10; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); max-height: 260px; overflow: auto; }
.dropdown:empty { display: none; }
.dropdown li { padding: 7px 10px; border-radius: 7px; cursor: pointer; }
.dropdown li:hover, .dropdown li:focus { background: var(--accent-soft); outline: none; }

/* ===== Weather ===== */
.w-now { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.w-icon { font-size: 52px; line-height: 1; }
.w-temp { font-size: 44px; font-weight: 700; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.w-desc { font-weight: 600; }
.w-meta { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px 14px; margin: 12px 0 4px; font-size: 13px; }
.w-meta span { color: var(--muted); }
.w-hours { display: flex; gap: 4px; overflow-x: auto; padding: 4px 0 8px; scroll-snap-type: x proximity; scrollbar-width: thin; }
.w-hour { flex: 0 0 54px; text-align: center; padding: 6px 2px; border-radius: 10px; background: var(--card-2); scroll-snap-align: start; font-size: 12px; }
.w-hour b { display: block; font-size: 14px; }
.w-hour .ic { font-size: 20px; display: block; margin: 2px 0; }
.w-hour .pp { color: var(--rain); }
.w-days { display: grid; gap: 2px; }
.w-day { display: grid; grid-template-columns: 38px 28px 1fr 2.6em minmax(60px, 1.6fr) 2.6em; align-items: center; gap: 8px; font-size: 13px; padding: 3px 0; }
.w-day .ic { font-size: 18px; }
.w-day .lo { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.w-day .hi { font-weight: 600; font-variant-numeric: tabular-nums; }
.rain { color: var(--rain); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 6px; border-radius: 3px; background: var(--card-2); position: relative; }
.bar i { position: absolute; top: 0; bottom: 0; border-radius: 3px; background: linear-gradient(90deg, #60a5fa, #fbbf24, #f97316); }
.w-extra { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: var(--card-2); border: 1px solid var(--line); }
.tag.good { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.tag.mid { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tag.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
@media (min-width: 1100px) {
  #weather .w-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 18px; }
}

/* ===== News ===== */
.tabs { display: flex; gap: 4px; overflow-x: auto; margin-bottom: 8px; scrollbar-width: none; }
.tab { font: inherit; font-size: 13px; cursor: pointer; padding: 5px 12px; border-radius: 999px; border: 1px solid transparent; background: none; color: var(--muted); white-space: nowrap; }
.tab[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.news { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px 18px; max-height: 620px; overflow: auto; }
@media (min-width: 1100px) { .news { grid-template-columns: 1fr 1fr; } }
.news li:not(.loading) { display: grid; grid-template-columns: 72px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.news li.noimg { grid-template-columns: 1fr; }
@media (max-width: 719px) { .news { max-height: none; } }
.news img { width: 72px; height: 48px; object-fit: cover; border-radius: 6px; background: var(--card-2); }
.news a { color: var(--text); font-weight: 600; display: block; line-height: 1.3; }
.news a:visited { color: var(--muted); }
.news p { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.news time { font-size: 11px; color: var(--muted); }
.news .src { color: var(--accent); font-weight: 600; }

/* ===== Departures ===== */
.departures { list-style: none; margin: 0; padding: 0; }
.departures li:not(.loading) { display: grid; grid-template-columns: 44px 76px 1fr auto; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.line { font-weight: 700; font-size: 12px; text-align: center; padding: 2px 4px; border-radius: 5px; background: var(--text); color: var(--card); white-space: nowrap; overflow: hidden; }
.line.T { background: #0369a1; color: #fff; } .line.B { background: #475569; color: #fff; }
.line.S { background: #1d4ed8; color: #fff; }
.line.IC, .line.IR, .line.EC, .line.ICE, .line.RE, .line.TGV, .line.RJX, .line.EN { background: #c60018; color: #fff; }
.dep-time { font-variant-numeric: tabular-nums; }
.dep-time small { display: block; font-size: 11px; color: var(--muted); }
.dep-to { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dep-pl { font-size: 12px; color: var(--muted); text-align: right; }
.delay { color: var(--bad); font-weight: 600; font-size: 12px; }

/* ===== Key/value ===== */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.copy { cursor: copy; border-bottom: 1px dashed var(--line); }
.status { margin: 8px 0 0; padding: 7px 10px; border-radius: 9px; font-size: 13px; }
.status.good { background: var(--accent-soft); color: var(--accent); }
.status.mid { background: var(--warn-soft); color: var(--warn); }
.status.bad { background: var(--bad-soft); color: var(--bad); }
.rtc-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.rtc-table th { text-align: left; color: var(--muted); font-weight: 500; padding: 3px 4px; border-bottom: 1px solid var(--line); }
.rtc-table td { padding: 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.rtc-table td.mono { font-size: 12px; }
.table-wrap { overflow-x: auto; }

/* ===== FX ===== */
.fx-table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.fx-table td { padding: 5px 0; border-bottom: 1px solid var(--line); }
.fx-table td:not(:first-child) { text-align: right; }
.fx-table td small { color: var(--muted); }
.converter { display: grid; grid-template-columns: 1fr 90px; gap: 6px; margin-top: 10px; }
.converter output { grid-column: 1 / -1; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ===== Links ===== */
.link-group + .link-group { margin-top: 10px; }
.link-group h3 { margin-top: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; background: var(--card-2); border: 1px solid var(--line); color: var(--text); font-size: 13px; }
.chip:hover { border-color: var(--accent-2); text-decoration: none; }
.chip img { width: 14px; height: 14px; border-radius: 3px; }
.chip .del { border: 0; background: none; color: var(--bad); cursor: pointer; font: inherit; padding: 0 0 0 2px; }
.link-form { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 6px; margin-top: 10px; }

/* ===== Notes ===== */
#notes { width: 100%; resize: vertical; min-height: 140px; font-size: 14px; }

@media (max-width: 480px) {
  body { font-size: 14.5px; }
  .time { font-size: 28px; }
  #net-status:not(.off) { display: none; }
  .card { padding: 12px; }
  .w-temp { font-size: 38px; }
  .kv { grid-template-columns: 1fr; gap: 0; }
  .kv dt { margin-top: 6px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ===== Theme-Auswahl ===== */
html.theme-anim, html.theme-anim * { transition: background-color .3s ease, color .3s ease, border-color .3s ease, box-shadow .3s ease !important; }
.theme-wrap { position: relative; }
.theme-menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 50; width: 300px;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .18); 
  opacity: 0; transform: translateY(-6px) scale(.98); transform-origin: top right; pointer-events: none;
  transition: opacity .16s ease, transform .16s ease;
}
.theme-menu.open { opacity: 1; transform: none; pointer-events: auto; }
.theme-menu h3 { margin: 2px 4px 10px; }
.theme-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.swatch {
  font: inherit; font-size: 12px; color: var(--text); cursor: pointer; background: none; border: 0; padding: 0;
  display: grid; gap: 5px; justify-items: center; border-radius: 12px;
}
.swatch .pv {
  width: 100%; aspect-ratio: 4 / 3; border-radius: 10px; position: relative; overflow: hidden;
  background: var(--p-bg); border: 1px solid var(--line); transition: transform .15s ease, box-shadow .15s ease;
}
.swatch .pv::before { /* Karte */
  content: ""; position: absolute; left: 14%; right: 14%; top: 22%; bottom: 16%;
  background: var(--p-card); border-radius: 6px; box-shadow: 0 1px 3px rgba(0, 0, 0, .15);
}
.swatch .pv::after { /* Akzent-Balken */
  content: ""; position: absolute; left: 22%; width: 36%; top: 32%; height: 12%; border-radius: 99px; background: var(--p-accent);
  box-shadow: 0 calc(var(--u, 1px) * 12) 0 -1px var(--p-line), 0 calc(var(--u, 1px) * 20) 0 -1px var(--p-line);
}
.swatch .pv.auto { background: linear-gradient(135deg, #f3f6f3 50%, #0e1410 50%); }
.swatch .pv.auto::before { background: linear-gradient(135deg, #ffffff 50%, #151d17 50%); }
.swatch:hover .pv { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0, 0, 0, .12); }
.swatch[aria-checked="true"] .pv { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--accent); }
.swatch[aria-checked="true"] span { font-weight: 650; color: var(--accent); }
.swatch:focus-visible { outline: none; }
.swatch:focus-visible .pv { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--accent-2); }
.theme-note { margin: 10px 4px 0; font-size: 11px; color: var(--muted); }
@media (max-width: 480px) {
  .theme-menu { position: fixed; left: 12px; right: 12px; top: auto; bottom: max(12px, env(safe-area-inset-bottom)); width: auto; transform-origin: bottom center; transform: translateY(12px); }
}
@media (prefers-reduced-motion: reduce) { html.theme-anim, html.theme-anim *, .theme-menu, .swatch .pv { transition: none !important; } }
