/* ------------------------------------------------------------------ *
 *  Madrid Live — dashboard styles
 * ------------------------------------------------------------------ */
:root {
  --bg: #0b0d12;
  --bg2: #12151d;
  --panel: #161a24;
  --panel2: #1c2230;
  --line: #242b3a;
  --text: #e7ecf5;
  --muted: #93a0b5;
  --dim: #5b6678;
  --accent: #ff5a4d;      /* madrid red */
  --accent2: #ffc247;     /* gold */
  --good: #4ade80;
  --link: #7cc0ff;
  --radius: 16px;
  --shadow: 0 6px 24px rgba(0,0,0,.35);
  --gap: 14px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
[data-theme="light"] {
  --bg: #eef1f6;
  --bg2: #e4e9f1;
  --panel: #ffffff;
  --panel2: #f4f6fb;
  --line: #dbe2ee;
  --text: #16202e;
  --muted: #5a6678;
  --dim: #93a0b5;
  --shadow: 0 6px 20px rgba(20,40,80,.10);
  --link: #1f6feb;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(255,90,77,.10), transparent 60%),
    radial-gradient(900px 500px at 5% 0%, rgba(255,194,71,.08), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ---------- top bar ---------- */
#topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 18px;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; margin-right: auto; }
.brand-mark { font-size: 30px; line-height: 1; filter: drop-shadow(0 2px 6px rgba(0,0,0,.4)); }
.brand-text h1 { margin: 0; font-size: 22px; letter-spacing: .5px; font-weight: 800; }
.brand-text h1 span { color: var(--accent); }
.brand-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

.clock-block { text-align: center; }
.clock { font-family: var(--mono); font-size: 30px; font-weight: 700; letter-spacing: 1px; line-height: 1; }
.dateline { color: var(--muted); font-size: 12px; margin-top: 4px; text-transform: capitalize; }

.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.refresh-status { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12.5px; font-family: var(--mono); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 0 rgba(74,222,128,.6); animation: pulse 2.4s infinite; }
.dot.busy { background: var(--accent2); animation: none; }
@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(74,222,128,.5)} 70%{box-shadow:0 0 0 8px rgba(74,222,128,0)} 100%{box-shadow:0 0 0 0 rgba(74,222,128,0)} }

.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { background: transparent; color: var(--muted); border: 0; padding: 8px 12px; font-size: 13px; cursor: pointer; font-weight: 600; }
.seg button.active { background: var(--accent); color: #fff; }

.icon-btn, .primary-btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 10px; padding: 8px 11px; font-size: 14px; cursor: pointer;
  transition: transform .08s ease, background .15s ease;
}
.icon-btn:hover, .primary-btn:hover { transform: translateY(-1px); }
.primary-btn { background: linear-gradient(180deg, var(--accent), #e0483d); color: #fff; border: 0; font-weight: 700; }
.primary-btn.spin { opacity: .7; pointer-events: none; }

/* ---------- board / panels ---------- */
#board { padding: var(--gap); display: grid; gap: var(--gap); align-items: start; }
.view-collage { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); grid-auto-flow: dense; }
.view-cards   { grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }

.panel {
  background: linear-gradient(180deg, var(--panel), var(--panel2));
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; min-width: 0;
  display: flex; flex-direction: column;
}
.panel.wide  { grid-column: span 2; }
.panel.wide3 { grid-column: span 3; }
@media (max-width: 720px){ .panel.wide, .panel.wide3 { grid-column: span 1; } }

.panel-head {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 14px; border-bottom: 1px solid var(--line);
  font-weight: 700; font-size: 13.5px; letter-spacing: .3px;
}
.panel-head .ico { font-size: 16px; }
.panel-head .meta { margin-left: auto; color: var(--dim); font-weight: 500; font-size: 11.5px; font-family: var(--mono); }
.panel-body { padding: 14px; }
.panel-body.flush { padding: 0; }

.err { color: var(--accent); font-size: 12.5px; padding: 6px 0; }

/* ---------- cards view ---------- */
.view-cards .card {
  cursor: pointer; transition: transform .1s ease, border-color .15s ease;
}
.view-cards .card:hover { transform: translateY(-3px); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.view-cards .card .expand-hint { color: var(--dim); font-size: 11px; padding: 8px 14px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; }

/* ---------- weather ---------- */
.wx-now { display: flex; align-items: center; gap: 16px; }
.wx-emoji { font-size: 52px; line-height: 1; }
.wx-temp { font-size: 42px; font-weight: 800; line-height: 1; }
.wx-desc { color: var(--muted); font-size: 13px; margin-top: 4px; }
.wx-feels { color: var(--dim); font-size: 12px; }
.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px,1fr)); gap: 8px; margin-top: 14px; }
.metric { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.metric .k { color: var(--dim); font-size: 10.5px; text-transform: uppercase; letter-spacing: .4px; }
.metric .v { font-size: 17px; font-weight: 700; margin-top: 2px; }
.metric .v small { font-size: 11px; color: var(--muted); font-weight: 500; }

.hourly { display: flex; gap: 6px; overflow-x: auto; padding: 12px 0 4px; margin-top: 6px; }
.hourly .h { flex: 0 0 auto; text-align: center; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 9px; min-width: 52px; }
.hourly .h .t { font-size: 10.5px; color: var(--muted); }
.hourly .h .e { font-size: 18px; margin: 3px 0; }
.hourly .h .d { font-size: 13px; font-weight: 700; }
.hourly .h .p { font-size: 10px; color: var(--link); }

.daily { margin-top: 8px; }
.drow { display: grid; grid-template-columns: 46px 30px 1fr 78px; align-items: center; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 13px; }
.drow:first-child { border-top: 0; }
.drow .dd { color: var(--muted); }
.drow .de { font-size: 17px; text-align: center; }
.drow .dbar { height: 6px; border-radius: 4px; background: linear-gradient(90deg, var(--link), var(--accent2), var(--accent)); opacity:.55; }
.drow .dt { text-align: right; font-family: var(--mono); font-size: 12.5px; }
.drow .dt b { color: var(--text); }
.drow .dt span { color: var(--dim); }

.bar { height: 8px; border-radius: 6px; background: var(--bg2); overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; }

/* ---------- air quality ---------- */
.aqi-hero { display: flex; align-items: center; gap: 16px; }
.gauge { --p: 0; --c: #888; width: 92px; height: 92px; border-radius: 50%; flex: 0 0 auto;
  background: conic-gradient(var(--c) calc(var(--p)*1%), var(--bg2) 0);
  display: grid; place-items: center; }
.gauge > div { width: 70px; height: 70px; border-radius: 50%; background: var(--panel); display: grid; place-items: center; text-align: center; }
.gauge .g-num { font-size: 24px; font-weight: 800; }
.gauge .g-lbl { font-size: 9px; color: var(--dim); }
.aqi-band { font-size: 18px; font-weight: 800; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; font-size: 11.5px; }
.chip b { font-weight: 700; }
.chip .u { color: var(--dim); }

/* ---------- airport ---------- */
.metar-cat { display: inline-block; padding: 2px 9px; border-radius: 999px; color: #08110a; font-weight: 800; font-size: 12px; }
.raw { font-family: var(--mono); font-size: 12px; background: var(--bg2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px; margin-top: 10px; line-height: 1.5; word-break: break-word; color: var(--muted); }
.raw b { color: var(--text); }

/* ---------- cameras ---------- */
.cam-grid { display: grid; gap: 8px; padding: 10px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.cam-grid.mini { grid-template-columns: repeat(2, 1fr); }
.cam { position: relative; border-radius: 10px; overflow: hidden; background: var(--bg2); border: 1px solid var(--line); aspect-ratio: 4/3; }
.cam img { width: 100%; height: 100%; object-fit: cover; display: block; background: var(--bg2); }
.cam .lbl { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 8px 6px;
  background: linear-gradient(transparent, rgba(0,0,0,.78)); color: #fff; font-size: 11px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cam .live { position: absolute; top: 6px; left: 6px; background: var(--accent); color: #fff;
  font-size: 9px; font-weight: 800; padding: 2px 6px; border-radius: 5px; letter-spacing: .5px; }

/* camera picker inside modal */
.picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px,1fr)); gap: 6px; max-height: 40vh; overflow: auto; margin-top: 10px; padding-right: 4px; }
.picker label { display: flex; gap: 7px; align-items: center; font-size: 12px; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; cursor: pointer; }
.picker input { accent-color: var(--accent); }

/* ---------- map ---------- */
.tilemap { display: grid; gap: 0; line-height: 0; background: var(--bg2); }
.tilemap img { width: 100%; display: block; }
.map-cap { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 8px 12px; font-size: 11.5px; color: var(--dim); }

/* ---------- stream (iframe) ---------- */
.frame { width: 100%; border: 0; display: block; background: var(--bg2); }
.stream-frame { aspect-ratio: 16/9; }

/* ---------- news ---------- */
.news li { list-style: none; padding: 9px 0; border-top: 1px solid var(--line); }
.news ul { margin: 0; padding: 0; }
.news li:first-child { border-top: 0; }
.news a { color: var(--text); text-decoration: none; font-size: 13.5px; line-height: 1.35; }
.news a:hover { color: var(--link); }
.news .when { color: var(--dim); font-size: 11px; margin-top: 3px; }

/* ---------- moon / sun / fact ---------- */
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.big-emoji { font-size: 40px; }
.kv { display: flex; justify-content: space-between; font-size: 12.5px; padding: 4px 0; color: var(--muted); }
.kv b { color: var(--text); font-weight: 700; }
.fact { font-size: 14px; line-height: 1.5; color: var(--text); }
.fact:before { content: "💡 "; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 80; background: rgba(4,6,10,.72); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 24px; }
.modal.hidden { display: none; }
.modal-inner { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; max-width: 1100px; width: 100%; max-height: 88vh; overflow: auto; position: relative; box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.modal-close { position: absolute; top: 12px; right: 12px; z-index: 2; background: var(--panel2); border: 1px solid var(--line); color: var(--text); border-radius: 10px; width: 34px; height: 34px; cursor: pointer; font-size: 15px; }
#modalBody .panel { box-shadow: none; border: 0; }

/* ---------- footer ---------- */
#footbar { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  color: var(--dim); font-size: 11.5px; padding: 12px 20px 22px; border-top: 1px solid var(--line); margin-top: 6px; }
#genAt { font-family: var(--mono); }

/* ---------- snapshot mode ---------- */
body.snapshot #topbar .controls,
body.snapshot #footbar { display: none; }
body.snapshot #topbar { position: static; }

a { color: var(--link); }
::-webkit-scrollbar { height: 8px; width: 8px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
