@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
    --bg: #f5f3f0;
    --surface: #ffffff;
    --surface-2: #faf9f7;
    --surface-raised: #ffffff;
    --border: rgba(0, 0, 0, 0.05);
    --border-strong: rgba(0, 0, 0, 0.08);
    --text: #2d2d2d;
    --text-secondary: #6b6b6b;
    --text-dim: #a0a0a0;
    --ok: #34d399;
    --ok-bg: rgba(52, 211, 153, 0.12);
    --warning: #fbbf24;
    --warning-bg: rgba(251, 191, 36, 0.12);
    --critical: #f87171;
    --critical-bg: rgba(248, 113, 113, 0.1);
    --unreachable: #a1a1aa;
    --accent: #6366f1;
    --accent-light: #818cf8;
    --accent-bg: rgba(99, 102, 241, 0.08);
    --accent-bg-strong: rgba(99, 102, 241, 0.15);
    --mod-monitor: #6366f1;
    --mod-todos: #f59e0b;
    --mod-smarthome: #10b981;
    --mod-shopping: #f472b6;
    --mod-calendar: #3b82f6;
    --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', 'Cascadia Code', monospace;
    --radius: 16px;
    --radius-lg: 24px;
    --radius-sm: 12px;
    --radius-xs: 8px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.04), 0 2px 6px rgba(0,0,0,0.02);
    --shadow: 0 2px 8px rgba(0,0,0,0.05), 0 4px 20px rgba(0,0,0,0.03);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.06), 0 8px 32px rgba(0,0,0,0.04);
    --shadow-xl: 0 8px 24px rgba(0,0,0,0.08), 0 16px 48px rgba(0,0,0,0.05);
}

/* ── Dark Theme ── */
[data-theme="dark"] {
    --bg: #1a1a2e;
    --surface: #1e1e32;
    --surface-2: #252540;
    --surface-raised: #2a2a45;
    --border: rgba(255, 255, 255, 0.06);
    --border-strong: rgba(255, 255, 255, 0.1);
    --text: #e8e8ec;
    --text-secondary: #9a9ab0;
    --text-dim: #6b6b80;
    --ok: #34d399;
    --ok-bg: rgba(52, 211, 153, 0.15);
    --warning: #fbbf24;
    --warning-bg: rgba(251, 191, 36, 0.15);
    --critical: #f87171;
    --critical-bg: rgba(248, 113, 113, 0.15);
    --unreachable: #71717a;
    --accent: #818cf8;
    --accent-light: #a5b4fc;
    --accent-bg: rgba(129, 140, 248, 0.12);
    --accent-bg-strong: rgba(129, 140, 248, 0.2);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.2), 0 2px 6px rgba(0,0,0,0.15);
    --shadow: 0 2px 8px rgba(0,0,0,0.25), 0 4px 20px rgba(0,0,0,0.2);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.3), 0 8px 32px rgba(0,0,0,0.25);
    --shadow-xl: 0 8px 24px rgba(0,0,0,0.35), 0 16px 48px rgba(0,0,0,0.3);
    color-scheme: dark;
}
[data-theme="dark"] .badge-ok { color: #34d399; }
[data-theme="dark"] .badge-warning { color: #fbbf24; }
[data-theme="dark"] .badge-unreachable { color: #9ca3af; }
[data-theme="dark"] header,
[data-theme="dark"] .cal-header-bar { background: rgba(26, 26, 46, 0.85); }
[data-theme="dark"] .bottom-nav { background: rgba(26, 26, 46, 0.92); }
[data-theme="dark"] .cal-segment { background: rgba(255, 255, 255, 0.12); }
[data-theme="dark"] .cal-segment-slider { background: rgba(255, 255, 255, 0.2); box-shadow: none; }
[data-theme="dark"] .cal-segment-btn { color: rgba(255, 255, 255, 0.5); }
[data-theme="dark"] .cal-segment-btn.active { color: #fff; }
[data-theme="dark"] .cal-tl-col-weekend { background: rgba(255, 255, 255, 0.02); }
[data-theme="dark"] .log-source-nginx { color: #34d399; }
[data-theme="dark"] .log-source-php { color: #fbbf24; }
[data-theme="dark"] .nav-badge-dot { border-color: var(--bg); }
[data-theme="dark"] .login-page {
    background: radial-gradient(ellipse at 20% 50%, rgba(129,140,248,0.1) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(167,139,250,0.08) 0%, transparent 50%),
        var(--bg);
}

* {
    margin: 0; padding: 0; box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    line-height: 1.5;
    -webkit-user-select: none;
    user-select: none;
    overflow-x: hidden;
}
html { overflow-x: hidden; scroll-behavior: smooth; overscroll-behavior-y: contain; }

/* ── Native Feel Foundations ── */
body { touch-action: manipulation; -webkit-overflow-scrolling: touch; }

/* Page fade-in */
@keyframes pageIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}
main, .today-card, .page-content, .widget-grid, .quest-board, .shopping-list-wrap {
    animation: pageIn 0.25s ease-out;
}

/* Skeleton loading */
@keyframes skeletonPulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.8; }
}
.skeleton {
    background: var(--border-strong);
    border-radius: 6px;
    animation: skeletonPulse 1.2s ease-in-out infinite;
    color: transparent !important;
}
.skeleton-line {
    display: inline-block;
    height: 14px;
    width: 80px;
    background: var(--border-strong);
    border-radius: 4px;
    animation: skeletonPulse 1.2s ease-in-out infinite;
    vertical-align: middle;
}
.skeleton-line.w60 { width: 60px; }
.skeleton-line.w100 { width: 100px; }
.skeleton-line.w120 { width: 120px; }

/* Pull-to-refresh */
.ptr-indicator {
    position: fixed;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--surface);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: top 0.2s ease-out;
    z-index: 999;
}
.ptr-indicator.pulling { top: 16px; transition: none; }
.ptr-indicator.refreshing { top: 16px; }
.ptr-indicator svg { width: 20px; height: 20px; stroke: var(--accent); }
.ptr-indicator.refreshing svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Offline indicator */
.offline-chip {
    position: fixed;
    top: 8px;
    left: 50%;
    transform: translateX(-50%) translateY(-60px);
    background: var(--text);
    color: var(--bg);
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    z-index: 2000;
    transition: transform 0.3s cubic-bezier(.4,0,.2,1);
    pointer-events: none;
}
.offline-chip.show { transform: translateX(-50%) translateY(0); }

input, textarea, select {
    -webkit-user-select: text;
    user-select: text;
}

/* ══════════════════════════════════════════
   Header
   ══════════════════════════════════════════ */

header {
    display: flex;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(24px) saturate(1.4);
    -webkit-backdrop-filter: blur(24px) saturate(1.4);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
    gap: 8px;
}

.header-left {
    min-width: 0;
    overflow: hidden;
}

.header-left .summary {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
}

.header-right {
    flex-shrink: 0;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

header h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.4px;
    color: var(--text);
}

@media (max-width: 600px) {
    header {
        flex-wrap: wrap;
        padding: 10px 14px;
        gap: 4px 8px;
    }
    .header-left { flex: 1; min-width: 0; }
    .header-right { gap: 8px; }
    .header-right .timestamp,
    .header-right .toggle-auto,
    .header-right .btn-logout { display: none; }
    .header-right #refresh-btn { padding: 6px 12px; font-size: 12px; }
    .header-right select { padding: 6px 8px; font-size: 12px; }
    header h1 { font-size: 16px; }
    .header-left .summary { font-size: 11px; }

    .detail-controls {
        width: 100%;
        overflow-x: auto;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-bottom: 4px;
    }
    .detail-controls::-webkit-scrollbar { display: none; }
    .detail-controls > * { flex-shrink: 0; }
}

.back {
    color: var(--accent);
    text-decoration: none;
    font-size: 0;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: opacity 0.15s;
    width: 32px;
    height: 32px;
    justify-content: center;
}

.back::before {
    content: '';
    display: block;
    width: 12px;
    height: 12px;
    border-left: 2.5px solid var(--accent);
    border-bottom: 2.5px solid var(--accent);
    transform: rotate(45deg);
    margin-left: 3px;
}

.back:hover { opacity: 0.7; }

.ip { color: var(--text-dim); font-size: 13px; }
.summary { color: var(--text-secondary); font-size: 14px; font-weight: 400; }
.timestamp { color: var(--text-dim); font-size: 12px; font-weight: 500; }
.line-count { color: var(--text-dim); font-size: 12px; font-weight: 500; }

/* ══════════════════════════════════════════
   Badges
   ══════════════════════════════════════════ */

.badge {
    padding: 3px 10px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.badge-ok { background: var(--ok-bg); color: #16a34a; }
.badge-warning { background: var(--warning-bg); color: #d97706; }
.badge-critical { background: var(--critical-bg); color: var(--critical); }
.badge-unreachable { background: rgba(161,161,170,0.12); color: #71717a; }

/* ══════════════════════════════════════════
   Form Elements
   ══════════════════════════════════════════ */

select, input[type="text"], input[type="password"], input[type="search"] {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

select:focus, input:focus, textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-bg);
}

button, .btn-logout {
    background: var(--surface);
    color: var(--text-secondary);
    border: 1px solid var(--border-strong);
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

button:hover, .btn-logout:hover {
    background: var(--surface-2);
    border-color: var(--border-strong);
    color: var(--text);
}

button.active {
    background: var(--accent);
    color: #fff;
    border-color: transparent;
}

button.active:hover {
    background: var(--accent-light);
    border-color: transparent;
    color: #fff;
}

button.btn-danger {
    color: var(--critical);
    border-color: transparent;
    background: var(--critical-bg);
}

button.btn-danger:hover {
    background: var(--critical);
    color: #fff;
    border-color: var(--critical);
}

textarea {
    font-family: var(--font);
    font-size: 14px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

/* ══════════════════════════════════════════
   Login
   ══════════════════════════════════════════ */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 20px;
    background:
        radial-gradient(ellipse at 20% 50%, rgba(99,102,241,0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(167,139,250,0.06) 0%, transparent 50%),
        var(--bg);
}

.login-box {
    background: var(--surface);
    border-radius: 28px;
    padding: 44px 32px 36px;
    text-align: center;
    width: 360px;
    max-width: 100%;
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border);
    animation: modalIn 0.4s cubic-bezier(.4,0,.2,1);
}

.login-icon {
    margin-bottom: 16px;
}
.login-icon img {
    width: 72px;
    height: 72px;
    border-radius: 18px;
    box-shadow: var(--shadow);
}

.login-box h1 {
    margin-bottom: 4px;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.login-box .subtitle {
    color: var(--text-dim);
    font-size: 14px;
    margin-bottom: 28px;
}

.login-error {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--critical-bg);
    color: var(--critical);
    border-radius: var(--radius-xs);
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 16px;
    animation: shake 0.4s ease-out;
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(2px); }
}

.login-fields {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-bottom: 16px;
}

.login-field {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    transition: border-color 0.2s, box-shadow 0.2s;
}
.login-field:first-child {
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    border-bottom: none;
}
.login-field:last-child {
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}
.login-field:focus-within {
    border-color: var(--accent);
    box-shadow: none;
    z-index: 1;
    position: relative;
}
.login-field svg {
    flex-shrink: 0;
    color: var(--text-dim);
}
.login-field:focus-within svg {
    color: var(--accent);
}

.login-field input {
    width: 100%;
    padding: 14px 0;
    background: transparent;
    border: none;
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    border-radius: 0;
}
.login-field input:-webkit-autofill,
.login-field input:-webkit-autofill:hover,
.login-field input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 50px var(--surface-2) inset;
    -webkit-text-fill-color: var(--text);
    transition: background-color 5000s ease-in-out 0s;
}
.login-field input::placeholder {
    color: var(--text-dim);
}

.login-box button {
    width: 100%;
    padding: 14px;
    background: var(--accent);
    color: #fff;
    border: none;
    font-weight: 600;
    font-size: 15px;
    font-family: var(--font);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.login-box button:hover {
    background: var(--accent-light);
}

.login-box button:active {
    transform: scale(0.98);
}

.login-box .error {
    color: var(--critical);
    margin-bottom: 14px;
    font-size: 14px;
    font-weight: 500;
    background: var(--critical-bg);
    padding: 8px 14px;
    border-radius: var(--radius-xs);
}

.login-forgot-link {
    display: block;
    margin-top: 16px;
    color: var(--text-dim);
    font-size: 13px;
    text-decoration: none;
    transition: color 0.2s;
}
.login-forgot-link:hover {
    color: var(--accent);
}

.login-success {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--success-bg, rgba(34,197,94,0.1));
    color: var(--success, #22c55e);
    border-radius: var(--radius-xs);
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 16px;
    line-height: 1.5;
}

.login-field:only-child {
    border-radius: var(--radius-sm);
}

/* ══════════════════════════════════════════
   Landing Page — Module Cards
   ══════════════════════════════════════════ */

.home-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    padding: 20px;
    max-width: 680px;
    margin: 16px auto 0;
}

.module-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 28px 16px 24px;
    text-decoration: none;
    color: var(--text);
    transition: transform 0.25s cubic-bezier(.4,0,.2,1), box-shadow 0.25s;
    text-align: center;
    box-shadow: var(--shadow);
    border: none;
    position: relative;
    overflow: hidden;
}

.module-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--_mod-color, var(--accent));
    border-radius: 4px 4px 0 0;
}

.module-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.module-card:active {
    transform: scale(0.97);
}

/* Per-module colors — matches card order in home.php: Todos, Smart Home, Einkauf, Kalender, Monitor */
.module-card:nth-child(1) { --_mod-color: var(--mod-todos); }
.module-card:nth-child(2) { --_mod-color: var(--mod-smarthome); }
.module-card:nth-child(3) { --_mod-color: var(--mod-shopping); }
.module-card:nth-child(4) { --_mod-color: var(--mod-calendar); }
.module-card:nth-child(5) { --_mod-color: var(--mod-monitor); }

.module-icon {
    color: var(--_mod-color, var(--accent));
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(99, 102, 241, 0.12);
    border-radius: 16px;
    transition: background 0.2s, transform 0.2s;
}

/* Per-module icon backgrounds — explicit so no browser compat issues */
.module-card:nth-child(1) .module-icon { background: rgba(245, 158, 11, 0.12); }
.module-card:nth-child(2) .module-icon { background: rgba(16, 185, 129, 0.12); }
.module-card:nth-child(3) .module-icon { background: rgba(244, 114, 182, 0.12); }
.module-card:nth-child(4) .module-icon { background: rgba(59, 130, 246, 0.12); }
.module-card:nth-child(5) .module-icon { background: rgba(99, 102, 241, 0.12); }

.module-card:hover .module-icon {
    transform: scale(1.05);
}

.module-card:nth-child(1):hover .module-icon { background: rgba(245, 158, 11, 0.2); }
.module-card:nth-child(2):hover .module-icon { background: rgba(16, 185, 129, 0.2); }
.module-card:nth-child(3):hover .module-icon { background: rgba(244, 114, 182, 0.2); }
.module-card:nth-child(4):hover .module-icon { background: rgba(59, 130, 246, 0.2); }
.module-card:nth-child(5):hover .module-icon { background: rgba(99, 102, 241, 0.2); }

.module-icon svg {
    width: 26px;
    height: 26px;
}

.module-name {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.2px;
    color: var(--text);
}

.module-desc {
    font-size: 12px;
    color: var(--text-dim);
    line-height: 1.3;
}

.module-admin-links {
    grid-column: 1 / -1;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    padding-top: 4px;
}

.module-admin-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-dim);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.15s ease;
}

