/* ==========================================================================
   AARO Dashboard - modern theme
   Replaces aaro-status.css / dark-theme.css on index.html.
   Element IDs and classes written by aaro-status.js are preserved.
   ========================================================================== */

/* ---------- Tokens ---------- */
body {
    --font-display: "Bricolage Grotesque", "Instrument Sans", system-ui, sans-serif;
    --font-body: "Instrument Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

    /* light */
    --bg: #eef0f7;
    --surface: #ffffff;
    --surface-2: #f4f5fa;
    --line: #dde1ee;
    --text: #151a2d;
    --muted: #5d6788;
    --accent: #5b3fd6;
    --accent-ink: #ffffff;
    --safe: #13915f;
    --unsafe: #d9334a;
    --warn: #a87300;
    --safe-soft: rgba(19, 145, 95, 0.12);
    --unsafe-soft: rgba(217, 51, 74, 0.11);
    --warn-soft: rgba(201, 138, 0, 0.14);
    --grid: rgba(21, 26, 45, 0.08);
    --heat-empty: #e1e4ef;
    --header-bg: rgba(238, 240, 247, 0.85);
    --sky: linear-gradient(90deg, #cfe0ff 0%, #a9b6e6 20%, #3b4677 38%, #1d2448 50%, #3b4677 62%, #a9b6e6 80%, #cfe0ff 100%);
}

body.dark-theme {
    --bg: #090e1c;
    --surface: #111831;
    --surface-2: #0d1428;
    --line: rgba(150, 165, 215, 0.15);
    --text: #e7eaf6;
    --muted: #8e99bd;
    --accent: #8b6cff;
    --accent-ink: #0b0f1e;
    --safe: #43d39a;
    --unsafe: #ff6175;
    --warn: #f6c453;
    --safe-soft: rgba(67, 211, 154, 0.13);
    --unsafe-soft: rgba(255, 97, 117, 0.13);
    --warn-soft: rgba(246, 196, 83, 0.14);
    --grid: rgba(150, 165, 215, 0.10);
    --heat-empty: #0a0f20;
    --header-bg: rgba(9, 14, 28, 0.82);
    --sky: linear-gradient(90deg, #2c3b6b 0%, #1c2650 20%, #0a0f24 38%, #04060f 50%, #0a0f24 62%, #1c2650 80%, #2c3b6b 100%);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 var(--font-body);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
img { max-width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
h2, h3 { margin: 0; }
p { margin: 0; }

.wrap { max-width: 1360px; margin: 0 auto; padding: 0 24px; }

/* ---------- Header ---------- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--header-bg);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
}
.header-row { display: flex; align-items: center; gap: 20px; min-height: 64px; }

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    text-decoration: none;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.05rem;
    line-height: 1.15;
    white-space: nowrap;
}
.brand img { height: 40px; width: auto; border-radius: 6px; }
.brand small {
    display: block;
    font-family: var(--font-body);
    font-weight: 400;
    font-size: 0.74rem;
    color: var(--muted);
}

.site-nav {
    display: flex;
    gap: 2px;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
}
.site-nav::-webkit-scrollbar { display: none; }
.site-nav a {
    padding: 7px 11px;
    border-radius: 8px;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.9rem;
    white-space: nowrap;
}
.site-nav a:hover { color: var(--text); background: var(--surface-2); }

.header-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }

.btn {
    display: inline-flex;
    align-items: center;
    padding: 7px 12px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 0.87rem;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}
.btn:hover { border-color: var(--accent); }

.theme-switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--muted);
    cursor: pointer;
}
.theme-switch input {
    appearance: none;
    -webkit-appearance: none;
    position: relative;
    width: 38px;
    height: 22px;
    margin: 0;
    border: 0;
    border-radius: 11px;
    background: var(--line);
    cursor: pointer;
    transition: background 0.2s;
}
.theme-switch input::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.2s;
}
.theme-switch input:checked { background: var(--accent); }
.theme-switch input:checked::after { transform: translateX(16px); }

/* ---------- Sections ---------- */
main.wrap { padding-top: 26px; padding-bottom: 64px; }
.section { margin-top: 52px; scroll-margin-top: 84px; }
.section-first { margin-top: 0; }
.section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 6px 16px;
    margin-bottom: 14px;
}
h2 {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 650;
    letter-spacing: -0.01em;
}
h3 { font-size: 1rem; font-weight: 600; }
.section-note { color: var(--muted); font-size: 0.88rem; }

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 18px 20px;
}

/* ---------- Live status ---------- */
.status-line {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 12px;
    margin-bottom: 14px;
    color: var(--muted);
}
#updateWarning { color: var(--text); }

.conn { display: inline-flex; width: 12px; justify-content: center; }
.loadingMarker::before, .onlineMarker::before, .offlineMarker::before {
    content: "";
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    vertical-align: middle;
}
.loadingMarker::before { background: var(--warn); }
.offlineMarker::before { background: var(--unsafe); }
.onlineMarker::before {
    background: var(--safe);
    animation: pulse 2.4s ease-out infinite;
}
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 var(--safe-soft), 0 0 0 0 var(--safe); }
    70% { box-shadow: 0 0 0 8px transparent, 0 0 0 0 transparent; }
    100% { box-shadow: 0 0 0 0 transparent; }
}

