/* ============================================================
 * Sleepy · Default Theme · main.css
 * 设计 token、全局重置、通用组件、前台布局
 * 同时被 index.html / login.html / panel.html 引用
 * ============================================================ */

/* ---------- design tokens (shared, layout/motion only) ---------- */
:root {
    /* ===== Dala design tokens (per DESIGN.md) ===== */
    /* color */
    --color-void: #000000;
    --color-bone: #ffffff;
    --color-ash: #bdbdbd;
    --color-smoke: #9a9a9a;
    --color-plum-voltage: #8052ff;
    --color-amber-spark: #ffb829;
    --color-lichen: #15846e;

    /* radius — never below 24px on interactive elements */
    --r-xs: 16px;
    --r-sm: 18px;
    --r-md: 24px;
    --r-lg: 24px;
    --r-pill: 999px;

    /* motion */
    --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
    --t-fast: 140ms;
    --t-mid: 220ms;
    --t-slow: 380ms;

    /* brand accent is a single flat color — no gradients per spec */
    --accent-grad: var(--color-plum-voltage);
    --accent-grad-soft: rgba(128, 82, 255, 0.16);
}

/* ===== Single void theme — light/dark toggles collapse to one canvas ===== */
:root,
:root[data-theme="dark"],
:root[data-theme="light"],
:root:not([data-theme]) {
    color-scheme: dark;

    --bg-base: #000000;
    --bg-elev-1: rgba(255, 255, 255, 0.02);
    --bg-elev-2: rgba(255, 255, 255, 0.03);
    --bg-input: rgba(255, 255, 255, 0.03);
    --hairline: rgba(255, 255, 255, 0.10);
    --hairline-strong: rgba(255, 255, 255, 0.20);
    --inner-highlight: transparent;

    --text-primary: #ffffff;   /* bone */
    --text-secondary: #bdbdbd;  /* ash */
    --text-tertiary: #9a9a9a;   /* smoke */
    --text-muted: #6b6b6b;

    --accent: #8052ff;
    --accent-soft: rgba(128, 82, 255, 0.16);
    --accent-strong: #a386ff;

    --ok: #34d6a4;
    --ok-soft: rgba(52, 214, 164, 0.13);
    --warn: #ffb829;
    --warn-soft: rgba(255, 184, 41, 0.13);
    --danger: #ff5d7a;
    --danger-soft: rgba(255, 93, 122, 0.13);
    --info: #8052ff;
    --info-soft: rgba(128, 82, 255, 0.13);

    /* legacy refs (kept harmless) */
    --page-bg-spot-a: rgba(128, 82, 255, 0.18);
    --page-bg-spot-b: rgba(255, 184, 41, 0.08);
    --page-bg-spot-c: rgba(21, 132, 110, 0.08);
    --page-bg-base-top: #000000;
    --page-bg-base-bottom: #000000;
    --page-bg-blend: normal;

    --surface-faint: rgba(255, 255, 255, 0.02);
    --surface-subtle: rgba(255, 255, 255, 0.03);
    --surface-soft: rgba(255, 255, 255, 0.05);
    --surface-medium: rgba(255, 255, 255, 0.08);
    --surface-strong: rgba(255, 255, 255, 0.14);
    --card-bg: rgba(255, 255, 255, 0.02);
    --card-bg-strong: rgba(255, 255, 255, 0.04);
    --scrollbar-thumb: rgba(255, 255, 255, 0.12);
    --scrollbar-thumb-hover: rgba(255, 255, 255, 0.22);

    /* bg-stage spot palette (unused by particle field, kept for safety) */
    --spot-1: rgba(128, 82, 255, 0.4);
    --spot-2: rgba(255, 184, 41, 0.25);
    --spot-3: rgba(21, 132, 110, 0.25);
    --spot-4: rgba(128, 82, 255, 0.3);
    --spot-blur: 90px;
    --spot-opacity: 0.5;
    --grain-opacity: 0;

    /* no shadows, no elevation, no glow — depth via contrast + particle field */
    --shadow-sm: none;
    --shadow-md: none;
    --shadow-lg: none;
}

/* ---------- reset ---------- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
}

body {
    font-family: 'Space Grotesk', 'PingFang SC', 'Microsoft YaHei', system-ui, -apple-system, sans-serif;
    font-size: 14.5px;
    line-height: 1.55;
    color: var(--text-primary);
    background: var(--bg-base);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* ============================================================
 * Background stage — independent fixed layer with drifting spots
 * - 完全独立于 body，有自己的 paint layer，滚动时 GPU 合成
 * - 4 个 spot 用 transform animation 漂移（GPU 友好）
 * - 主题切换时 background 颜色 + spot 颜色都跟着变
 * ============================================================ */