.module-admin-link:hover {
    color: var(--text);
    border-color: var(--text-dim);
}

.module-admin-link svg {
    width: 16px;
    height: 16px;
    opacity: 0.5;
}

/* ══════════════════════════════════════════
   Module Content (shared)
   ══════════════════════════════════════════ */

.module-content {
    max-width: 640px;
    margin: 0 auto;
    padding: 20px;
}

/* ══════════════════════════════════════════
   Dashboard Grid (Monitor)
   ══════════════════════════════════════════ */

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
    padding: 20px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-decoration: none;
    color: var(--text);
    transition: transform 0.15s, box-shadow 0.15s;
    border-left: 3px solid var(--border-strong);
    box-shadow: var(--shadow-sm);
}

.card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.card-ok { border-left-color: var(--ok); }
.card-warning { border-left-color: var(--warning); }
.card-critical { border-left-color: var(--critical); }
.card-unreachable { border-left-color: var(--unreachable); }

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.card-name { font-weight: 600; font-size: 14px; font-family: var(--font-mono); color: var(--text); }
.card-status { font-size: 11px; text-transform: uppercase; color: var(--text-dim); font-weight: 600; letter-spacing: 0.3px; }

.card-count { font-size: 32px; font-weight: 700; line-height: 1; letter-spacing: -1px; }
.card-ok .card-count { color: var(--ok); }
.card-warning .card-count { color: var(--warning); }
.card-critical .card-count { color: var(--critical); }

.card-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; margin-bottom: 8px; letter-spacing: 0.5px; font-weight: 500; }

.card-sources { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }

.source-tag {
    font-size: 11px;
    color: var(--text-secondary);
    background: var(--surface-2);
    padding: 2px 8px;
    border-radius: var(--radius-xs);
    font-family: var(--font-mono);
    font-weight: 500;
}

.card-top-error, .card-message {
    font-size: 12px;
    color: var(--text-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 4px;
}

/* ══════════════════════════════════════════
   Log View
   ══════════════════════════════════════════ */

.log-view { padding: 12px 20px; overflow-x: auto; }

.log-view, .log-view * {
    -webkit-user-select: text;
    user-select: text;
}

#log-output {
    font-size: 12px;
    font-family: var(--font-mono);
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--text);
}

.log-line { display: block; border-radius: var(--radius-xs); padding: 1px 6px; }
.log-line:hover { background: var(--accent-bg); }
.log-line.hidden { display: none; }

.log-source { font-weight: 600; margin-right: 8px; }
.log-source-nginx { color: #16a34a; }
.log-source-php { color: #d97706; }
.log-source-app { color: var(--accent); }
.log-source-unknown { color: var(--text-dim); }

.log-filtered { opacity: 0.3; }
.log-filtered:hover { opacity: 0.6; }

.log-line.log-filtered { opacity: 0.35; }
.log-line.log-filtered:hover { opacity: 0.6; }

.toggle-filtered, .toggle-auto {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
}

.toggle-filtered input, .toggle-auto input { cursor: pointer; accent-color: var(--accent); }

/* ══════════════════════════════════════════
   Countdown Bar
   ══════════════════════════════════════════ */

.countdown-track {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: transparent;
}

.countdown-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--accent-light));
    transition: width 0.3s linear;
    border-radius: 1px;
}

/* ══════════════════════════════════════════
   Tabs
   ══════════════════════════════════════════ */

.tabs { display: flex; gap: 2px; }

.tab-btn {
    padding: 8px 16px;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    border-bottom: 2px solid transparent;
    font-size: 13px;
    font-weight: 500;
}

.tab-btn.active {
    background: var(--accent-bg);
    border-bottom-color: var(--accent);
    color: var(--accent);
}

/* ══════════════════════════════════════════
   Trends, Copy, Health
   ══════════════════════════════════════════ */

.card-trend { font-size: 11px; font-weight: 600; margin-right: 4px; }
.trend-up { color: var(--critical); }
.trend-down { color: var(--ok); }
.trend-flat { color: var(--text-dim); }

.btn-copy {
    padding: 2px 6px;
    font-size: 10px;
    color: var(--text-dim);
    background: transparent;
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
    margin-left: 6px;
    flex-shrink: 0;
    font-family: var(--font-mono);
}

.card-error-line:hover .btn-copy,
.summary-row:hover .btn-copy,
.log-line:hover .btn-copy { opacity: 1; }

.btn-copy:hover { color: var(--accent); border-color: var(--accent); }
.btn-copy.copied { color: var(--ok); border-color: var(--ok); }

.card-health { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.health-metric { font-size: 11px; color: var(--text-secondary); font-family: var(--font-mono); }
.health-warn { color: var(--warning); font-weight: 600; }
.health-crit { color: var(--critical); font-weight: 600; }

.card-top-errors { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 6px; }

.card-error-line {
    display: flex;
    align-items: center;
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    line-height: 1.6;
    font-family: var(--font-mono);
}

.card-error-line .error-msg { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.error-count { color: var(--critical); font-weight: 600; margin-right: 4px; }

.card-message { font-size: 12px; color: var(--unreachable); font-style: italic; margin-top: 6px; }

/* ══════════════════════════════════════════
   Summary View
   ══════════════════════════════════════════ */

.summary-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background 0.1s;
}

.summary-row:hover { background: var(--surface-2); }
.summary-count { color: var(--critical); font-weight: 700; font-size: 15px; min-width: 40px; flex-shrink: 0; }

.summary-source {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: var(--radius-xs);
    background: var(--surface-2);
    flex-shrink: 0;
    font-family: var(--font-mono);
    color: var(--text-secondary);
}

.summary-msg { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-mono); color: var(--text); }
.summary-ago { color: var(--text-dim); font-size: 12px; flex-shrink: 0; white-space: nowrap; }

.summary-detail {
    display: none;
    padding: 0 12px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    max-height: 300px;
    overflow-y: auto;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

.summary-detail.expanded { display: block; }

.summary-logline {
    font-size: 12px;
    font-family: var(--font-mono);
    padding: 4px 8px;
    border-bottom: 1px solid var(--border);
    word-break: break-all;
    line-height: 1.5;
    color: var(--text-secondary);
}

.summary-logline:last-child { border-bottom: none; }

.summary-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--ok);
    font-size: 16px;
    font-weight: 500;
}

/* ══════════════════════════════════════════
   Todos
   ══════════════════════════════════════════ */

.todo-add, .shopping-add {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}
.todo-add {
    flex-wrap: wrap;
}

.todo-add input, .shopping-add input {
    flex: 1;
    background: var(--surface);
    color: var(--text);
    border: none;
    padding: 12px 16px;
    border-radius: 16px;
    font-family: var(--font);
    font-size: 15px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s;
    min-width: 0;
}
.shopping-add {
    flex-wrap: nowrap !important;
    flex-direction: row !important;
}
.shopping-add input {
    padding: 10px 14px;
    font-size: 16px;
    min-width: 0;
}
.shopping-add button {
    padding: 10px 16px !important;
    font-size: 18px;
    line-height: 1;
    min-width: 42px;
    flex-shrink: 0;
}
.shop-spec-toggle {
    padding: 10px 10px !important;
    min-width: 36px;
    font-size: 14px;
    letter-spacing: 1px;
    background: var(--surface) !important;
    color: var(--text-dim) !important;
    box-shadow: var(--shadow-sm);
}
.shop-spec-toggle.active {
    background: var(--accent-bg) !important;
    color: var(--accent) !important;
}
.shopping-spec-row {
    margin: -12px 0 12px;
}
.shopping-spec-row input {
    width: 100%;
    background: var(--surface);
    color: var(--text);
    border: none;
    padding: 10px 14px;
    border-radius: 14px;
    font-family: var(--font);
    font-size: 16px;
    box-shadow: var(--shadow-sm);
}
.shopping-spec-row input:focus {
    box-shadow: var(--shadow), 0 0 0 3px var(--accent-bg);
    outline: none;
}

