/* Tesla Sentry Monitor — night-sky glass UI (aurora over a forest overlook) */
:root {
    color-scheme: dark;
    --text: #e7eefc;
    --muted: rgba(203, 216, 240, .66);
    --faint: rgba(203, 216, 240, .42);
    --line: rgba(255, 255, 255, .09);
    --glass: linear-gradient(160deg, rgba(36, 66, 122, .42), rgba(8, 20, 46, .58));
    --glass-border: rgba(255, 255, 255, .13);
    --blue: #0a84ff;
    --sky-blue: #7dd3fc;
    --green: #4ade80;
    --radius: 22px;
    --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
    --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { background: #030817; }

body {
    min-height: 100vh;
    min-height: 100dvh;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    display: flex;
    flex-direction: column;
}

a { color: var(--sky-blue); text-decoration: none; }
a:hover { color: #bae6fd; }
:focus-visible { outline: 2px solid var(--sky-blue); outline-offset: 2px; border-radius: 8px; }

/* ------------------------------------------------------------------ */
/* Scene: night sky, aurora, layered forest ridges                     */
/* ------------------------------------------------------------------ */
.scene {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
    background:
        radial-gradient(120% 60% at 50% 100%, rgba(37, 99, 235, .35), transparent 70%),
        linear-gradient(180deg, #01030b 0%, #04102b 38%, #0a2452 70%, #123a73 100%);
}

.stars {
    position: absolute;
    inset: 0 0 30% 0;
    background: url("/static/stars.svg") 0 0 / 800px 500px repeat;
    opacity: .75;
    -webkit-mask-image: linear-gradient(to bottom, #000 40%, transparent);
    mask-image: linear-gradient(to bottom, #000 40%, transparent);
    animation: twinkle 9s ease-in-out infinite alternate;
}
/* two more star groups that twinkle on their own rhythm, so neighbouring stars flicker independently */
.stars::before, .stars::after {
    content: "";
    position: absolute;
    inset: 0;
    background: url("/static/stars-b.svg") 0 0 / 800px 500px repeat;
    animation: twinkle-a 3.7s ease-in-out infinite alternate;
}
.stars::after {
    background-image: url("/static/stars-c.svg");
    animation: twinkle-b 5.3s ease-in-out -2s infinite alternate;
}
.stars.real-sky::before, .stars.real-sky::after { display: none; }   /* sky.js twinkles the real stars itself */
/* sky.js draws the real sky on a canvas once a location is known */
.stars.real-sky { background: none; }
.stars canvas { display: block; width: 100%; height: 100%; }

.aurora {
    position: absolute;
    inset: -10% -20% 25% -20%;
    filter: blur(48px) saturate(140%);
    mix-blend-mode: screen;
}
.band {
    position: absolute;
    border-radius: 50%;
    opacity: .7;
    will-change: transform, opacity;
}
.b1 {
    left: 0; top: 18%; width: 75%; height: 34%;
    background: linear-gradient(90deg, transparent, rgba(56, 189, 248, .75) 25%, rgba(45, 212, 191, .55) 50%, rgba(59, 130, 246, .7) 75%, transparent);
    animation: drift-a 26s ease-in-out infinite alternate;
}
.b2 {
    left: 30%; top: 6%; width: 70%; height: 28%;
    background: linear-gradient(90deg, transparent, rgba(129, 140, 248, .6) 30%, rgba(56, 189, 248, .55) 60%, transparent);
    animation: drift-b 34s ease-in-out infinite alternate;
}
.b3 {
    left: 15%; top: 34%; width: 60%; height: 20%;
    background: linear-gradient(90deg, transparent, rgba(52, 211, 153, .35) 35%, rgba(14, 165, 233, .5) 65%, transparent);
    animation: drift-c 40s ease-in-out infinite alternate;
}

/* faint vertical curtain rays inside the aurora */
.rays {
    position: absolute;
    inset: 0 -10% 40% -10%;
    background: repeating-linear-gradient(90deg, transparent 0 14px, rgba(125, 211, 252, .07) 14px 17px, transparent 17px 31px, rgba(165, 180, 252, .05) 31px 33px);
    -webkit-mask-image: radial-gradient(55% 45% at 45% 40%, #000, transparent 75%);
    mask-image: radial-gradient(55% 45% at 45% 40%, #000, transparent 75%);
    filter: blur(1.5px);
    mix-blend-mode: screen;
    animation: rays 22s ease-in-out infinite alternate;
}
@keyframes rays {
    from { transform: translateX(-3%) skewX(-10deg); opacity: .5; }
    to   { transform: translateX(3%) skewX(6deg); opacity: 1; }
}

.ridge {
    position: absolute;
    left: -3%; right: -3%;   /* overhang so the sway never shows a gap at the screen edges */
    background-repeat: repeat-x;
    background-size: auto 100%;
    background-position: center bottom;
    transform-origin: 50% 100%;   /* anchored at the ground: tree tops move most */
    will-change: transform;
}
/* wind: each ridge sways on its own rhythm; nearer trees move a little more */
.ridge.far  { bottom: 9vh;  height: 30vh; background-image: url("/static/forest-far.svg"); opacity: .9;
              --sway: .35deg; animation: sway 11s ease-in-out infinite; }
.ridge.mid  { bottom: 3vh;  height: 27vh; background-image: url("/static/forest-mid.svg"); background-position: 30% bottom;
              --sway: .6deg; animation: sway 8.5s ease-in-out -3s infinite; }
.ridge.near { bottom: -3vh; height: 24vh; background-image: url("/static/forest-near.svg"); background-position: 70% bottom;
              --sway: 1deg; animation: sway 7s ease-in-out -5s infinite; }
.mist {
    position: absolute;
    left: -10%; right: -10%; bottom: 10vh; height: 18vh;
    background: radial-gradient(60% 50% at 50% 60%, rgba(147, 197, 253, .18), transparent 70%);
    animation: mist 30s ease-in-out infinite alternate;
}

@keyframes drift-a {
    0%   { transform: translateX(-8%) rotate(-6deg) scaleY(.8); opacity: .55; }
    50%  { transform: translateX(4%) rotate(-2deg) scaleY(1.15); opacity: .85; }
    100% { transform: translateX(10%) rotate(-8deg) scaleY(.9); opacity: .6; }
}
@keyframes drift-b {
    0%   { transform: translateX(6%) rotate(5deg) scaleY(1); opacity: .45; }
    100% { transform: translateX(-12%) rotate(1deg) scaleY(1.3); opacity: .8; }
}
@keyframes drift-c {
    0%   { transform: translateX(-4%) skewX(-12deg); opacity: .35; }
    100% { transform: translateX(14%) skewX(8deg); opacity: .7; }
}
@keyframes mist { from { transform: translateX(-4%); opacity: .7; } to { transform: translateX(4%); opacity: 1; } }
@keyframes twinkle { from { opacity: .55; } to { opacity: .85; } }
@keyframes twinkle-a { 0% { opacity: .9; } 35% { opacity: .25; } 60% { opacity: 1; } 100% { opacity: .45; } }
@keyframes twinkle-b { 0% { opacity: .3; } 45% { opacity: 1; } 70% { opacity: .5; } 100% { opacity: .95; } }
/* a gust: lean, ease back past centre, settle */
@keyframes sway {
    0%, 100% { transform: skewX(0deg); }
    30% { transform: skewX(calc(var(--sway) * -1)); }
    55% { transform: skewX(calc(var(--sway) * .45)); }
    75% { transform: skewX(calc(var(--sway) * -.3)); }
}
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .45; transform: scale(.8); } }

@media (prefers-reduced-motion: reduce) {
    .band, .mist, .stars, .stars::before, .stars::after, .rays, .live-dot,
    .ridge.far, .ridge.mid, .ridge.near { animation: none; }   /* match the ridges' own specificity */
}

/* ------------------------------------------------------------------ */
/* Glass surfaces                                                      */
/* ------------------------------------------------------------------ */
.glass {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: 0 24px 60px -24px rgba(0, 4, 20, .8), inset 0 1px 0 rgba(255, 255, 255, .14);
    -webkit-backdrop-filter: blur(22px) saturate(170%);
    backdrop-filter: blur(22px) saturate(170%);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .glass { background: rgba(10, 24, 54, .94); }
}

/* ------------------------------------------------------------------ */
/* Top bar                                                             */
/* ------------------------------------------------------------------ */
.topbar {
    position: sticky;
    top: max(12px, env(safe-area-inset-top));
    z-index: 10;
    margin: 12px auto 0;
    width: min(1120px, calc(100% - 24px));
    padding: 10px 12px 10px 18px;
    display: flex;
    align-items: center;
    gap: 16px;
    border-radius: 999px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 650; letter-spacing: -.01em; white-space: nowrap; }
.brand:hover { color: #fff; }
.logo { width: 30px; height: 30px; flex: none; filter: drop-shadow(0 0 10px rgba(125, 211, 252, .45)); }

.segmented {
    display: flex;
    gap: 2px;
    margin-inline: auto;
    padding: 3px;
    border-radius: 999px;
    background: rgba(0, 0, 0, .22);
    border: 1px solid rgba(255, 255, 255, .06);
    overflow-x: auto;
    scrollbar-width: none;
}
.segmented a {
    padding: 7px 16px;
    border-radius: 999px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    transition: color .2s, background .2s;
}
.segmented a:hover { color: var(--text); }
.segmented a[aria-current="page"] {
    color: #fff;
    background: linear-gradient(180deg, rgba(255, 255, 255, .2), rgba(255, 255, 255, .08));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22), 0 4px 12px -4px rgba(0, 0, 0, .5);
}

/* ------------------------------------------------------------------ */
/* Layout                                                              */
/* ------------------------------------------------------------------ */
.container {
    flex: 1;
    width: min(1120px, calc(100% - 32px));
    margin: 36px auto 48px;
}
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { font-size: clamp(26px, 4vw, 34px); font-weight: 700; letter-spacing: -.025em; }
.page-head p { color: var(--muted); margin-top: 2px; }

.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); align-items: start; }

.panel { padding: 22px; margin-bottom: 16px; }
.panel > h2 { font-size: 17px; font-weight: 650; letter-spacing: -.01em; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.panel > h2 .count { color: var(--faint); font-weight: 500; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; }

.stat { padding: 18px 20px; }
.stat .label { color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.stat .value {
    margin-top: 6px;
    font-size: 34px;
    font-weight: 700;
    letter-spacing: -.03em;
    line-height: 1.1;
    background: linear-gradient(180deg, #fff, #9cc7ff);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.stat .value.small { font-size: 20px; padding-top: 8px; }

.live { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; font-size: 13px; color: var(--muted); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 10px var(--green); animation: pulse 2.4s ease-in-out infinite; }

/* Vehicles */
.vehicles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.vehicle {
    padding: 16px;
    border-radius: 16px;
    background: rgba(255, 255, 255, .05);
    border: 1px solid var(--line);
    display: grid;
    gap: 6px;
}
.vehicle .name { font-weight: 650; }
.vehicle .meta { color: var(--muted); font-size: 13px; }

/* Alerts list */
.list { list-style: none; display: grid; }
.list li { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 14px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; padding-top: 0; }
.list .msg { font-size: 14px; }
.list .badge { justify-self: start; }
.list .sub { grid-column: 2; color: var(--faint); font-size: 12px; }
.list time { color: var(--muted); font-size: 13px; white-space: nowrap; }

.empty { color: var(--muted); padding: 18px 0 6px; text-align: center; font-size: 14px; }

/* Badges */
.badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px; font-weight: 600;
    white-space: nowrap;
    color: #dbeafe;
    background: rgba(96, 165, 250, .16);
    border: 1px solid rgba(96, 165, 250, .3);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-sentry_off_motion, .badge.off { color: #fecaca; background: rgba(255, 107, 107, .15); border-color: rgba(255, 107, 107, .35); }
.badge-sentry_off_exit { color: #fed7aa; background: rgba(251, 146, 60, .15); border-color: rgba(251, 146, 60, .35); }
.badge-sentry_disabled_event { color: #fde68a; background: rgba(251, 191, 36, .14); border-color: rgba(251, 191, 36, .35); }
.badge-sentry_on_event, .badge.on { color: #bbf7d0; background: rgba(74, 222, 128, .13); border-color: rgba(74, 222, 128, .32); }
.badge-sentry_threat, .cat-sentry { color: #e9d5ff; background: rgba(168, 85, 247, .16); border-color: rgba(168, 85, 247, .38); }
.badge-outage { color: #fde68a; background: rgba(251, 191, 36, .14); border-color: rgba(251, 191, 36, .35); }
.badge-recovered { color: #bbf7d0; background: rgba(74, 222, 128, .13); border-color: rgba(74, 222, 128, .32); }
.cat-state { color: #bae6fd; }
.cat-telemetry { color: var(--muted); background: rgba(255, 255, 255, .06); border-color: var(--line); }
.list .count { color: var(--faint); font-size: 12px; }

.section-title { font-size: 20px; font-weight: 650; letter-spacing: -.01em; margin: 10px 0 14px; }
.car-settings .hint.mono { margin: -8px 0 12px; }
.panel > p.hint { margin: -6px 0 14px; }
.car-settings { scroll-margin-top: 150px; }   /* keep headings clear of the sticky top bar */

.banner {
    display: flex; gap: 14px; align-items: center;
    padding: 14px 18px; margin-bottom: 16px;
    border-color: rgba(255, 107, 107, .45);
    background: linear-gradient(160deg, rgba(127, 29, 29, .55), rgba(30, 10, 40, .6));
}
.banner strong { display: block; color: #fecaca; }
.banner span { color: #fde2e2; font-size: 14px; }
.banner-icon { font-size: 26px; }

.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; align-items: end; padding: 18px; margin-bottom: 16px; }
.filters .actions { flex-wrap: nowrap; }
fieldset.field { border: 0; gap: 10px; }

.badge.muted { color: var(--muted); background: rgba(255, 255, 255, .06); border-color: var(--line); }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 -6px; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
th { text-align: left; color: var(--faint); font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; padding: 0 10px 10px; white-space: nowrap; }
td { padding: 12px 10px; border-top: 1px solid var(--line); vertical-align: top; }
tbody tr { transition: background .15s; }
tbody tr:hover td { background: rgba(255, 255, 255, .035); }
td.mono, .mono { font-family: var(--mono); font-size: 13px; color: var(--muted); }
td time { white-space: nowrap; }

details summary { cursor: pointer; color: var(--sky-blue); font-size: 13px; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary::before { content: "▸ "; }
details[open] summary::before { content: "▾ "; }
pre.code {
    margin-top: 8px;
    padding: 12px 14px;
    max-width: 520px;
    overflow-x: auto;
    border-radius: 12px;
    background: rgba(0, 0, 0, .35);
    border: 1px solid var(--line);
    font: 12.5px/1.55 var(--mono);
    color: #c7d7f5;
}

/* ------------------------------------------------------------------ */
/* Forms                                                               */
/* ------------------------------------------------------------------ */
form { display: grid; gap: 16px; }
.field { display: grid; gap: 7px; }
.field > span { font-size: 13px; font-weight: 550; color: var(--muted); }
.field small { color: var(--faint); font-size: 12px; }

select,
input:not([type="checkbox"]):not([type="hidden"]) {
    width: 100%;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, .14);
    background: rgba(255, 255, 255, .06);
    color: var(--text);
    font: inherit;
    transition: border-color .2s, box-shadow .2s, background .2s;
}
input::placeholder { color: var(--faint); }
select:focus,
input:not([type="checkbox"]):focus {
    outline: none;
    border-color: rgba(96, 165, 250, .8);
    background: rgba(255, 255, 255, .09);
    box-shadow: 0 0 0 4px rgba(10, 132, 255, .22);
}
input:-webkit-autofill, input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--text);
    -webkit-box-shadow: 0 0 0 1000px #13284d inset;
    caret-color: var(--text);
}
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--blue); }
.check { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }

.btn, button {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 11px 22px;
    border: 0;
    border-radius: 999px;
    font: 600 15px/1.2 var(--font);
    color: #fff;
    cursor: pointer;
    background: linear-gradient(180deg, #3d9bff, #0a6cff);
    box-shadow: 0 10px 24px -10px rgba(10, 132, 255, .9), inset 0 1px 0 rgba(255, 255, 255, .35);
    transition: transform .15s, filter .2s, box-shadow .2s;
}
.btn:hover, button:hover { filter: brightness(1.1); color: #fff; }
.btn:active, button:active { transform: scale(.98); }
.btn-ghost, button.btn-ghost {
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    background: rgba(255, 255, 255, .08);
    border: 1px solid rgba(255, 255, 255, .12);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .1);
}
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.error {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    color: #fecaca;
    background: rgba(255, 107, 107, .13);
    border: 1px solid rgba(255, 107, 107, .3);
}

/* Users */
.user-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.user-row:first-child { border-top: 0; padding-top: 0; }
.avatar {
    width: 36px; height: 36px; flex: none;
    display: grid; place-items: center;
    border-radius: 50%;
    font-weight: 700; text-transform: uppercase;
    background: linear-gradient(135deg, #38bdf8, #6366f1);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35);
}
.user-row .who { flex: 1; min-width: 0; }
.user-row .who .mono { display: block; }

/* ------------------------------------------------------------------ */
/* Login                                                               */
/* ------------------------------------------------------------------ */
.login-page .container { display: grid; place-items: center; margin-top: 0; }
.login-card { width: min(400px, 100%); padding: 34px 30px 30px; margin-top: 10vh; }
.login-card .logo { width: 58px; height: 58px; margin: 0 auto 14px; display: block; }
.login-card h1 { text-align: center; font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.login-card .hint { text-align: center; margin: 4px 0 24px; }
.login-card button { width: 100%; margin-top: 4px; }

.foot { text-align: center; color: var(--faint); font-size: 12px; padding: 0 16px calc(20px + env(safe-area-inset-bottom)); }

/* ------------------------------------------------------------------ */
/* Small screens                                                       */
/* ------------------------------------------------------------------ */
@media (max-width: 720px) {
    .topbar { flex-wrap: wrap; border-radius: 24px; padding: 10px 12px; row-gap: 10px; }
    .segmented { order: 3; width: 100%; margin: 0; }
    .segmented a { flex: 1; text-align: center; padding: 7px 10px; }
    .topbar .btn-ghost { margin-left: auto; }
    .container { margin-top: 24px; width: calc(100% - 24px); }
    .panel { padding: 18px 16px; }
    .stat .value { font-size: 28px; }
    .grid.stats { grid-template-columns: repeat(2, 1fr); gap: 12px; }
    .filters { grid-template-columns: 1fr 1fr; gap: 10px; padding: 14px; }
    .filters .actions { grid-column: 1 / -1; }
    .list li { grid-template-columns: 1fr auto; }
    .list .msg { grid-column: 1 / -1; order: 2; }
    .list .sub { grid-column: 1 / -1; order: 3; }
    .ridge.far { height: 22vh; }
    .ridge.mid { height: 20vh; }
    .ridge.near { height: 17vh; }
}