.bg-stage {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
    background: #000000;
}

/* Particle constellation owns the canvas; legacy orb/aurora/mesh spots removed */
.bg-spot,
.bg-grain {
    display: none !important;
}

.particle-field {
    position: fixed;
    inset: 0;
    z-index: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: block;
}

.bg-spot {
    position: absolute;
    border-radius: 50%;
    filter: blur(var(--spot-blur));
    opacity: var(--spot-opacity);
    will-change: transform;
    transition: background 600ms var(--ease), opacity 600ms var(--ease);
}

.bg-spot-1 {
    width: 55vmax;
    height: 55vmax;
    left: -12vmax;
    top: -12vmax;
    background: radial-gradient(circle, var(--spot-1), transparent 70%);
    animation: spot-drift-1 22s var(--ease) infinite alternate;
}

.bg-spot-2 {
    width: 42vmax;
    height: 42vmax;
    right: -10vmax;
    top: -8vmax;
    background: radial-gradient(circle, var(--spot-2), transparent 70%);
    animation: spot-drift-2 26s var(--ease) infinite alternate;
}

.bg-spot-3 {
    width: 60vmax;
    height: 60vmax;
    left: 18vw;
    bottom: -22vmax;
    background: radial-gradient(circle, var(--spot-3), transparent 70%);
    animation: spot-drift-3 30s var(--ease) infinite alternate;
}

.bg-spot-4 {
    width: 38vmax;
    height: 38vmax;
    right: -6vmax;
    bottom: 8vmax;
    background: radial-gradient(circle, var(--spot-4), transparent 70%);
    animation: spot-drift-4 34s var(--ease) infinite alternate;
}

@keyframes spot-drift-1 {
    0% { transform: translate3d(0, 0, 0) scale(1); }
    100% { transform: translate3d(8vw, 6vh, 0) scale(1.12); }
}

@keyframes spot-drift-2 {
    0% { transform: translate3d(0, 0, 0) scale(1); }
    100% { transform: translate3d(-6vw, 9vh, 0) scale(1.18); }
}

@keyframes spot-drift-3 {
    0% { transform: translate3d(0, 0, 0) scale(1); }
    100% { transform: translate3d(-10vw, -8vh, 0) scale(1.08); }
}

@keyframes spot-drift-4 {
    0% { transform: translate3d(0, 0, 0) scale(1); }
    100% { transform: translate3d(7vw, -6vh, 0) scale(1.15); }
}

/* ============================================================
 * BG variant: AURORA — 纵向流动光柱 (Northern Lights)
 * 复用同样 4 个 .bg-spot 元素，只覆盖样式
 * ============================================================ */
:root[data-bg="aurora"] .bg-spot {
    border-radius: 0;
    filter: blur(80px);
}

:root[data-bg="aurora"] .bg-spot-1 {
    width: 32vw;
    height: 130vh;
    left: -8vw;
    top: -15vh;
    background: linear-gradient(180deg, transparent 0%, var(--spot-1) 35%, var(--spot-1) 65%, transparent 100%);
    animation: aurora-1 16s var(--ease) infinite alternate;
}

:root[data-bg="aurora"] .bg-spot-2 {
    width: 26vw;
    height: 130vh;
    left: 28vw;
    top: -10vh;
    right: auto;
    background: linear-gradient(180deg, transparent 0%, var(--spot-2) 40%, transparent 100%);
    animation: aurora-2 20s var(--ease) infinite alternate;
}

:root[data-bg="aurora"] .bg-spot-3 {
    width: 30vw;
    height: 130vh;
    left: 55vw;
    top: -12vh;
    bottom: auto;
    background: linear-gradient(180deg, transparent 0%, var(--spot-3) 50%, var(--spot-3) 70%, transparent 100%);
    animation: aurora-3 24s var(--ease) infinite alternate;
}

:root[data-bg="aurora"] .bg-spot-4 {
    width: 28vw;
    height: 130vh;
    left: auto;
    right: -6vw;
    top: -10vh;
    bottom: auto;
    background: linear-gradient(180deg, transparent 0%, var(--spot-4) 45%, transparent 100%);
    animation: aurora-4 28s var(--ease) infinite alternate;
}

@keyframes aurora-1 {
    0% { transform: translate3d(0, 0, 0) skewX(-2deg); }
    100% { transform: translate3d(12vw, 4vh, 0) skewX(3deg); }
}

@keyframes aurora-2 {
    0% { transform: translate3d(0, 0, 0) skewX(2deg); }
    100% { transform: translate3d(-8vw, 6vh, 0) skewX(-3deg); }
}