.todo-add input:focus, .shopping-add input:focus {
    box-shadow: var(--shadow), 0 0 0 3px var(--accent-bg);
    outline: none;
}

.todo-add input::placeholder, .shopping-add input::placeholder {
    color: var(--text-dim);
}

.todo-add button, .shopping-add button {
    padding: 12px 24px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 16px;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font);
    font-size: 15px;
    transition: background 0.2s, transform 0.1s;
}
.todo-add button {
    flex: 1 1 100%;
}

.todo-add button:hover, .shopping-add button:hover {
    background: var(--accent-light);
}

.todo-add button:active, .shopping-add button:active {
    transform: scale(0.97);
}

.todo-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 26px 18px;
    background: var(--surface);
    border-radius: var(--radius);
    margin-bottom: 8px;
    transition: transform 0.15s, box-shadow 0.2s;
    box-shadow: var(--shadow-sm);
    border: none;
}

.todo-row:hover {
    box-shadow: var(--shadow);
}

.todo-row:active {
    transform: scale(0.99);
}

.todo-row input[type="checkbox"] {
    width: 24px;
    height: 24px;
    cursor: pointer;
    accent-color: var(--accent);
    flex-shrink: 0;
}

.todo-title {
    flex: 1;
    font-size: 16px;
    font-weight: 400;
    color: var(--text);
}

.todo-meta {
    font-size: 13px;
    color: var(--text-dim);
    flex-shrink: 0;
    font-weight: 500;
}

.todo-delete {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 22px;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: var(--radius-xs);
    opacity: 0;
    transition: opacity 0.15s, color 0.15s, background 0.15s;
    font-family: var(--font);
    line-height: 1;
}

.todo-row:hover .todo-delete,
.todo-delete:hover { color: var(--critical); background: var(--critical-bg); }

.todo-done { opacity: 0.45; }
.todo-done .todo-title { text-decoration: line-through; color: var(--text-dim); }

.todo-done-toggle {
    margin-top: 20px;
    text-align: center;
}

.todo-done-toggle button {
    background: transparent;
    color: var(--text-dim);
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    border: 1px solid var(--border);
    font-weight: 500;
}

.todo-done-toggle button:hover {
    color: var(--text-secondary);
    background: var(--surface);
}

.todo-empty {
    padding: 48px 20px;
    text-align: center;
    color: var(--text-dim);
    font-size: 15px;
    font-weight: 500;
}

.todo-empty::before {
    content: '';
    display: block;
    width: 48px;
    height: 48px;
    margin: 0 auto 12px;
    border-radius: 50%;
    background: var(--ok-bg);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2334d399' stroke-width='2'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 24px;
}

/* ── Quest Board ── */

.quest-row {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px 16px;
    margin-bottom: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    position: relative;
    transition: box-shadow 0.15s;
}
.quest-row:hover {
    box-shadow: 0 3px 10px rgba(0,0,0,0.3);
}

.quest-label-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.quest-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.quest-points {
    font-size: 13px;
    font-weight: 700;
    color: var(--warning);
    white-space: nowrap;
    flex-shrink: 0;
}

.quest-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.quest-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
}

.quest-avatar-initials {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
}

.quest-claim-btn {
    background: var(--ok);
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
    white-space: nowrap;
}
.quest-claim-btn:hover {
    opacity: 0.85;
}

.quest-check-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}
.quest-check-btn:hover {
    opacity: 0.85;
}

.quest-unclaim-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, border-color 0.15s;
}
.quest-unclaim-btn:hover {
    color: var(--critical);
    border-color: var(--critical);
}


.quest-assignee, .quest-done-by {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-dim);
}

/* Due date urgency */
.quest-tomorrow {
    border-left: 3px solid var(--warning);
}
.quest-today {
    border-left: 3px solid #f97316;
}
.quest-overdue {
    border-left: 3px solid var(--critical);
    animation: pulse-border 2s ease-in-out infinite;
}
@keyframes pulse-border {
    0%, 100% { border-left-color: var(--critical); }
    50% { border-left-color: rgba(239,68,68,0.3); }
}

/* ── Reward Animations ── */

.reward-check {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    font-size: 80px;
    color: var(--ok);
    z-index: 2000;
    pointer-events: none;
    animation: reward-check-anim 0.8s ease-out forwards;
    text-shadow: 0 4px 20px rgba(52,211,153,0.5);
}
@keyframes reward-check-anim {
    0% { transform: translate(-50%, -50%) scale(0) rotate(-20deg); opacity: 0; }
    40% { transform: translate(-50%, -50%) scale(1.3) rotate(5deg); opacity: 1; }
    70% { transform: translate(-50%, -50%) scale(1) rotate(0deg); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(0.8) rotate(0deg); opacity: 0; }
}

.reward-canvas {
    position: fixed;
    inset: 0;
    z-index: 2000;
    pointer-events: none;
}

.reward-levelup {
    position: fixed;
    inset: 0;
    z-index: 1999;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}
.reward-levelup.show {
    opacity: 1;
}
.reward-levelup-content {
    text-align: center;
}
.reward-levelup-label {
    font-size: 18px;
    font-weight: 700;
    color: var(--warning);
    letter-spacing: 4px;
    text-transform: uppercase;
    margin-bottom: 8px;
    text-shadow: 0 2px 20px rgba(245,158,11,0.6);
}
.reward-levelup-number {
    font-size: 100px;
    font-weight: 900;
    background: linear-gradient(135deg, var(--warning), #f97316, var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: levelup-number 0.6s ease-out;
    text-shadow: none;
    filter: drop-shadow(0 4px 30px rgba(245,158,11,0.4));
}
@keyframes levelup-number {
    0% { transform: scale(0) rotate(-10deg); }
    60% { transform: scale(1.2) rotate(3deg); }
    100% { transform: scale(1) rotate(0deg); }
}

#todo-due-date {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    font-size: 13px;
    max-width: 130px;
}

.quest-done {
    opacity: 0.45;
}
.quest-done .quest-title {
    text-decoration: line-through;
    color: var(--text-dim);
}

/* Quest Edit Modal */
.quest-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease-out;
}
.quest-modal {
    background: var(--surface);
    border-radius: 16px;
    padding: 24px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    animation: modalIn 0.25s cubic-bezier(.4,0,.2,1);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.quest-modal h3 {
    margin: 0 0 16px;
    font-size: 18px;
    color: var(--text);
}
.quest-modal label {
    display: block;
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 4px;
    font-weight: 600;
}
.quest-modal-input {
    width: 100%;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    margin-bottom: 12px;
    box-sizing: border-box;
}
.quest-modal-select {
    width: 100%;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    margin-bottom: 20px;
    box-sizing: border-box;
}
.quest-modal-btns {
    display: flex;
    gap: 8px;
}
.quest-modal-save {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 8px 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.quest-modal-cancel {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 16px;
    font-size: 14px;
    cursor: pointer;
}
.quest-modal-delete {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 16px;
    font-size: 14px;
    cursor: pointer;
    margin-left: auto;
    transition: all 0.15s;
}
.quest-modal-delete.confirm {
    background: var(--critical);
    color: #fff;
    border-color: var(--critical);
}

/* Label Color Picker Grid */
.label-color-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    margin-top: 8px;
}
.label-color-swatch {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid transparent;
    transition: transform 0.15s, border-color 0.15s;
    box-sizing: border-box;
}
.label-color-swatch:hover {
    transform: scale(1.15);
}
.label-color-swatch.selected {
    border-color: #fff;
    box-shadow: 0 0 0 2px var(--text), 0 2px 8px rgba(0,0,0,0.3);
    transform: scale(1.1);
}

/* Filter Bar */
.quest-filter-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
}
.quest-filter-btn {
    background: transparent;
    border: 1.5px solid var(--border);
    color: var(--text-dim);
    border-radius: 14px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}
.quest-filter-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.quest-filter-btn:not(.active):hover {
    border-color: var(--text-dim);
    color: var(--text);
}
.quest-filter-btn.empty {
    opacity: 0.4;
}
.quest-filter-add {
    border-style: dashed;
    font-size: 14px;
    padding: 4px 10px;
}

/* Label Select in Add Bar */
#todo-label-select {
    background: var(--surface);
    color: var(--text);
    border: none;
    border-radius: 16px;
    padding: 12px 12px;
    font-size: 15px;
    font-family: var(--font);
    min-width: 0;
    flex-shrink: 1;
    box-shadow: var(--shadow-sm);
    -webkit-appearance: none;
    appearance: none;
}

/* Stats Overlay */

#stats-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 16px;
    overflow-y: auto;
}

.stats-content {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.stats-header h2 {
    font-size: 20px;
    margin: 0;
    color: var(--text);
}
.stats-close {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}
.stats-close:hover {
    color: var(--text);
}

.stats-period {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}
.stats-period-btn {
    flex: 1;
    padding: 8px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-dim);
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
}
.stats-period-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.stats-lb-card {
    background: var(--bg);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 10px;
}

.stats-lb-top {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.stats-rank {
    width: 28px;
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-dim);
}

.stats-avatar {
    display: flex;
    align-items: center;
}

.stats-name {
    flex: 1;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.stats-streak {
    font-size: 14px;
}

.stats-xp-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.stats-level {
    font-size: 13px;
    font-weight: 700;
    color: var(--accent);
    min-width: 36px;
}

.stats-xp-bar {
    flex: 1;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.stats-xp-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--ok));
    border-radius: 4px;
    transition: width 0.5s ease;
}

.stats-xp-text {
    font-size: 11px;
    color: var(--text-dim);
    min-width: 70px;
    text-align: right;
}

.stats-period-points {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 2px;
    padding-left: 44px;
}

.stats-subtitle {
    font-size: 16px;
    margin: 24px 0 12px;
    color: var(--text);
}

.stats-badge-user {
    margin-bottom: 16px;
}
.stats-badge-username {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

.stats-badge-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.stats-badge {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px;
    border-radius: 12px;
    min-width: 72px;
    text-align: center;
    transition: transform 0.15s;
}
.stats-badge.earned {
    background: rgba(99,102,241,0.15);
}
.stats-badge.locked {
    opacity: 0.3;
    filter: grayscale(1);
}
.stats-badge.earned:hover {
    transform: scale(1.05);
}

.badge-icon {
    font-size: 24px;
    line-height: 1;
}
.badge-name {
    font-size: 10px;
    color: var(--text-dim);
    font-weight: 600;
}

/* Toast */

.quest-toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--surface);
    color: var(--text);
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 14px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    z-index: 2000;
    pointer-events: none;
    max-width: 90vw;
    text-align: center;
}
.quest-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Mobile: Quest Board */
@media (max-width: 600px) {
    .quest-delete-btn {
        opacity: 0.4;
    }
    .quest-row {
        padding: 14px 14px;
        gap: 10px;
    }
    #stats-overlay {
        padding: 20px 12px;
    }
    .stats-content {
        padding: 16px;
    }
}

/* ══════════════════════════════════════════
   Smart Home Widgets
   ══════════════════════════════════════════ */

.widget-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
    gap: 12px;
    padding: 20px;
    max-width: 900px;
    margin: 0 auto;
}