.warmup {
    display: inline-flex;
    gap: 6px;
    padding: 2px 10px;
    border-radius: 999px;
    background: var(--warn-soft);
    color: var(--warn);
    font-size: 0.87rem;
}
.warmup:has(#deadbandDot[style*="transparent"]) { display: none; }
#deadbandDot {
    background: none !important;
    color: inherit !important;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* Hero: roof / safety / tonight */
.now {
    display: grid;
    grid-template-columns: 1fr 1fr 1.45fr;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 18px;
    overflow: hidden;
}
.now > div { padding: 22px 24px; min-width: 0; }
.now > div + div { border-left: 1px solid var(--line); }
.now-label { color: var(--muted); margin-bottom: 4px; }
.big-state {
    font-family: var(--font-display);
    font-size: clamp(2.2rem, 4.4vw, 3.4rem);
    font-weight: 700;
    line-height: 1.05;
    letter-spacing: -0.025em;
    min-height: 1.05em;
}
.big-state[style*="80, 200, 120"] { color: var(--safe) !important; }
.big-state[style*="243, 23, 45"] { color: var(--unsafe) !important; }
.now-sub { margin-top: 10px; font-variant-numeric: tabular-nums; }
.now-reason { color: var(--muted); margin-top: 2px; }

.window-times { display: flex; gap: 32px; margin: 0 0 16px; }
.window-times dt { color: var(--muted); }
.window-times dd {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    min-height: 1.3em;
}

#nightBar {
    position: relative;
    height: 46px;
    border-radius: 10px;
    background: var(--sky);
    overflow: hidden;
}
#nightBar .win {
    position: absolute;
    top: 9px;
    bottom: 9px;
    border-radius: 6px;
    background: color-mix(in srgb, var(--accent) 38%, transparent);
    border: 1px solid var(--accent);
}
#nightBar .nowmark {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    margin-left: -1px;
    background: #fff;
    box-shadow: 0 0 6px rgba(255, 255, 255, 0.8);
}
.night-ticks {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    color: var(--muted);
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
}