@keyframes aurora-3 {
    0% { transform: translate3d(0, 0, 0) skewX(-3deg); }
    100% { transform: translate3d(10vw, -5vh, 0) skewX(2deg); }
}

@keyframes aurora-4 {
    0% { transform: translate3d(0, 0, 0) skewX(2deg); }
    100% { transform: translate3d(-10vw, 5vh, 0) skewX(-2deg); }
}

/* ============================================================
 * BG variant: MESH — 慢速旋转的彩色网格
 * 让 spot-1 接管全屏多重 radial-gradient 网格点阵；其他 spot 隐藏
 * ============================================================ */
:root[data-bg="mesh"] .bg-spot-2,
:root[data-bg="mesh"] .bg-spot-3,
:root[data-bg="mesh"] .bg-spot-4 {
    display: none;
}

:root[data-bg="mesh"] .bg-spot-1 {
    width: 140vmax;
    height: 140vmax;
    left: -20vmax;
    top: -20vmax;
    border-radius: 50%;
    filter: blur(70px);
    background:
        radial-gradient(circle at 18% 22%, var(--spot-1), transparent 14%),
        radial-gradient(circle at 78% 30%, var(--spot-2), transparent 18%),
        radial-gradient(circle at 32% 70%, var(--spot-3), transparent 16%),
        radial-gradient(circle at 82% 78%, var(--spot-4), transparent 16%),
        radial-gradient(circle at 50% 50%, var(--spot-1), transparent 12%);
    animation: mesh-rotate 80s linear infinite;
}

@keyframes mesh-rotate {
    0% { transform: rotate(0deg) scale(1); }
    50% { transform: rotate(180deg) scale(1.05); }
    100% { transform: rotate(360deg) scale(1); }
}

/* very faint grain overlay for analog feel */
.bg-grain {
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.45 0'/></filter><rect width='100%' height='100%' filter='url(%23n)' opacity='0.6'/></svg>");
    opacity: var(--grain-opacity);
    mix-blend-mode: overlay;
    pointer-events: none;
}

/* respect reduced-motion */
@media (prefers-reduced-motion: reduce) {
    .bg-spot {
        animation: none !important;
    }
    .bg-stage,
    .bg-spot {
        transition: none !important;
    }
}

/* ============================================================
 * Theme toggle button
 * ============================================================ */
.theme-toggle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-elev-2);
    border: 1px solid var(--hairline);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    flex-shrink: 0;
    transition: color var(--t-fast) var(--ease),
                background var(--t-fast) var(--ease),
                transform var(--t-fast) var(--ease),
                border-color var(--t-fast) var(--ease);
}

.theme-toggle:hover {
    color: var(--text-primary);
    border-color: var(--hairline-strong);
    transform: scale(1.06);
}

.theme-toggle:active {
    transform: scale(0.96);
}

.theme-toggle .theme-icon {
    display: none;
    width: 18px;
    height: 18px;
}

:root[data-theme="dark"] .theme-toggle .theme-icon-sun {
    display: block;
}

:root[data-theme="light"] .theme-toggle .theme-icon-moon,
:root:not([data-theme]) .theme-toggle .theme-icon-sun {
    display: block;
}

.theme-toggle.floating {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 50;
}

/* ============================================================
 * Background toggle button — 共用 theme-toggle 圆按钮样式
 * 3 个 SVG 图标按当前 data-bg 互斥显示
 * ============================================================ */
.bg-toggle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-elev-2);
    border: 1px solid var(--hairline);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    flex-shrink: 0;
    transition: color var(--t-fast) var(--ease),
                background var(--t-fast) var(--ease),
                transform var(--t-fast) var(--ease),
                border-color var(--t-fast) var(--ease);
}

.bg-toggle:hover {
    color: var(--text-primary);
    border-color: var(--hairline-strong);
    transform: scale(1.06);
}

.bg-toggle:active {
    transform: scale(0.96);
}

.bg-toggle .bg-icon {
    display: none;
    width: 18px;
    height: 18px;
}

:root[data-bg="orbs"] .bg-toggle .bg-icon-orbs,
:root:not([data-bg]) .bg-toggle .bg-icon-orbs {
    display: block;
}

:root[data-bg="aurora"] .bg-toggle .bg-icon-aurora {
    display: block;
}

:root[data-bg="mesh"] .bg-toggle .bg-icon-mesh {
    display: block;
}

.bg-toggle.floating {
    position: fixed;
    top: 18px;
    right: 64px;
    z-index: 50;
}

a {
    color: inherit;
    text-decoration: none;
    transition: color var(--t-fast) var(--ease);
}

a:hover {
    color: var(--accent-strong);
}