.widget-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 22px 16px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    transition: transform 0.2s cubic-bezier(.4,0,.2,1), box-shadow 0.2s;
    box-shadow: var(--shadow);
    border: none;
}

.widget-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.widget-icon { margin-bottom: 2px; }
.widget-icon svg { stroke-width: 1.8; }

.widget-value {
    font-size: 26px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.5px;
}

.widget-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

.widget-ago {
    font-size: 10px;
    color: var(--text-dim);
    font-weight: 500;
}

/* ── Widget Controls (bidirectional) ── */

.widget-control {
    margin-top: 8px;
    width: 100%;
}

.ctrl-btn {
    font-family: var(--font);
    font-size: 12px;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-xs);
    padding: 5px 12px;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    background: var(--accent-bg);
    color: var(--accent);
}

.ctrl-btn:hover {
    background: var(--accent-bg-strong);
}

.ctrl-btn:active {
    transform: scale(0.95);
}

.ctrl-toggle-btn {
    width: 100%;
    padding: 6px;
}

.ctrl-toggle-btn.ctrl-on {
    background: var(--ok-bg);
    color: var(--ok);
}

.ctrl-toggle-btn.ctrl-off {
    background: var(--accent-bg);
    color: var(--text-secondary);
}

.control-temp {
    display: flex;
    gap: 6px;
    justify-content: center;
}

.ctrl-minus, .ctrl-plus {
    width: 36px;
    height: 28px;
    padding: 0;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.control-slider {
    padding: 0 4px;
}

.control-slider input[type="range"] {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border-strong);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.control-slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}

.control-slider input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    cursor: pointer;
}

.control-climate {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-climate .ctrl-toggle-btn {
    width: 100%;
    padding: 6px;
}

.control-climate-modes {
    display: flex;
    gap: 4px;
}

.ctrl-mode-btn {
    flex: 1;
    font-size: 11px;
    padding: 4px 6px;
    background: var(--surface-2);
    color: var(--text-secondary);
}

.ctrl-mode-btn.ctrl-mode-active {
    background: var(--accent-bg-strong);
    color: var(--accent);
}

.control-climate-temp {
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: center;
}

.climate-temp-display {
    font-size: 14px;
    font-weight: 600;
    min-width: 55px;
    text-align: center;
    color: var(--text);
}

.control-rooms {
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: center;
}

.ctrl-room-select {
    flex: 1;
    padding: 5px 8px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 11px;
    font-family: var(--font);
    cursor: pointer;
}

.ctrl-room-clean-btn {
    font-size: 11px;
    padding: 5px 10px;
    border-radius: 8px;
    background: var(--mod-smarthome);
    color: #fff;
    white-space: nowrap;
}

/* ── Light Control ── */

.control-light {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ctrl-light-toggle {
    width: 100%;
    padding: 6px;
}

.ctrl-light-toggle.ctrl-on {
    background: rgba(245, 200, 66, 0.15);
    color: #f5c842;
}

.ctrl-light-toggle.ctrl-off {
    background: var(--accent-bg);
    color: var(--text-secondary);
}

.ctrl-light-slider {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border-strong);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.ctrl-light-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #f5c842;
    cursor: pointer;
}

.ctrl-light-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #f5c842;
    border: none;
    cursor: pointer;
}

/* ── Edit Mode (iOS-style wiggle) ── */

@keyframes wiggle {
    0%, 100% { transform: translate3d(0,0,0) rotate(-1deg); }
    50% { transform: translate3d(0,0,0) rotate(1deg); }
}

.widget-card.wiggle {
    animation: wiggle 0.35s ease-in-out infinite;
    will-change: transform;
    cursor: grab;
    /* Override the normal hover transition so it doesn't fight the animation */
    transition: none;
}

.widget-card.wiggle:hover {
    transform: none;
}

.widget-card.wiggle:active {
    cursor: grabbing;
}

/* Stagger wiggle for natural feel */
.widget-card.wiggle:nth-child(even) {
    animation-delay: 0.06s;
}
.widget-card.wiggle:nth-child(3n) {
    animation-delay: 0.12s;
}
.widget-card.wiggle:nth-child(5n) {
    animation-delay: 0.18s;
}

/* Hide button (top-left red circle with X) */
.widget-card .edit-hide-btn {
    display: none;
    position: absolute;
    top: -8px;
    left: -8px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--critical);
    color: #fff;
    border: 2px solid var(--bg);
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    z-index: 10;
    padding: 0;
    font-family: var(--font);
}

.widget-card.wiggle .edit-hide-btn {
    display: flex;
}

/* Show button (top-left green circle with +) for hidden widgets */
.widget-card .edit-show-btn {
    display: none;
    position: absolute;
    top: -8px;
    left: -8px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--ok);
    color: #fff;
    border: 2px solid var(--bg);
    font-size: 15px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    z-index: 10;
    padding: 0;
    font-family: var(--font);
}

.widget-card.wiggle.hidden-widget .edit-show-btn {
    display: flex;
}
.widget-card.wiggle.hidden-widget .edit-hide-btn {
    display: none;
}

/* Hidden widget (faded) */
.widget-card.hidden-widget {
    opacity: 0.3;
}

/* Card needs relative for absolute positioned buttons */
.widget-card.wiggle,
.widget-card.hidden-widget {
    position: relative;
    overflow: visible;
}

.widget-card.dragging {
    opacity: 0.15;
}

/* Pause ALL wiggle animations while actively dragging */
.dragging-active .widget-card.wiggle {
    animation-play-state: paused;
}

/* Touch drag clone — no animation, GPU-only */
.touch-drag-clone {
    animation: none !important;
    will-change: transform;
    box-shadow: 0 8px 30px rgba(0,0,0,0.3);
    border-radius: var(--radius-lg);
}

/* Collapsible category headers in edit mode */
.sensor-category-header.collapsible {
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

/* Category move buttons (edit mode) */
.cat-move-buttons {
    display: flex;
    gap: 2px;
    margin-left: auto;
}

.cat-move-btn {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    transition: background 0.15s;
}

.cat-move-btn:active {
    background: var(--accent-bg-strong);
    color: var(--accent);
}

.sensor-category-header .collapse-arrow {
    transition: transform 0.2s;
    display: inline-flex;
    margin-left: 8px;
}

.cat-move-buttons + .collapse-arrow {
    margin-left: 8px;
}

.sensor-category-header.collapsed .collapse-arrow {
    transform: rotate(-90deg);
}

.sensor-subgrid.collapsed {
    display: none;
}

/* Fertig floating button */
.edit-mode-done-btn {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 20px;
    padding: 12px 40px;
    font-size: 16px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    z-index: 1000;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    transition: background 0.2s, transform 0.2s;
}

.edit-mode-done-btn:active {
    transform: translateX(-50%) scale(0.95);
}

/* Edit mode active indicator on edit button */
.btn-icon.edit-active {
    background: var(--accent-bg-strong);
    color: var(--accent);
}

@media (max-width: 768px) {
    .edit-mode-done-btn {
        bottom: 90px;
    }
}

/* Command feedback */
.widget-sent {
    box-shadow: 0 0 0 2px var(--ok), var(--shadow) !important;
    transition: box-shadow 0.3s;
}

.widget-error {
    box-shadow: 0 0 0 2px var(--critical), var(--shadow) !important;
    transition: box-shadow 0.3s;
}

/* ══════════════════════════════════════════
   Shopping List (Bring!)
   ══════════════════════════════════════════ */

/* Shopping card grid */
.shopping-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}
.shopping-grid.bought { opacity: 0.45; }

.shop-card {
    background: var(--surface);
    border-radius: 14px;
    padding: 10px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s, opacity 0.3s;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    position: relative;
    user-select: none;
    -webkit-user-select: none;
}
.shop-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,0.3); }
.shop-card:active { transform: scale(0.96); }

.shop-card.shop-checking {
    animation: shop-check-anim 0.6s ease-out forwards;
}
@keyframes shop-check-anim {
    0% { transform: scale(1); opacity: 1; }
    30% { transform: scale(1.05); }
    100% { transform: scale(0.8); opacity: 0; }
}

.shop-card.shop-adding {
    animation: shop-pop-in 0.25s ease-out;
}
@keyframes shop-pop-in {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.shop-check-effect {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 42px;
    color: #22c55e;
    background: rgba(34,197,94,0.1);
    border-radius: 14px;
    opacity: 0;
    transform: scale(0.3);
    transition: opacity 0.2s, transform 0.3s cubic-bezier(0.175,0.885,0.32,1.275);
    z-index: 2;
    pointer-events: none;
}
.shop-check-effect.show {
    opacity: 1;
    transform: scale(1);
}

.shop-card.shop-bought {
    opacity: 0.5;
}
.shop-card.shop-bought .shop-card-name {
    text-decoration: line-through;
}

.frequent-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 4px;
}
.frequent-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-family: var(--font);
    font-size: 14px;
    color: var(--text);
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.15s;
    box-shadow: var(--shadow-sm);
}
.frequent-chip:active {
    transform: scale(0.95);
}
.frequent-chip.frequent-adding {
    opacity: 0.4;
    pointer-events: none;
}
.frequent-emoji {
    font-size: 16px;
}
.frequent-name {
    font-weight: 500;
}
.frequent-count {
    font-size: 12px;
    color: var(--text-dim);
    font-weight: 400;
}

.shop-card-emoji {
    font-size: 36px;
    line-height: 1;
    margin-bottom: 4px;
}
.shop-card-letter {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    margin: 0 auto 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 700;
    color: #fff;
    opacity: 0.85;
}

.shop-card-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.2;
    overflow: hidden;
    overflow-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
    -webkit-hyphens: auto;
}
.shop-card-spec {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 2px;
}

.shop-del-btn {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 14px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.shop-card:hover .shop-del-btn { display: flex; }

/* Suggestions dropdown */
.suggestions-box {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.4);
    z-index: 100;
    max-height: 240px;
    overflow-y: auto;
    margin-top: 4px;
}
.suggestion-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
    transition: background 0.1s;
}
.suggestion-item:hover { background: var(--bg); }
.suggestion-emoji {
    font-size: 20px;
    line-height: 1;
}

/* Shopping delete confirm */
.shop-confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}
.shop-confirm-overlay.show { opacity: 1; }
.shop-confirm-modal {
    background: var(--surface);
    border-radius: 18px;
    padding: 28px 24px 20px;
    text-align: center;
    min-width: 260px;
    max-width: 320px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.4);
    transform: scale(0.9);
    transition: transform 0.2s;
}
.shop-confirm-overlay.show .shop-confirm-modal { transform: scale(1); }
.shop-confirm-emoji { font-size: 44px; margin-bottom: 8px; }
.shop-confirm-msg {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 20px;
}
.shop-confirm-btns {
    display: flex;
    gap: 10px;
}
.shop-confirm-btns button {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 12px;
    font-family: var(--font);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s;
}
.shop-confirm-btns button:active { transform: scale(0.96); }
.shop-confirm-cancel {
    background: var(--bg);
    color: var(--text);
}
.shop-confirm-del {
    background: #ef4444;
    color: #fff;
}

/* Emoji picker grid */
.emoji-picker-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 12px;
}
.emoji-picker-btn {
    font-size: 32px;
    padding: 10px;
    background: var(--bg);
    border: 2px solid transparent;
    border-radius: 14px;
    cursor: pointer;
    transition: transform 0.1s, border-color 0.15s;
    line-height: 1;
}
.emoji-picker-btn:hover { border-color: var(--accent); }
.emoji-picker-btn:active { transform: scale(0.9); }
.emoji-picker-loading {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-dim);
    font-size: 14px;
    padding: 20px;
}