/* Sensor tiles */
.sensors {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    margin-top: 12px;
}
.sensor {
    background: var(--surface);
    border: 1px solid var(--line);
    border-top: 3px solid var(--line);
    border-radius: 12px;
    padding: 14px 16px 16px;
    min-width: 0;
}
.sensor:has(.sensor-since[style*="80, 200, 120"]) { border-top-color: var(--safe); }
.sensor:has(.sensor-since[style*="243, 23, 45"]) { border-top-color: var(--unsafe); }
.sensor-name { color: var(--muted); font-size: 0.9rem; }
.sensor-value {
    display: block;
    margin: 2px 0 10px;
    min-height: 1.3em;
    background: none !important;
    font-family: var(--font-display);
    font-size: 1.65rem;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.sensor-since {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 0.8rem;
    background: var(--surface-2) !important;
    color: var(--muted) !important;
}
.sensor-since:empty { display: none; }
.sensor-since[style*="80, 200, 120"] { background: var(--safe-soft) !important; color: var(--safe) !important; }
.sensor-since[style*="243, 23, 45"] { background: var(--unsafe-soft) !important; color: var(--unsafe) !important; }
.sensor-since[style*="80, 200, 120"]::before { content: "Safe for "; }
.sensor-since[style*="243, 23, 45"]::before { content: "Unsafe for "; }

/* ---------- Graphs ---------- */
.graphs { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
.graph-card { padding: 16px 16px 10px; min-width: 0; }
.graph-card h3 { margin-bottom: 8px; }
.graph-card h3 span { display: block; color: var(--muted); font-weight: 400; font-size: 0.85rem; }
.smallGraphDiv { position: relative; }

/* ---------- Imaging nights ---------- */
.stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin: 0 0 12px;
}
.stat dt { color: var(--muted); }
.stat dd {
    margin: 2px 0 0;
    font-family: var(--font-display);
    font-size: 1.9rem;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    min-height: 1.3em;
}

.heatmap-head {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 20px;
    margin-bottom: 12px;
}
.heatmap-hint { color: var(--muted); font-size: 0.88rem; flex: 1; }
.hint-touch { display: none; }
@media (hover: none) {
    .hint-mouse { display: none; }
    .hint-touch { display: inline; }
}
#cal-heatmap { overflow-x: auto; padding-bottom: 4px; }
#cal-heatmap > svg { display: block; margin: 0 auto; }
#cal-heatmap text, #cal-heatmap-legend text { fill: var(--muted) !important; }
.ch-subdomain-bg { fill: var(--heat-empty); }

/* ---------- Roof log ---------- */
.roofTabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.tablinks {
    min-width: 92px;
    padding: 8px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 0.88rem;
    line-height: 1.3;
    cursor: pointer;
}
.tablinks:hover { border-color: var(--muted); }
.tablinks.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.tablinks.openBackground { background: var(--safe-soft); color: var(--safe); }
.tablinks.closedBackground { background: var(--unsafe-soft); color: var(--unsafe); }
.tablinks.stoppedBackground { background: var(--surface-2); color: var(--muted); }
.tablinks.maintenanceBackground { background: var(--warn-soft); color: var(--warn); }
.tablinks.openingBackground, .tablinks.closingBackground {
    background-size: 200% 100%;
    animation: travel 1.8s linear infinite;
}
.tablinks.openingBackground {
    color: var(--safe);
    background-image: linear-gradient(90deg, var(--surface) 0%, var(--safe-soft) 50%, var(--surface) 100%);
}
.tablinks.closingBackground {
    color: var(--unsafe);
    background-image: linear-gradient(90deg, var(--surface) 0%, var(--unsafe-soft) 50%, var(--surface) 100%);
}
@keyframes travel { from { background-position: 200% 0; } to { background-position: 0 0; } }

.tabcontent { display: none; }
.roofLogDiv {
    max-height: 340px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
}
.roofLogDiv table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.roofLogDiv td { padding: 9px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
.roofLogDiv tr:last-child td { border-bottom: 0; }
.roofLogDiv td:first-child {
    width: 190px !important;
    font-weight: 400 !important;
    color: var(--muted);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* ---------- Embeds & forecast ---------- */
.callout {
    margin-bottom: 12px;
    padding: 12px 16px;
    border-left: 3px solid var(--warn);
    border-radius: 10px;
    background: var(--warn-soft);
}
.embed {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #000;
}
.embed iframe { display: block; width: 100%; aspect-ratio: 3 / 2; border: 0; }

.forecasts {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
    margin-top: 14px;
}
.forecast-card h3 { margin-bottom: 12px; }
/* Show forecast charts at native size (never upscaled), centred */
.forecast-card img { display: block; width: auto; max-width: 100%; height: auto; margin: 0 auto; border-radius: 6px; }
#AstrosphericEmbedContainer { max-width: 924px; margin: 0 auto; }
.hscroll { overflow-x: auto; }

/* ---------- Cameras ---------- */
#allCamsSelector table, #allCamsSelector tbody, #allCamsSelector tr {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: auto !important;
}
#allCamsSelector { margin-bottom: 14px; }
#allCamsSelector td {
    display: block;
    padding: 8px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
}
#allCamsSelector td:first-child { display: none; }
#allCamsSelector input { accent-color: var(--accent); }
#allCamsSelector label { cursor: pointer; }

#allCamsContainer {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr));
    gap: 12px;
}
#allCamsContainer:empty::before {
    content: "Choose an observatory above to start its camera feed.";
    color: var(--muted);
}
.webcamcontainer {
    position: relative;
    overflow: hidden;
    aspect-ratio: 16 / 9;
    border-radius: 12px;
    background: #000;
    color: #fff;
}
.webcamcontainer img.webcamsize { display: block; width: 100%; height: 100%; object-fit: cover; }
.centeredText { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; }
.camOverlay { font-size: 1.15rem; text-shadow: 0 1px 8px #000; }

/* ---------- Guides & footer ---------- */
.guides { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.guide { color: var(--text); text-decoration: none; font-weight: 600; }
.guide:hover { border-color: var(--accent); }
.guide span { display: block; margin-top: 4px; color: var(--muted); font-weight: 400; font-size: 0.88rem; }
.site-footer { border-top: 1px solid var(--line); padding: 22px 0 30px; color: var(--muted); font-size: 0.85rem; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1100px) {
    .now { grid-template-columns: 1fr 1fr; }
    .now > .tonight { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); }
    .sensors { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 900px) {
    .header-row { flex-wrap: wrap; gap: 6px 14px; padding: 10px 0 6px; }
    .site-nav { order: 3; flex-basis: 100%; margin: 0 -11px; }
    .section { scroll-margin-top: 120px; }
    .graphs { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 640px) {
    .wrap, main { padding-left: 14px; padding-right: 14px; }
    .brand small, .hide-sm { display: none; }
    .theme-switch span { display: none; }
    main.wrap { padding-top: 18px; }
    .section { margin-top: 40px; }
    h2 { font-size: 1.3rem; }

    .now { grid-template-columns: 1fr; border-radius: 14px; }
    .now > div { padding: 18px; }
    .now > div + div { border-left: 0; border-top: 1px solid var(--line); }
    .window-times { gap: 24px; }

    .sensors { grid-template-columns: 1fr 1fr; gap: 10px; }
    .sensor { padding: 12px 14px 14px; }
    .sensor-value { font-size: 1.4rem; }

    .stats { grid-template-columns: 1fr; gap: 8px; }
    .stat { display: flex; align-items: baseline; justify-content: space-between; padding: 12px 14px; }
    .stat dd { font-size: 1.3rem; }

    .panel { padding: 14px; }
    .graph-card { padding: 12px 10px 6px; }

    .tablinks { flex: 1 1 auto; min-width: 0; }
    .roofLogDiv { max-height: 300px; }
    .roofLogDiv tr { display: block; padding: 8px 14px; border-bottom: 1px solid var(--line); }
    .roofLogDiv tr:last-child { border-bottom: 0; }
    .roofLogDiv td { display: block; padding: 0; border: 0; }
    .roofLogDiv td:first-child { width: auto !important; font-size: 0.8rem; }

    .embed iframe { aspect-ratio: auto; height: 75vh; }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