button,
input,
textarea,
select {
    font: inherit;
    color: inherit;
    background: transparent;
    border: none;
    outline: none;
}

button {
    cursor: pointer;
}

button:disabled,
button.disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: var(--r-pill);
    border: 2px solid transparent;
    background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
    background-clip: padding-box;
    border: 2px solid transparent;
}

/* ---------- typography helpers ---------- */
h1,
h2,
h3,
h4 {
    font-weight: 500;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

h1 {
    font-size: 28px;
    line-height: 1.2;
}

h2 {
    font-size: 20px;
    line-height: 1.3;
}

h3 {
    font-size: 16px;
}

.eyebrow {
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--text-tertiary);
    margin-bottom: 12px;
}

.muted-text {
    color: var(--text-secondary);
}

.hint-text {
    font-size: 12.5px;
    color: var(--text-tertiary);
    line-height: 1.6;
}

.text-danger {
    color: var(--danger);
}

/* ---------- legacy ambient nodes (kept harmless if templates still emit them) ---------- */
.ambient {
    display: none;
}

/* ---------- glass panel base ----------
 * NOTE: backdrop-filter 仅保留在少数（topbar / login-card）以保住"玻璃质感"，
 * 普通卡片改用纯 alpha 背景，避免滚动时多处 blur 同时重绘导致卡顿。
 */
.glass,
.glass-card,
.glass-dashboard {
    position: relative;
    background: var(--card-bg);
    border: 1px solid var(--hairline);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-md), inset 0 1px 0 var(--inner-highlight);
}

/* ---------- buttons ---------- */
.glass-button,
.dashboard-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 38px;
    padding: 0 18px;
    border-radius: var(--r-pill);
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--surface-subtle);
    border: 1px solid var(--hairline-strong);
    transition: transform var(--t-fast) var(--ease),
                background var(--t-fast) var(--ease),
                border-color var(--t-fast) var(--ease),
                box-shadow var(--t-fast) var(--ease);
    white-space: nowrap;
}

.glass-button:hover,
.dashboard-btn:hover {
    background: var(--surface-medium);
    border-color: var(--surface-strong);
    transform: translateY(-1px);
}

.glass-button:active,
.dashboard-btn:active {
    transform: translateY(0);
}

.glass-button.primary,
.dashboard-btn.primary {
    background: var(--color-plum-voltage);
    color: var(--color-bone);
    border-color: transparent;
    font-weight: 600;
}

.glass-button.primary:hover,
.dashboard-btn.primary:hover {
    background: #9268ff;
}

.glass-button.secondary,
.dashboard-btn.secondary {
    background: var(--surface-subtle);
    color: var(--text-primary);
}

.dashboard-btn.danger {
    background: var(--danger-soft);
    border-color: var(--danger);
    color: var(--danger);
}

.dashboard-btn.danger:hover {
    background: rgba(255, 107, 138, 0.28);
    border-color: rgba(255, 107, 138, 0.55);
}

.dashboard-btn.warn {
    background: var(--warn-soft);
    border-color: var(--warn);
    color: var(--warn);
}

.dashboard-btn.warn:hover {
    background: rgba(246, 193, 119, 0.28);
    border-color: rgba(246, 193, 119, 0.55);
}

.dashboard-btn.fun {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent-strong);
}

.dashboard-btn.fun:hover {
    background: rgba(124, 92, 255, 0.28);
    border-color: rgba(124, 92, 255, 0.55);
}

.dashboard-btn.soft-danger {
    background: var(--danger-soft);
    border-color: var(--danger);
    color: var(--danger);
}

.dashboard-btn.wide {
    width: 100%;
}

.mini-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 30px;
    padding: 0 12px;
    border-radius: var(--r-pill);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--surface-subtle);
    border: 1px solid var(--hairline-strong);
    transition: background var(--t-fast) var(--ease),
                border-color var(--t-fast) var(--ease),
                transform var(--t-fast) var(--ease);
}

.mini-btn:hover {
    background: var(--surface-medium);
    border-color: var(--surface-strong);
    transform: translateY(-1px);
}

.mini-btn.fun {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent-strong);
}

.mini-btn.fun:hover {
    background: rgba(124, 92, 255, 0.30);
    border-color: rgba(124, 92, 255, 0.55);
}

.mini-btn.warn {
    background: var(--warn-soft);
    border-color: var(--warn);
    color: var(--warn);
}

.mini-btn.warn:hover {
    background: rgba(246, 193, 119, 0.28);
}

.mini-btn.danger {
    background: var(--danger-soft);
    border-color: var(--danger);
    color: var(--danger);
}

.mini-btn.danger:hover {
    background: rgba(255, 107, 138, 0.28);
}