/* ══════════════════════════════════════════
   Calendar
   ══════════════════════════════════════════ */
body.cal-page {
    overflow: hidden;
    padding-bottom: 0 !important;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-template-rows: auto;
    grid-auto-rows: 1fr;
    gap: 1px;
    background: var(--border);
    overflow: hidden;
    margin: 0;
    height: 100%;
}

.cal-header {
    background: var(--surface-2);
    padding: 6px;
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.cal-day {
    background: var(--surface);
    padding: 4px 6px;
    cursor: pointer;
    transition: background 0.15s;
    overflow: hidden;
}

.cal-day:hover { background: var(--surface-2); }
.cal-day-empty { background: var(--surface-2); cursor: default; opacity: 0.4; }

.cal-today { background: var(--accent-bg-strong, rgba(99,102,241,0.12)); }
.cal-today:hover { background: rgba(99,102,241,0.18); }
.cal-day-selected { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal-day-selected.cal-today { background: rgba(99,102,241,0.18); }

.cal-day-num {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    margin-bottom: 2px;
}

.cal-today .cal-day-num {
    background: var(--accent);
    color: #fff;
    font-weight: 700;
}

.cal-event {
    font-size: 11px;
    padding: 2px 6px;
    margin-bottom: 2px;
    border-radius: var(--radius-xs);
    background: var(--accent-bg);
    border-left: 2px solid var(--accent);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.1s;
    color: var(--accent);
    font-weight: 500;
}

.cal-event:hover { background: var(--accent-bg-strong); }

/* ── Calendar Header Bar ── */

.cal-header-bar {
    flex-shrink: 0;
    z-index: 10;
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(24px) saturate(1.4);
    -webkit-backdrop-filter: blur(24px) saturate(1.4);
    border-bottom: 1px solid var(--border);
    padding: 10px 16px 8px;
}
.cal-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.cal-back {
    color: var(--accent);
    text-decoration: none;
    font-size: 22px;
    font-weight: 400;
    line-height: 1;
    padding: 4px;
}
.cal-header-center {
    display: flex;
    align-items: center;
    gap: 6px;
}
.cal-header-center h1 {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.3px;
    color: var(--text);
    white-space: nowrap;
    margin: 0;
}
.cal-kw {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-dim);
    white-space: nowrap;
}
.cal-arrow {
    font-size: 22px;
    font-weight: 300;
    color: var(--accent);
    cursor: pointer;
    padding: 2px 6px;
    line-height: 1;
    border-radius: 6px;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.cal-arrow:active { background: var(--accent-bg); }
.cal-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}
.cal-today-btn {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.cal-add-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 20px;
    font-weight: 300;
    line-height: 1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.cal-add-btn:active { opacity: 0.8; }

/* ── Segmented Control ── */

.cal-segment {
    display: flex;
    position: relative;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 9px;
    padding: 2px;
}
.cal-segment-slider {
    position: absolute;
    top: 2px;
    bottom: 2px;
    width: calc((100% - 4px) / 3);
    left: calc(var(--seg, 0) * (100% - 4px) / 3 + 2px);
    background: #fff;
    border-radius: 7px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    transition: left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 0;
}
.cal-segment-btn {
    flex: 1;
    padding: 6px 0;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    position: relative;
    z-index: 1;
    text-align: center;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.2s;
}
.cal-segment-btn.active { color: var(--text); font-weight: 600; }

/* ── Calendar Timeline (Week + Day) ── */

main.cal-main {
    padding: 0 !important;
    max-width: none !important;
    overflow: hidden;
    margin: 0;
    flex: 1;
    min-height: 0;
}
.cal-view-container { position: relative; overflow: hidden; height: 100%; }

.cal-timeline {
    max-width: none;
    margin: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.cal-tl-header {
    display: flex;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.cal-tl-scroll {
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
.cal-tl-header-gutter {
    min-width: 48px;
    flex-shrink: 0;
}
.cal-tl-header-day {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 2px;
    min-width: 0;
    cursor: pointer;
    gap: 2px;
}
.cal-tl-dayname {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
}
.cal-tl-header-day.is-today .cal-tl-dayname {
    color: var(--accent);
}
.cal-tl-header-day .cal-tl-daynum {
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}
.cal-tl-header-day.is-today .cal-tl-daynum {
    background: var(--accent);
    color: #fff;
}

.cal-tl-body {
    position: relative;
    display: flex;
    padding-top: 12px;
}
.cal-tl-gutter {
    min-width: 48px;
    flex-shrink: 0;
}
.cal-tl-gutter-label {
    height: 60px;
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    padding-right: 8px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-dim);
    transform: translateY(-7px);
}
.cal-tl-cols {
    flex: 1;
    display: flex;
    position: relative;
}
.cal-tl-col {
    flex: 1;
    min-width: 0;
    border-left: 1px solid var(--border);
    position: relative;
}
.cal-tl-col:first-child { border-left: none; }

.cal-tl-slot {
    height: 60px;
    border-top: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.1s;
}
.cal-tl-slot:hover { background: var(--accent-bg); }

.cal-tl-event {
    position: absolute;
    left: 2px;
    right: auto;
    width: calc(100% - 4px);
    border-radius: 6px;
    padding: 4px 6px 4px 8px;
    font-size: 11px;
    font-weight: 500;
    overflow: hidden;
    cursor: pointer;
    z-index: 2;
    line-height: 1.3;
    transition: opacity 0.15s;
}
.cal-tl-event:hover { opacity: 0.85; }
.cal-tl-event-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-tl-event-time { font-size: 10px; opacity: 0.8; }
.cal-tl-event-detail { font-size: 11px; opacity: 0.6; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cal-timeline.view-day .cal-tl-col { min-width: 100%; }
.cal-timeline.view-day .cal-tl-event {
    padding: 6px 10px;
    font-size: 13px;
}
.cal-timeline.view-day .cal-tl-event-time { font-size: 11px; }

.cal-tl-now {
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background: #ef4444;
    z-index: 3;
    pointer-events: none;
}
.cal-tl-now::before {
    content: '';
    position: absolute;
    left: -4px;
    top: -3px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ef4444;
}

.cal-allday-bar {
    max-width: 900px;
    margin: 0 auto;
    padding: 6px 48px 6px 48px;
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: var(--radius) var(--radius) 0 0;
}
.cal-allday-event {
    font-size: 11px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
}

/* ── Agenda (week list view) ── */
.cal-agenda-scroll {
    overflow-y: auto;
    flex: 1;
}
.cal-agenda-day {
    display: flex;
    align-items: flex-start;
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    gap: 16px;
    min-height: 52px;
}
.cal-agenda-today {
    background: var(--accent-bg);
}
.cal-agenda-day-label {
    width: 70px;
    min-width: 70px;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    padding-top: 2px;
}
.cal-agenda-daynum {
    font-size: 28px;
    font-weight: 700;
    line-height: 1;
    color: var(--text);
}
.cal-agenda-today .cal-agenda-daynum {
    color: var(--accent);
}
.cal-agenda-dayname {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-top: 2px;
}
.cal-agenda-today .cal-agenda-dayname {
    color: var(--accent);
}
.cal-agenda-events {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 28px;
    cursor: pointer;
}
.cal-agenda-event {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.1s;
}
.cal-agenda-event:hover {
    background: var(--surface-2);
}
.cal-agenda-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.cal-agenda-time {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    width: 44px;
    min-width: 44px;
    flex-shrink: 0;
}
.cal-agenda-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

@media (max-width: 600px) {
    .cal-agenda-day {
        padding: 10px 12px;
        gap: 12px;
    }
    .cal-agenda-day-label {
        width: 56px;
        min-width: 56px;
    }
    .cal-agenda-daynum {
        font-size: 24px;
    }
    .cal-agenda-title {
        font-size: 13px;
    }
}

/* ══════════════════════════════════════════
   Modal
   ══════════════════════════════════════════ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

.modal {
    background: var(--surface);
    border-radius: 24px;
    padding: 28px;
    width: 420px;
    max-width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    border: none;
    animation: modalIn 0.25s cubic-bezier(.4,0,.2,1);
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.96) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Confirm dialog */
.confirm-modal {
    width: 340px;
    padding: 24px;
    text-align: center;
}

.confirm-title {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
}

.confirm-message {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.5;
}

.confirm-actions {
    display: flex;
    gap: 10px;
}

.confirm-actions button {
    flex: 1;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    font-family: var(--font);
    text-align: center;
    transition: background 0.15s, color 0.15s;
}

.confirm-actions button.confirm-cancel {
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
}

.confirm-actions button.confirm-cancel:hover {
    background: var(--bg);
    color: var(--text);
}

.confirm-actions button.confirm-ok {
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    color: #fff;
}

.confirm-actions button.confirm-ok:hover {
    background: var(--accent-light);
    color: #fff;
}

.confirm-actions button.confirm-ok.btn-danger {
    background: var(--critical);
    color: #fff;
}

.confirm-actions button.confirm-ok.btn-danger:hover {
    background: #ef4444;
    color: #fff;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.modal input[type="text"],
.modal input[type="date"],
.modal input[type="datetime-local"],
.modal input[type="password"],
.modal textarea,
.modal select {
    width: 100%;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border-strong);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 14px;
    margin-bottom: 10px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.modal input:focus, .modal textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-bg);
}

.modal textarea { resize: vertical; }

.form-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 10px;
}

.form-row label {
    font-size: 14px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-weight: 500;
}

/* Modal content (used by config modal etc.) */
.modal-content {
    background: var(--surface);
    border-radius: 24px;
    padding: 28px;
    width: 420px;
    max-width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    animation: modalIn 0.25s cubic-bezier(.4,0,.2,1);
}
.modal-content.modal-lg { width: 560px; }

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-dim);
    line-height: 1;
    padding: 4px 8px;
    border-radius: var(--radius-xs);
}
.modal-close:hover { color: var(--text); background: var(--surface-2); }

.modal-body { margin-bottom: 20px; }

.modal-footer {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.btn {
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    font-family: var(--font);
    border: none;
    transition: background 0.15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-light); }
.btn-secondary { background: var(--surface-2); color: var(--text-secondary); border: 1px solid var(--border-strong); }
.btn-secondary:hover { background: var(--bg); color: var(--text); }

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 6px;
    border-radius: var(--radius-xs);
    display: flex;
    align-items: center;
    transition: color 0.15s, background 0.15s;
}
.btn-icon:hover { color: var(--text); background: var(--surface-2); }

/* Sensor Config Modal */
.config-category { margin-bottom: 16px; }
.config-category-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.config-sensor-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}
.config-sensor-row:last-child { border-bottom: none; }
.config-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    flex: 1;
    min-width: 0;
}
.config-sensor-label {
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.config-category-select {
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-xs);
    padding: 4px 8px;
    font-size: 12px;
    font-family: var(--font);
    color: var(--text);
    max-width: 140px;
}

.form-row label input[type="checkbox"] {
    accent-color: var(--accent);
}

.form-row input[type="datetime-local"],
.form-row input[type="date"] { flex: 1; margin-bottom: 0; }

.form-actions {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: 20px;
}

.form-actions button[type="submit"] {
    flex: 1;
    padding: 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font);
    font-size: 15px;
    transition: background 0.15s, transform 0.1s;
}

.form-actions button[type="submit"]:hover {
    background: var(--accent-light);
}

.form-actions button[type="submit"]:active {
    transform: scale(0.98);
}

/* ══════════════════════════════════════════
   Admin
   ══════════════════════════════════════════ */

.admin-add {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    border: none;
}

.admin-add h3 {
    font-size: 14px;
    margin-bottom: 14px;
    color: var(--text-secondary);
    font-weight: 600;
}

.admin-add .form-row { flex-wrap: wrap; }

.admin-add input, .admin-add select {
    flex: 1;
    min-width: 100px;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border-strong);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 14px;
}

.admin-add button {
    padding: 10px 24px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font);
}

.admin-user-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    background: var(--surface);
    border-radius: var(--radius);
    margin-bottom: 6px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.admin-user-row:hover { box-shadow: var(--shadow); }

.admin-user-name { font-size: 15px; font-weight: 600; color: var(--text); }
.admin-user-meta { font-size: 12px; color: var(--text-dim); font-weight: 500; margin-left: 8px; }
.admin-user-actions { display: flex; gap: 6px; }
.admin-user-actions button { padding: 6px 12px; font-size: 12px; }

/* ══════════════════════════════════════════
   Loading States
   ══════════════════════════════════════════ */

.loading { opacity: 0.5; pointer-events: none; }
.card-loading { animation: pulse 1.5s ease-in-out infinite; }
.card-loading .card-count { color: var(--text-dim); }
.badge-loading { background: var(--surface-2); color: var(--text-dim); border: 1px solid var(--border); }
.skeleton-text { color: var(--text-dim); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.loading-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 40px 20px;
    color: var(--text-dim);
    font-size: 15px;
    justify-content: center;
    font-weight: 500;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid var(--border-strong);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════════
   Meal Plan / Essensplan
   ══════════════════════════════════════════ */

.meal-week-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.meal-week-label {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.meal-week-btn {
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: 10px;
    width: 36px;
    height: 36px;
    font-size: 20px;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.meal-week-btn:hover { background: var(--hover); }

.meal-week-strip {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
    margin-bottom: 24px;
}

.meal-day-card {
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 4px;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s;
    min-height: 90px;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.meal-day-card:hover { border-color: var(--accent); background: var(--hover); }
.meal-day-card.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.meal-day-card.has-meal { background: var(--accent-bg); }

.meal-day-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.meal-day-num {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    margin: 2px 0 4px;
}

.meal-day-meal {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    width: 100%;
    overflow: hidden;
}

.meal-day-emoji { font-size: 20px; line-height: 1; }
.meal-day-name {
    font-size: 9px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    padding: 0 2px;
}
.meal-day-plus {
    font-size: 22px;
    color: var(--text-dim);
    opacity: 0.5;
}

.meal-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.meal-add-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s;
}
.meal-add-btn:hover { opacity: 0.85; }

.meal-search {
    margin-bottom: 12px;
}
.meal-search input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-raised);
    color: var(--text);
    font-size: 14px;
    box-sizing: border-box;
}
.meal-search input:focus { outline: none; border-color: var(--accent); }

.meal-collection {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.meal-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.15s;
}
.meal-card:hover { border-color: var(--accent); background: var(--hover); }

.meal-card-emoji { font-size: 28px; flex-shrink: 0; }
.meal-card-info { flex: 1; min-width: 0; }
.meal-card-name {
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.meal-card-meta {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 2px;
}

.meal-empty {
    text-align: center;
    color: var(--text-dim);
    padding: 24px;
    font-size: 14px;
}

/* Assign modal */
.meal-assign-list {
    max-height: 50vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 12px 0;
}
.meal-assign-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.12s;
}
.meal-assign-item:hover { background: var(--hover); }
.meal-assign-emoji { font-size: 24px; }
.meal-assign-name { font-size: 15px; color: var(--text); }

/* Detail modal ingredients */
.meal-ingredients-list {
    margin: 12px 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.meal-ingredient-check {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
    transition: background 0.12s;
}
.meal-ingredient-check:hover { background: var(--hover); }
.meal-ingredient-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

/* Edit modal ingredients */
.meal-edit-ingredients {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 8px;
}
.meal-ingredient-row {
    display: flex;
    gap: 6px;
    align-items: center;
}
.meal-ingredient-row .form-input { flex: 1; }
.meal-add-ingredient {
    display: flex;
    gap: 6px;
    align-items: center;
}
.meal-add-ingredient .form-input { flex: 1; }

.meal-section-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.btn-icon-danger {
    background: none;
    border: none;
    color: var(--danger, #ef4444);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.12s;
}
.btn-icon-danger:hover { background: rgba(239,68,68,0.1); }

.btn-text-danger {
    background: none;
    border: none;
    color: var(--danger, #ef4444);
    font-size: 13px;
    cursor: pointer;
    padding: 6px 0;
    text-align: center;
    width: 100%;
    opacity: 0.7;
}
.btn-text-danger:hover { opacity: 1; }

.btn-small {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    width: 36px;
    height: 36px;
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
}

.meal-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px;
    color: var(--text-secondary);
    font-size: 13px;
}

/* Today card meal section */
.today-birthday {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: linear-gradient(135deg, rgba(251,191,36,0.1), rgba(244,114,182,0.1));
    border-radius: 10px;
    color: var(--text);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
    transition: background 0.12s;
}
.today-birthday:hover { background: linear-gradient(135deg, rgba(251,191,36,0.18), rgba(244,114,182,0.18)); }

.today-meal-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    color: var(--text);
    text-decoration: none;
    font-size: 14px;
}
.today-meal-emoji {
    flex-shrink: 0;
    width: 14px;
    font-size: 14px;
    line-height: 1;
    text-align: center;
}

/* ══════════════════════════════════════════
   Responsive — Mobile First
   ══════════════════════════════════════════ */

@media (max-width: 768px) {
    header {
        padding: 12px 16px;
    }

    .grid { grid-template-columns: 1fr; padding: 12px; gap: 10px; }

    .home-grid {
        grid-template-columns: repeat(2, 1fr);
        padding: 14px;
        gap: 10px;
        max-width: 100%;
        margin-top: 12px;
    }

    .module-card { padding: 20px 12px; }
    .module-icon { width: 40px; height: 40px; }

    .widget-grid {
        grid-template-columns: repeat(2, 1fr);
        padding: 12px;
        gap: 10px;
    }

    .widget-card { padding: 18px 12px; }
    .widget-value { font-size: 22px; }

    .calendar-grid { height: 100%; }
    .cal-day { padding: 0 1px; }
    .cal-day-num { font-size: 10px; margin-bottom: 0; line-height: 1.2; }
    .cal-event { font-size: 7px; padding: 0 1px; margin-top: 0; line-height: 1.15; white-space: normal; word-break: break-word; }
    .cal-event-text { white-space: normal; word-break: break-word; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
    .cal-event-stripe { width: 2px; }
    .cal-span-layer { grid-auto-rows: 16px; row-gap: 1px; padding: 1px 0; }
    .cal-span-event { font-size: 7px; padding: 0 2px 0 4px; height: 14px; }
    .cal-span-stripe { width: 2px; }
    .cal-header { padding: 6px; font-size: 11px; }
    .cal-tl-header-gutter, .cal-tl-gutter { min-width: 36px; }
    .cal-tl-header-day { font-size: 10px; }
    .cal-tl-header-day .cal-tl-daynum { font-size: 16px; }
    .cal-tl-event { font-size: 10px; padding: 2px 4px; }
    .cal-tl-event-time { display: none; }
    .cal-header-bar { padding: 8px 12px 6px; }
    .cal-header-center h1 { font-size: 15px; }
    .cal-kw { font-size: 11px; }
    .cal-allday-bar { padding-left: 36px; }
    main.cal-main { padding-bottom: 0 !important; }

    .module-content { padding: 14px; }

    .meal-week-strip { gap: 4px; }
    .meal-day-card { padding: 6px 2px; min-height: 80px; border-radius: 10px; }
    .meal-day-emoji { font-size: 16px; }
    .meal-day-name { font-size: 8px; }
    .meal-day-num { font-size: 14px; }

    .admin-add .form-row { flex-direction: column; }
    .form-row { flex-direction: column; align-items: flex-start; }

    .todo-row { padding: 12px; }
    .shopping-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .shop-del-btn { display: flex; opacity: 0.4; }

    /* Show delete buttons on touch devices */
    .todo-delete { opacity: 0.5; }

    .modal { padding: 20px; }

    .todo-add button { width: 100%; }
}

@media (max-width: 420px) {
    .widget-grid {
        grid-template-columns: 1fr 1fr;
    }

    header h1 { font-size: 16px; }

    .card-count { font-size: 28px; }
}

/* ══════════════════════════════════════════
   Safe Area (notch devices)
   ══════════════════════════════════════════ */

@supports (padding-top: env(safe-area-inset-top)) {
    header {
        padding-top: calc(14px + env(safe-area-inset-top));
        padding-left: calc(20px + env(safe-area-inset-left));
        padding-right: calc(20px + env(safe-area-inset-right));
    }

    .grid, .home-grid, .widget-grid, .widget-container, .module-content {
        padding-left: calc(20px + env(safe-area-inset-left));
        padding-right: calc(20px + env(safe-area-inset-right));
    }
}

/* ══════════════════════════════════════════
   Selection & Scrollbar
   ══════════════════════════════════════════ */

::selection {
    background: var(--accent-bg-strong);
    color: var(--text);
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ══════════════════════════════════════════
   Page Transition
   ══════════════════════════════════════════ */

@keyframes pageIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

main { animation: pageIn 0.18s ease-out; }

/* ══════════════════════════════════════════
   Bottom Navigation
   ══════════════════════════════════════════ */

.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(24px) saturate(1.4);
    -webkit-backdrop-filter: blur(24px) saturate(1.4);
    border-top: 1px solid var(--border);
    z-index: 50;
    justify-content: space-around;
    align-items: center;
    padding: 6px 0;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    text-decoration: none;
    color: var(--text-dim);
    font-size: 10px;
    font-weight: 500;
    padding: 6px 4px 4px;
    border-radius: var(--radius-sm);
    transition: color 0.2s;
    min-width: 0;
    flex: 1;
    position: relative;
}

.bottom-nav-item.active {
    color: var(--accent);
}

.bottom-nav-item.active::after {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 3px;
    background: var(--accent);
    border-radius: 0 0 3px 3px;
}

.bottom-nav-item:hover {
    color: var(--text-secondary);
}

.bottom-nav-item.active:hover {
    color: var(--accent);
}

.bottom-nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
}

.bottom-nav-icon svg {
    width: 22px;
    height: 22px;
}

.bottom-nav-label {
    letter-spacing: -0.1px;
    line-height: 1;
}

/* Nav badge dot for calendar */
.nav-badge-dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 7px;
    height: 7px;
    background: var(--mod-calendar);
    border-radius: 50%;
    border: 1.5px solid rgba(255,255,255,0.92);
}

.bottom-nav-icon { position: relative; }

/* ── Today Card ── */
.today-card {
    max-width: 680px;
    margin: 16px auto 0;
    padding: 0 20px;
}
.today-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 12px;
}
.today-date {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}
.today-weather {
    font-size: 16px;
    color: var(--text-secondary);
    white-space: nowrap;
}
.today-sections {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.today-section {
    padding: 12px 16px;
}
.today-section + .today-section {
    border-top: 1px solid var(--border);
}
.today-section-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 5px;
}
.today-section-label svg {
    opacity: 0.5;
}
.today-section-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.today-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    text-decoration: none;
    color: var(--text);
    font-size: 14px;
}
.today-item-stripe {
    width: 3px;
    border-radius: 2px;
    align-self: stretch;
    flex-shrink: 0;
    min-height: 18px;
}
.today-item-time {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    min-width: 52px;
    flex-shrink: 0;
}
.today-item-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.today-item-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    flex-shrink: 0;
}
.today-item-dot.overdue {
    background: #ef4444;
}
.today-shopping-link {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text);
    font-size: 14px;
    padding: 4px 0;
}
.today-shopping-link svg {
    color: var(--mod-shopping, #f472b6);
    flex-shrink: 0;
}
.today-empty {
    text-align: center;
    padding: 20px 16px;
    color: var(--text-secondary);
    font-size: 14px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

@media (max-width: 600px) {
    .today-card { padding: 0 14px; margin-top: 12px; }
    .today-date { font-size: 16px; }
    .today-weather { font-size: 14px; }
}

/* (upcoming-events section removed — integrated into today-card) */

@media (max-width: 768px) {
    .bottom-nav {
        display: flex;
    }

    body {
        padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px));
    }

    header .btn-logout {
        display: none;
    }

    .home-grid {
        margin-top: 8px;
    }
}