.mini-btn.subtle {
    background: transparent;
    border-color: var(--hairline);
    color: var(--text-secondary);
}

.mini-btn.subtle:hover {
    color: var(--text-primary);
    background: var(--surface-soft);
    border-color: var(--hairline-strong);
}

/* ---------- chip / pill ---------- */
.chip,
.capability-chip,
.sub-pill,
.theme-pill,
.state-pill,
.state-chip,
.status-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--r-pill);
    font-size: 11.5px;
    font-weight: 500;
    line-height: 1;
    color: var(--text-secondary);
    background: var(--surface-subtle);
    border: 1px solid var(--hairline);
    white-space: nowrap;
}

.chip.green,
.capability-chip.active,
.state-pill.green,
.state-chip.green {
    color: var(--ok);
    background: var(--ok-soft);
    border-color: rgba(62, 255, 193, 0.28);
}

.chip.blue,
.capability-chip.remote,
.capability-chip.message {
    color: var(--info);
    background: var(--info-soft);
    border-color: rgba(110, 193, 255, 0.28);
}

.chip.orange,
.state-pill.orange {
    color: var(--warn);
    background: var(--warn-soft);
    border-color: rgba(246, 193, 119, 0.28);
}

.chip.rose,
.capability-chip.stale,
.state-pill.stale,
.state-chip.stale {
    color: var(--danger);
    background: var(--danger-soft);
    border-color: rgba(255, 107, 138, 0.28);
}

.capability-chip.media {
    color: var(--ok);
    background: var(--ok-soft);
    border-color: rgba(62, 255, 193, 0.22);
}

.chip.violet,
.capability-chip.kind {
    color: var(--color-plum-voltage, #8052ff);
    background: rgba(128, 82, 255, 0.12);
    border-color: rgba(128, 82, 255, 0.30);
}

.theme-pill {
    color: var(--text-secondary);
    background: rgba(124, 92, 255, 0.08);
    border-color: rgba(124, 92, 255, 0.22);
    transition: all var(--t-fast) var(--ease);
}

.theme-pill:hover {
    color: var(--text-primary);
    background: rgba(124, 92, 255, 0.18);
    border-color: rgba(124, 92, 255, 0.4);
}

.status-chip {
    align-self: flex-start;
}

/* ---------- form fields ---------- */
.field-label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 6px;
}

.field-input {
    display: block;
    width: 100%;
    padding: 10px 14px;
    border-radius: var(--r-sm);
    background: var(--bg-input);
    border: 1px solid var(--hairline-strong);
    color: var(--text-primary);
    font-size: 13.5px;
    transition: border-color var(--t-fast) var(--ease),
                background var(--t-fast) var(--ease),
                box-shadow var(--t-fast) var(--ease);
}

.field-input::placeholder {
    color: var(--text-muted);
}

.field-input:focus {
    border-color: rgba(124, 92, 255, 0.55);
    background: rgba(15, 18, 26, 0.92);
    box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.18);
}

.field-textarea {
    min-height: 96px;
    resize: vertical;
    font-family: inherit;
    line-height: 1.55;
}

select.field-input {
    appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='%23aab2c2' d='M5 6 0 0h10z'/></svg>");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 38px;
}

select.field-input option {
    background: #11141d;
    color: var(--text-primary);
}

/* ---------- toggle switch ---------- */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--surface-medium);
    border: 1px solid var(--hairline-strong);
    border-radius: var(--r-pill);
    transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
    cursor: pointer;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    transition: transform var(--t-fast) var(--ease);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--accent-grad);
    border-color: transparent;
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

/* ============================================================
 * Front page (index.html / .front-page)
 * ============================================================ */

.front-page {
    position: relative;
    z-index: 1;
}

.front-shell {
    position: relative;
    z-index: 2;
    max-width: 1200px;
    margin: 0 auto;
    padding: 72px 28px 96px;
}

.front-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    gap: 24px;
    align-items: start;
}

.front-grid > .card-main {
    grid-column: 1 / 2;
}

.front-grid > .card-side {
    grid-column: 2 / 3;
    position: sticky;
    top: 24px;
}

.front-closed-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding-top: 48px;
    padding-bottom: 48px;
}

.front-closed-grid {
    width: min(100%, 720px);
}