/* ══════════════════════════════════════════
   Sensor Categories
   ══════════════════════════════════════════ */

.widget-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
}

.sensor-category {
    margin-bottom: 24px;
}

.sensor-category:last-child {
    margin-bottom: 0;
}

.sensor-category-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    padding: 0 4px;
}

.sensor-category-icon {
    color: var(--accent);
    display: flex;
    align-items: center;
}

.sensor-category-icon svg {
    width: 20px;
    height: 20px;
}

.sensor-category-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: -0.2px;
}

.sensor-subgrid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
    gap: 12px;
}

@media (max-width: 768px) {
    .widget-container {
        padding: 12px;
    }

    .sensor-subgrid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .sensor-category {
        margin-bottom: 20px;
    }
}

/* ══════════════════════════════════════════
   CalDAV Info
   ══════════════════════════════════════════ */

.caldav-info {
    max-width: 900px;
    margin: 20px auto 0;
    padding: 0 16px;
}

.caldav-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    cursor: pointer;
    width: 100%;
    font-family: var(--font);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: background 0.15s, box-shadow 0.15s;
    box-shadow: var(--shadow-sm);
}

.caldav-toggle:hover {
    background: var(--surface-2);
    box-shadow: var(--shadow);
}

.caldav-toggle svg {
    width: 18px;
    height: 18px;
    color: var(--accent);
    flex-shrink: 0;
}

.caldav-toggle-arrow {
    margin-left: auto;
    transition: transform 0.2s;
    color: var(--text-dim);
}

.caldav-toggle.open .caldav-toggle-arrow {
    transform: rotate(180deg);
}

.caldav-details {
    display: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    padding: 20px;
    margin-top: -1px;
}

.caldav-details.open {
    display: block;
    animation: pageIn 0.18s ease-out;
}

.caldav-field {
    margin-bottom: 14px;
}

.caldav-field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.caldav-url {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text);
    word-break: break-all;
}

.caldav-url .btn-copy-url {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    padding: 4px 10px;
    border-radius: var(--radius-xs);
    font-size: 12px;
    cursor: pointer;
    color: var(--text-secondary);
    flex-shrink: 0;
    font-family: var(--font);
    font-weight: 500;
    transition: all 0.15s;
}

.caldav-url .btn-copy-url:hover {
    background: var(--accent-bg);
    color: var(--accent);
    border-color: var(--accent);
}

.caldav-steps {
    margin-top: 16px;
}

.caldav-steps h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.caldav-steps ol {
    padding-left: 20px;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.8;
    margin-bottom: 16px;
}

/* ══════════════════════════════════════════
   Admin UX Improvements
   ══════════════════════════════════════════ */

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    color: #fff;
    flex-shrink: 0;
    letter-spacing: -0.3px;
}

.role-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.role-badge-admin {
    background: var(--accent-bg);
    color: var(--accent);
}

.role-badge-member {
    background: var(--surface-2);
    color: var(--text-dim);
}

.admin-user-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    background: var(--surface);
    border-radius: var(--radius);
    margin-bottom: 8px;
    box-shadow: var(--shadow-sm);
    border: none;
    transition: box-shadow 0.2s;
}

.admin-user-info {
    flex: 1;
    min-width: 0;
}

.admin-user-name-line {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.admin-user-detail {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 2px;
}

.admin-pw-section {
    display: none;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.admin-pw-section.open {
    display: flex;
    gap: 8px;
    align-items: center;
    animation: pageIn 0.15s ease-out;
}

.admin-pw-section input {
    flex: 1;
    padding: 8px 12px;
    font-size: 13px;
}

.admin-pw-section button {
    padding: 8px 14px;
    font-size: 12px;
}

.admin-caldav-url {
    font-size: 11px;
    color: var(--text-dim);
    font-family: var(--font-mono);
    margin-top: 2px;
    cursor: pointer;
    transition: color 0.15s;
}

.admin-caldav-url:hover {
    color: var(--accent);
}

.admin-delete-confirm {
    display: none;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    gap: 8px;
    align-items: center;
}

.admin-delete-confirm.open {
    display: flex;
    animation: pageIn 0.15s ease-out;
}

.admin-delete-confirm span {
    flex: 1;
    font-size: 13px;
    color: var(--critical);
    font-weight: 500;
}

/* ══════════════════════════════════════════
   Toast Notifications
   ══════════════════════════════════════════ */

.toast-container {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

.toast {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 18px;
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    animation: toastIn 0.25s ease-out;
    max-width: 320px;
}

.toast-success {
    border-left: 3px solid var(--ok);
}

.toast-error {
    border-left: 3px solid var(--critical);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(20px); }
}

/* ══════════════════════════════════════════
   Push Notification Bell
   ══════════════════════════════════════════ */

.btn-bell {
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-xs);
    display: flex;
    align-items: center;
    transition: color 0.15s;
}

.btn-bell:hover {
    color: var(--accent);
}

.btn-bell.subscribed {
    color: var(--accent);
}

.btn-bell svg {
    width: 20px;
    height: 20px;
}

/* ══════════════════════════════════════════
   Profile Page
   ══════════════════════════════════════════ */

.profile-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow-sm);
    max-width: 500px;
    margin: 0 auto;
}

.profile-avatar-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.profile-avatar {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.profile-avatar .avatar-initials {
    color: #fff;
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -1px;
}

.profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: absolute;
    inset: 0;
}

.profile-avatar-upload {
    font-size: 13px;
    color: var(--accent);
    cursor: pointer;
    font-weight: 500;
}

.profile-avatar-upload input {
    display: none;
}

/* ---- Avatar Crop Modal ---- */
.crop-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}
.crop-modal-backdrop.active { opacity: 1; }

.crop-modal {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border-strong);
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    transform: scale(0.95);
    transition: transform 0.2s ease;
    max-width: calc(100vw - 24px);
}
.crop-modal-backdrop.active .crop-modal { transform: scale(1); }

.crop-canvas {
    border-radius: var(--radius-xs);
    cursor: grab;
    touch-action: none;
    display: block;
}

.crop-actions {
    display: flex;
    gap: 10px;
    width: 100%;
}
.crop-actions button {
    flex: 1;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: opacity 0.15s;
}
.crop-btn-cancel {
    background: var(--surface-2);
    color: var(--text);
}
.crop-btn-save {
    background: var(--accent);
    color: #fff;
}
.crop-actions button:active { opacity: 0.7; }

.profile-fields {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.profile-field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.profile-value {
    font-size: 15px;
    color: var(--text);
}

.profile-edit-row {
    display: flex;
    gap: 8px;
}

.profile-edit-row input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-xs);
    font-size: 14px;
    font-family: var(--font);
    background: var(--surface-2);
}

.profile-edit-row button {
    padding: 8px 14px;
    border: none;
    border-radius: 20px;
    background: var(--accent);
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}

/* Settings page */
.profile-card + .profile-card { margin-top: 12px; }
.profile-card h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
}
.setting-desc {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 12px;
    line-height: 1.4;
}
.setting-select {
    width: 100%;
    padding: 10px 12px;
    border-radius: var(--radius-xs);
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text);
    font-size: 14px;
    font-family: var(--font);
    outline: none;
}
.setting-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-bg);
}
.settings-section-label {
    max-width: 500px;
    margin: 24px auto 8px;
    padding: 0 4px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-dim);
}
.settings-logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    max-width: 500px;
    margin: 24px auto 0;
    padding: 14px;
    border-radius: var(--radius);
    background: var(--critical-bg);
    color: var(--critical);
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.15s, transform 0.1s;
}
.settings-logout-btn:active { transform: scale(0.98); }

/* Event creator info in modal */
.ev-creator-info {
    font-size: 13px;
    color: var(--text-secondary);
    margin: -4px 0 8px;
    font-style: italic;
}

/* Event participant avatar picker */
.ev-participants {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 0 10px;
}

.ev-participants-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    font-weight: 500;
}

.ev-avatar {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: visible;
    cursor: pointer;
    opacity: 0.5;
    filter: grayscale(30%);
    border: 2px solid transparent;
    transition: opacity 0.15s, border-color 0.15s, transform 0.1s, filter 0.15s;
    flex-shrink: 0;
}

.ev-avatar:hover {
    opacity: 0.8;
    filter: none;
}

.ev-avatar.selected {
    opacity: 1;
    filter: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-bg-strong);
}

.ev-avatar.selected::after {
    content: '\2713';
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 16px;
    height: 16px;
    background: var(--accent);
    color: #fff;
    border-radius: 50%;
    font-size: 10px;
    line-height: 16px;
    text-align: center;
    font-weight: 700;
}

.ev-avatar:active {
    transform: scale(0.92);
}

.ev-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 50%;
}

.ev-avatar-initials {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* Reminder add row in modal */
.ev-reminders-section {
    margin-bottom: 10px;
}

.ev-reminder-add-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

.ev-reminder-add-row select {
    flex: 1;
    margin-bottom: 0;
}

.ev-reminder-add-row button {
    padding: 10px 16px;
    font-size: 16px;
    font-weight: 600;
    line-height: 1;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
}

.ev-reminder-add-row button:hover {
    background: var(--accent-light);
}

/* Calendar event with creator */
.cal-event {
    font-size: 11px;
    padding: 2px 4px 2px 7px;
    border-radius: 3px;
    margin-top: 2px;
    cursor: pointer;
    overflow: hidden;
    white-space: nowrap;
    transition: opacity 0.15s;
    position: relative;
}
.cal-event-stripe {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    border-radius: 3px 0 0 3px;
}
.cal-event-text {
    overflow: hidden;
    text-overflow: ellipsis;
}

.cal-event:hover {
    opacity: 0.8;
}

/* Multi-day spanning events */
.cal-week-row {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}
.cal-span-layer {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-auto-rows: 20px;
    column-gap: 1px;
    row-gap: 2px;
    padding: 2px 0 1px 0;
    background: var(--surface);
}
.cal-span-event {
    height: 18px;
    font-size: 11px;
    padding: 1px 6px 1px 8px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    cursor: pointer;
    display: flex;
    align-items: center;
    position: relative;
    font-weight: 500;
    transition: opacity 0.15s;
}
.cal-span-event:hover { opacity: 0.75; }
.cal-span-stripe {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
}
.cal-span-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cal-week-days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: var(--border);
    flex: 1;
    min-height: 0;
}

/* Weekend dimming */
.cal-weekend { background: var(--surface-2); }
.cal-weekend .cal-day-num { color: var(--text-dim); }
.cal-tl-col-weekend { background: rgba(0,0,0,0.02); }

/* Past events dimming */
.cal-tl-event-past { opacity: 0.45; filter: grayscale(30%); }
.cal-tl-event-past:hover { opacity: 0.7; filter: none; }

/* Today column highlight in week view */
.cal-tl-col-today {
    background: var(--accent-bg);
}
.cal-tl-col-today .cal-tl-slot {
    border-top-color: rgba(99, 102, 241, 0.1);
}

/* Event tooltip */
.ev-tooltip {
    position: fixed;
    z-index: 1000;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text);
    box-shadow: var(--shadow-lg);
    max-width: 260px;
    pointer-events: none;
    animation: tooltipIn 0.12s ease-out;
}
.ev-tooltip strong { font-weight: 600; }
.ev-tooltip-desc { opacity: 0.6; font-size: 12px; }
@keyframes tooltipIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

/* Drag cursor */
.cal-tl-event { cursor: pointer; }

/* Multi-color stripe for timeline events */
.cal-tl-event-stripe {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    border-radius: 3px 0 0 3px;
}

/* Header avatar link */
.header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    text-decoration: none;
    flex-shrink: 0;
}

.header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.header-avatar span {
    color: #fff;
    font-size: 14px;
    font-weight: 700;
}

/* Alert History */
.alert-all-ok {
    text-align: center;
    padding: 1rem;
    color: var(--green, #22c55e);
    font-weight: 600;
    font-size: 1.1rem;
}
.alert-current-states {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    overflow-x: auto;
}
.alert-state-card {
    background: var(--surface);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    min-width: 200px;
    border-left: 3px solid var(--red, #ef4444);
    box-shadow: var(--shadow, 0 1px 3px rgba(0,0,0,0.1));
}
.alert-state-details {
    font-size: 0.8rem;
    color: var(--text-muted, #94a3b8);
    margin-top: 0.25rem;
    white-space: pre-line;
}
.alert-state-since {
    font-size: 0.75rem;
    color: var(--text-muted, #94a3b8);
    margin-top: 0.25rem;
}
.alert-history-table {
    padding: 0 1rem 2rem;
    overflow-x: auto;
}
.alert-history-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.alert-history-table th,
.alert-history-table td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border, #e2e0dc);
}
.alert-history-table th {
    color: var(--text-muted, #94a3b8);
    font-weight: 500;
    font-size: 0.8rem;
    text-transform: uppercase;
}
.alert-details-cell {
    max-width: 300px;
    white-space: pre-line;
    word-break: break-word;
    font-size: 0.8rem;
}
.btn-alerts {
    padding: 0.3rem 0.7rem;
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    font-size: 0.8rem;
    border: 1px solid var(--border, #e2e0dc);
}
.btn-alerts:hover {
    background: var(--border, #e2e0dc);
}

/* ══════════════════════════════════════════
   Stats Dashboard
   ══════════════════════════════════════════ */
.sd-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    flex-wrap: wrap;
}
.sd-header .back {
    text-decoration: none;
    font-size: 1.2rem;
}
.sd-header h1 {
    font-size: 1.25rem;
    margin: 0;
    margin-right: auto;
    color: var(--text);
}
.sd-ticker-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: rgba(99, 102, 241, 0.12);
    color: var(--accent-light, #818cf8);
    border: 1px solid rgba(99, 102, 241, 0.25);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
}
.sd-ticker-btn:hover {
    background: rgba(99, 102, 241, 0.22);
    border-color: rgba(99, 102, 241, 0.45);
    color: var(--accent-light, #818cf8);
}
.sd-filters {
    display: flex;
    gap: 8px;
    margin-left: auto;
}
.sd-header select {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.85rem;
    cursor: pointer;
}
.sd-summary-cards {
    display: flex;
    gap: 12px;
    padding: 8px 16px 16px;
    flex-wrap: wrap;
}
.sd-card {
    flex: 1;
    min-width: 140px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    cursor: pointer;
    transition: background 0.15s;
}
.sd-card:hover { background: var(--surface-2, var(--surface)); }
.sd-card-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}
.sd-card-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    font-family: var(--font-mono);
}
.sd-card-trend {
    font-size: 0.75rem;
    font-weight: 600;
    margin-top: 4px;
}
.sd-card-trend.up { color: #22c55e; }
.sd-card-trend.down { color: #ef4444; }
.sd-card-trend.neutral { color: var(--text-secondary); }
.sd-section {
    padding: 0 16px 16px;
}
.sd-section-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0 0 12px;
}
.sd-charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.sd-chart-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
}
.sd-chart-card h3 {
    margin: 0 0 12px;
    font-size: 0.95rem;
    color: var(--text);
}
.sd-chart-wrap {
    position: relative;
    height: 260px;
}
.sd-conversion {
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 8px 0 0;
    text-align: center;
}
.sd-top-buyers {
    padding: 0 16px 100px;
}
.sd-top-buyers h3 {
    margin: 0 0 12px;
    font-size: 0.95rem;
    color: var(--text);
}
.sd-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.sd-table th,
.sd-table td {
    padding: 10px 14px;
    text-align: left;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
}
.sd-table th {
    background: var(--surface-raised, var(--surface));
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.sd-table td {
    color: var(--text);
    font-family: var(--font-mono);
}
.sd-table tr:last-child td {
    border-bottom: none;
}
.sd-table .sd-skill-link {
    cursor: pointer;
    color: var(--accent);
    font-family: var(--font);
}
.sd-table .sd-skill-link:hover {
    text-decoration: underline;
}
.sd-loading {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}
#sd-loading-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.15);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}
#sd-loading-overlay.active {
    display: flex;
}
.sd-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: var(--accent, #6366f1);
    border-radius: 50%;
    animation: sd-spin 0.7s linear infinite;
}
@keyframes sd-spin {
    to { transform: rotate(360deg); }
}
@media (max-width: 768px) {
    .sd-charts-grid {
        grid-template-columns: 1fr;
    }
    .sd-summary-cards {
        gap: 8px;
        display: grid;
        grid-template-columns: 1fr 1fr;
    }
    .sd-card {
        min-width: 0;
        padding: 12px;
    }
    .sd-card-value {
        font-size: 1.1rem;
    }
    .sd-header {
        padding: 12px;
    }
    .sd-filters {
        margin-left: 0;
        width: 100%;
    }
    .sd-filters select {
        flex: 1;
    }
    .sd-table th,
    .sd-table td {
        padding: 8px 10px;
        font-size: 0.78rem;
    }
    .sd-top-buyers {
        overflow-x: auto;
    }
}

/* ── Skill Tester ── */
.st-header { padding: 16px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border, #333); }
.st-header h1 { font-size: 1.2rem; margin: 0; font-weight: 600; letter-spacing: 0.5px; }
.st-controls { display: flex; gap: 10px; padding: 12px 16px; flex-wrap: wrap; border-bottom: 1px solid var(--border, #333); align-items: center; }
.st-controls select { flex: 1; min-width: 100px; padding: 10px 12px; border: 1px solid var(--border, #444); border-radius: 8px; background: var(--surface); color: var(--text); font-size: 0.9rem; transition: all 0.2s; }
.st-controls select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99,102,241,0.15); }
.st-btn-start { padding: 10px 24px; background: var(--accent); color: #fff; border: none; border-radius: 8px; font-size: 0.9rem; font-weight: 600; cursor: pointer; white-space: nowrap; transition: all 0.2s; box-shadow: 0 2px 8px rgba(99,102,241,0.3); }
.st-btn-start:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(99,102,241,0.4); }
.st-btn-start:disabled { opacity: 0.5; cursor: not-allowed; }
.st-main { display: flex; gap: 16px; padding: 16px; min-height: 400px; }
.st-chat { flex: 1; background: var(--surface); border: 1px solid var(--border, #333); border-radius: 12px; padding: 16px; overflow-y: auto; max-height: 500px; display: flex; flex-direction: column; gap: 12px; }
.st-bubble { padding: 12px 16px; border-radius: 18px; max-width: 85%; font-size: 0.9rem; line-height: 1.5; box-shadow: 0 1px 4px rgba(0,0,0,0.1); animation: st-fadein 0.3s ease; }
@keyframes st-fadein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.st-alexa { background: var(--bg, #f0f0f0); align-self: flex-start; border-bottom-left-radius: 4px; }
.st-player { background: var(--accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.st-label { display: block; font-size: 0.65rem; font-weight: 700; opacity: 0.5; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.st-review { width: 320px; flex-shrink: 0; background: var(--surface); border: 1px solid var(--border, #333); border-radius: 12px; padding: 16px; overflow-y: auto; max-height: 500px; }
.st-review h3 { margin: 0 0 14px; font-size: 1.1rem; font-weight: 700; border-bottom: 2px solid var(--accent); padding-bottom: 8px; }
.st-score { font-size: 1.1rem; margin-bottom: 14px; padding: 10px 12px; background: rgba(99,102,241,0.08); border-radius: 8px; border-left: 4px solid var(--accent); }
.st-score strong { font-size: 1.3rem; color: var(--accent); }
.st-issue { padding: 12px; border-radius: 8px; margin-bottom: 10px; font-size: 0.85rem; border-left: 4px solid; }
.st-issue blockquote { margin: 8px 0 0; padding: 8px 12px; border-left: 3px solid currentColor; opacity: 0.8; font-style: italic; background: rgba(0,0,0,0.05); border-radius: 4px; }
.st-issue-header { font-weight: 700; margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.st-sev-high { background: rgba(248,113,113,0.1); border-left-color: #f87171; }
.st-sev-medium { background: rgba(251,191,36,0.1); border-left-color: #fbbf24; }
.st-sev-low { background: rgba(99,102,241,0.1); border-left-color: #6366f1; }
.st-sev { font-size: 0.65rem; padding: 2px 8px; border-radius: 4px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.3px; }
.st-sev-high .st-sev { background: #f87171; color: #fff; }
.st-sev-medium .st-sev { background: #fbbf24; color: #000; }
.st-sev-low .st-sev { background: #6366f1; color: #fff; }
.st-status { text-align: center; padding: 24px; color: var(--text-secondary); animation: st-pulse 1.5s ease-in-out infinite; }
@keyframes st-pulse { 0%, 100% { opacity: 0.5; } 50% { opacity: 1; } }
.st-error { text-align: center; padding: 12px; color: var(--critical); background: rgba(248,113,113,0.1); border: 1px solid rgba(248,113,113,0.3); border-radius: 8px; }
.st-empty { text-align: center; padding: 40px; color: var(--text-secondary); }
.st-history { padding: 16px; border-top: 1px solid var(--border, #333); }
.st-history h3 { font-size: 1rem; margin: 0 0 10px; font-weight: 700; }
.st-hist-item { padding: 10px 14px; background: var(--surface); border: 1px solid var(--border, #444); border-radius: 10px; margin-bottom: 8px; cursor: pointer; font-size: 0.85rem; display: flex; align-items: center; gap: 10px; transition: all 0.2s; }
.st-hist-item:hover { border-color: var(--accent); transform: translateX(2px); }
.st-turns { color: var(--text-secondary); font-size: 0.8rem; }
.st-date { color: var(--text-secondary); font-size: 0.75rem; margin-left: auto; white-space: nowrap; }
.st-status-running { border-left: 4px solid var(--accent); }
.st-status-completed { border-left: 4px solid var(--ok); }
.st-status-error { border-left: 4px solid var(--critical); }
.st-empty-hist { color: var(--text-secondary); font-size: 0.85rem; padding: 16px; text-align: center; }
@media (max-width: 768px) {
    .st-main { flex-direction: column; }
    .st-review { width: 100%; }
    .st-bubble { max-width: 90%; }
}