.front-closed-card {
    position: relative;
    overflow: hidden;
    min-height: 330px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.front-closed-card::after {
    content: "";
    position: absolute;
    width: 220px;
    height: 220px;
    right: -100px;
    top: -105px;
    border: 1px solid rgba(169, 139, 255, 0.22);
    border-radius: 50%;
    box-shadow:
        0 0 0 28px rgba(169, 139, 255, 0.03),
        0 0 80px rgba(128, 82, 255, 0.1);
    pointer-events: none;
}

.front-closed-kicker {
    margin: 0 0 16px;
    color: var(--text-tertiary);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.2em;
    text-transform: uppercase;
}

.front-closed-card h1 {
    max-width: 560px;
    margin: 0;
    color: var(--text-primary);
    font-size: clamp(34px, 7vw, 64px);
    font-weight: 650;
    letter-spacing: -0.045em;
    line-height: 1.02;
}

.front-closed-rule {
    width: 76px;
    height: 2px;
    margin: 28px 0 22px;
    background: linear-gradient(90deg, var(--plum-hi), rgba(169, 139, 255, 0));
}

.front-closed-message {
    max-width: 580px;
    margin: 0;
    color: var(--text-secondary);
    font-size: clamp(16px, 2.2vw, 20px);
    line-height: 1.8;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

@media (max-width: 960px) {
    .front-shell {
        padding: 36px 18px 64px;
    }

    .front-grid {
        grid-template-columns: 1fr;
    }

    .front-grid > .card-main,
    .front-grid > .card-side {
        grid-column: 1 / 2;
        position: static;
    }
}

.glass-card {
    padding: 30px 32px;
}

@media (max-width: 720px) {
    .glass-card {
        padding: 22px 20px;
    }
}

/* ----- live hero (main.index.html) ----- */
.live-stage {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.live-hero {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
    gap: 24px;
    align-items: stretch;
}

@media (max-width: 720px) {
    .live-hero {
        grid-template-columns: 1fr;
    }
}

.hero-story h1 {
    margin: 8px 0 18px;
    font-size: clamp(40px, 6vw, 72px);
    font-weight: 300;
    line-height: 0.95;
    letter-spacing: -0.035em;
}

.hero-text {
    color: var(--text-secondary);
    font-size: 15px;
    line-height: 1.7;
    max-width: 46ch;
}

.hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 22px;
}

.status-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 22px;
    border-radius: var(--r-md);
    background: var(--surface-subtle);
    border: 1px solid var(--hairline);
}

.status-panel #status,
.status-panel strong {
    font-size: 44px;
    font-weight: 300;
    letter-spacing: -0.03em;
    line-height: 1;
    color: var(--text-primary);
}

.status-panel #status.awake,
.status-panel #status.online {
    color: var(--ok);
}

.status-panel #status.sleeping {
    color: var(--info);
}

.status-panel #status.error {
    color: var(--danger);
}

.status-copy {
    color: var(--text-secondary);
    font-size: 13.5px;
    line-height: 1.65;
}

.signal-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.signal-card {
    padding: 14px 16px;
    border-radius: var(--r-md);
    background: var(--surface-subtle);
    border: 1px solid var(--hairline);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.signal-label {
    font-size: 11.5px;
    color: var(--text-tertiary);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.signal-card strong {
    font-size: 15px;
    color: var(--text-primary);
    word-break: break-word;
}

/* ----- device showcase ----- */
.device-showcase {
    margin-top: 28px;
}

.section-heading-block {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 20px;
}

.section-heading-block h2 {
    margin-top: 4px;
}

.section-intro {
    color: var(--text-secondary);
    font-size: 13px;
    max-width: 36ch;
    text-align: right;
}

@media (max-width: 720px) {
    .section-heading-block {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .section-intro {
        text-align: left;
    }
}

.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr));
    gap: 14px;
}

.device-card {
    position: relative;
    padding: 16px 18px;
    background: var(--card-bg);
    border: 1px solid var(--hairline);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-sm), inset 0 1px 0 var(--inner-highlight);
    transition: transform var(--t-fast) var(--ease),
                border-color var(--t-fast) var(--ease),
                box-shadow var(--t-fast) var(--ease);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.device-card:hover {
    transform: translateY(-2px);
    border-color: rgba(128, 82, 255, 0.45);
}

.device-card.is-idle {
    opacity: 0.85;
}

.device-card.is-stale {
    opacity: 0.6;
}

.device-card-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
}

.device-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.device-subline {
    font-size: 11.5px;
    color: var(--text-tertiary);
    margin-top: 4px;
    word-break: break-all;
}

.device-primary-status {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.55;
    padding: 12px 14px;
    border-radius: var(--r-sm);
    background: var(--surface-subtle);
    border: 1px solid var(--hairline);
}

.device-primary-status.is-stale {
    color: var(--text-tertiary);
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.device-head-id {
    min-width: 0;
    flex: 1;
}

.device-kind-tag {
    display: inline-block;
    margin-left: 8px;
    padding: 1px 8px;
    border-radius: var(--r-pill);
    background: rgba(128, 82, 255, 0.14);
    border: 1px solid rgba(128, 82, 255, 0.30);
    color: var(--color-plum-voltage, #8052ff);
    font-size: 10.5px;
    font-weight: 600;
    vertical-align: middle;
}

.device-metrics {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 8px;
}

.device-metrics .metric {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    max-width: 100%;
    padding: 5px 10px;
    border-radius: var(--r-pill);
    background: var(--surface-faint);
    border: 1px solid var(--hairline);
    font-size: 12px;
    line-height: 1.3;
    min-width: 0;
}

.device-metrics .mk {
    color: var(--text-tertiary);
    font-size: 10.5px;
    letter-spacing: 0.04em;
    flex: none;
}

.device-metrics .mv {
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.media-panel {
    padding: 10px 12px;
    border-radius: var(--r-sm);
    background: rgba(110, 193, 255, 0.04);
    border: 1px solid rgba(110, 193, 255, 0.16);
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.media-panel.guard-panel {
    background: rgba(124, 92, 255, 0.05);
    border-color: rgba(124, 92, 255, 0.18);
}

.media-panel.is-stale {
    opacity: 0.55;
}

.media-title {
    font-size: 11px;
    letter-spacing: 0.06em;
    color: var(--text-tertiary);
    flex: none;
}

.media-value {
    font-size: 13px;
    color: var(--text-primary);
    line-height: 1.4;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.media-panel.guard-panel {
    display: block;
}

.guard-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 4px;
}

.guard-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.guard-label {
    font-size: 10.5px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.guard-value {
    font-size: 13px;
    color: var(--text-primary);
}

.guard-value.danger {
    color: var(--danger);
}

.guard-errors {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
}

/* ----- briefing rail (more_info.index.html) ----- */
.briefing-rail {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
    backdrop-filter: none;
}

.rail-card {
    padding: 22px 22px;
    border-radius: var(--r-lg);
    background: var(--card-bg);
    border: 1px solid var(--hairline);
    box-shadow: var(--shadow-sm), inset 0 1px 0 var(--inner-highlight);
}

.rail-card h3 {
    margin: 4px 0 10px;
}

.rail-copy {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.7;
}

.rail-copy a {
    color: var(--accent-strong);
    border-bottom: 1px dashed rgba(124, 92, 255, 0.4);
}

.rail-copy a:hover {
    color: var(--accent-strong);
}

.rail-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.rail-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-radius: var(--r-sm);
    background: var(--surface-subtle);
    border: 1px solid var(--hairline);
    color: var(--text-primary);
    font-size: 13px;
    transition: all var(--t-fast) var(--ease);
}

.rail-link::after {
    content: '→';
    color: var(--text-tertiary);
    font-size: 14px;
    transition: transform var(--t-fast) var(--ease);
}

.rail-link:hover {
    border-color: rgba(124, 92, 255, 0.35);
    background: rgba(124, 92, 255, 0.06);
    color: var(--text-primary);
}

.rail-link:hover::after {
    transform: translateX(4px);
    color: var(--accent-strong);
}

.theme-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.rail-note {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
    border-radius: var(--r-md);
    background: rgba(124, 92, 255, 0.05);
    border: 1px solid rgba(124, 92, 255, 0.16);
    color: var(--text-secondary);
    font-size: 12.5px;
    line-height: 1.6;
}

.rail-note-dot {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-plum-voltage);
    margin-top: 6px;
}

/* ============================================================
 * Device search / filter / pagination
 * ============================================================ */

.device-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-top: 16px;
}

.search-box {
    position: relative;
    flex: 1;
    min-width: 220px;
    max-width: 420px;
}

.search-box svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--text-tertiary);
    pointer-events: none;
    transition: color var(--t-fast) var(--ease);
}

.search-box:focus-within svg {
    color: var(--accent);
}

.search-input {
    width: 100%;
    height: 38px;
    padding: 0 14px 0 38px;
    border-radius: var(--r-pill);
    border: 1px solid var(--hairline);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 13.5px;
    font-family: inherit;
    outline: none;
    transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.filter-select {
    height: 38px;
    padding: 0 32px 0 12px;
    border-radius: var(--r-pill);
    border: 1px solid var(--hairline);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236f7889' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    transition: border-color var(--t-fast) var(--ease);
}

.filter-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.filter-select option {
    background: var(--bg-elev-2);
    color: var(--text-primary);
}

.device-count-badge {
    display: inline-flex;
    align-items: center;
    height: 30px;
    padding: 0 12px;
    border-radius: var(--r-pill);
    background: var(--surface-subtle);
    border: 1px solid var(--hairline);
    color: var(--text-secondary);
    font-size: 12.5px;
    white-space: nowrap;
}

/* pagination bar */
.pagination-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: center;
    margin-top: 20px;
    padding: 12px 0;
}

.pagination-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
    border-radius: var(--r-sm);
    border: 1px solid var(--hairline);
    background: var(--bg-input);
    color: var(--text-secondary);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--t-fast) var(--ease);
    user-select: none;
}

.pagination-btn:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent-strong);
    background: var(--accent-soft);
}

.pagination-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.pagination-btn.active {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}

.pagination-btn svg {
    width: 16px;
    height: 16px;
}

.pagination-ellipsis {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    color: var(--text-muted);
    font-size: 13px;
    user-select: none;
}

.per-page-select {
    height: 36px;
    padding: 0 28px 0 10px;
    border-radius: var(--r-sm);
    border: 1px solid var(--hairline);
    background: var(--bg-input);
    color: var(--text-secondary);
    font-size: 12.5px;
    font-family: inherit;
    outline: none;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%236f7889' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

.pagination-info {
    font-size: 12.5px;
    color: var(--text-muted);
    white-space: nowrap;
}

.empty-search-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}

.empty-search-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
    opacity: 0.4;
}

.empty-search-state p {
    font-size: 14px;
    margin: 0;
}

/* ============================================================
 * Modal / OTA Push
 * ============================================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, .72);
    padding: 24px;
}

.modal-overlay[hidden] {
    display: none;
}

.modal-card {
    background: #050505;
    border: 1px solid var(--hairline-strong);
    border-radius: var(--r-lg);
    max-width: 520px;
    width: 100%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: #e0e0e0;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #f0f0f0;
}

.modal-close-btn {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    transition: background .15s;
}

.modal-close-btn:hover {
    background: rgba(255, 255, 255, .08);
}

.modal-body {
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px 20px;
    border-top: 1px solid rgba(255, 255, 255, .08);
}

.ota-push-info {
    margin: 0 0 16px;
    font-size: 14px;
    color: #a0a0b8;
    line-height: 1.5;
}

.ota-push-actions-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.ota-device-checklist {
    max-height: 280px;
    overflow-y: auto;
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 12px;
    padding: 4px 0;
    background: rgba(0, 0, 0, .2);
}

.ota-device-check-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    cursor: pointer;
    transition: background .12s;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
}

.ota-device-check-item:last-child {
    border-bottom: none;
}

.ota-device-check-item:hover {
    background: rgba(255, 255, 255, .06);
}

.ota-device-check-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #6366f1;
    flex-shrink: 0;
    cursor: pointer;
}

.ota-device-check-label {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ota-device-check-name {
    font-size: 14px;
    font-weight: 500;
    color: #e8e8f0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ota-device-check-meta {
    font-size: 12px;
    color: #9090a8;
    display: flex;
    gap: 8px;
    align-items: center;
}

.ota-device-check-meta .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.ota-device-check-meta .dot.online {
    background: #22c55e;
}

.ota-device-check-meta .dot.idle {
    background: #f59e0b;
}

.ota-device-check-meta .dot.stale {
    background: #ef4444;
}

/* ============================================================
 * OTA device status
 * ============================================================ */

.ota-status-list .empty-state {
    text-align: center;
    padding: 16px;
    color: var(--text-secondary);
}

.ota-status-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: var(--hairline) solid var(--border-soft, #e5e7eb);
    font-size: 13px;
}

.ota-status-row:last-child {
    border-bottom: none;
}

.ota-status-device {
    font-weight: 500;
    color: var(--text-primary);
    min-width: 0;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ota-status-badge {
    font-size: 11px;
    padding: 2px 10px;
    border-radius: var(--r-pill);
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

.ota-clear-status-btn {
    flex-shrink: 0;
    padding: 4px;
    line-height: 1;
    border-radius: var(--r-sm);
    opacity: 0;
    transition: opacity 0.15s;
}
.ota-status-row:hover .ota-clear-status-btn {
    opacity: 0.5;
}
.ota-status-row:hover .ota-clear-status-btn:hover {
    opacity: 1;
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger, #ef4444);
}

.ota-status-badge.idle { background: #e5e7eb; color: #6b7280; }
.ota-status-badge.downloading { background: #dbeafe; color: #2563eb; }
.ota-status-badge.installing { background: #fef3c7; color: #d97706; }
.ota-status-badge.done { background: #d1fae5; color: #059669; }
.ota-status-badge.failed { background: #fee2e2; color: #dc2626; }
.ota-status-badge.rolled_back { background: #fce7f3; color: #be185d; }

.ota-status-msg {
    color: var(--text-secondary);
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex-shrink: 1;
}

/* ============================================================
 * Reduced motion
 * ============================================================ */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}
