@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;700&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
    --olive: #4f5a2a;
    --olive-light: #6b7a3a;
    --olive-tint: #eef1e4;
    --sage: #8fa35e;
    --copper: #b5651d;
    --copper-tint: #f5e8dc;
    --bg: #f6f5f1;
    --card: #ffffff;
    --text: #22261a;
    --muted: #767a6a;
    --border: #e6e5dc;
    --radius: 14px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', sans-serif;
}

h1, h2, h3, .brand-text { font-family: 'Space Grotesk', sans-serif; }

.mono { font-family: 'IBM Plex Mono', monospace; }

/* ---------- App shell / sidebar ---------- */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 220px;
    flex-shrink: 0;
    background: var(--olive);
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: 24px 18px;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 4px 24px;
    border-bottom: 1px solid rgba(255,255,255,0.15);
    margin-bottom: 20px;
}

.brand-mark { font-size: 1.4rem; }
.brand-text {
    font-size: 0.92rem;
    font-weight: 700;
    line-height: 1.2;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-grow: 1;
}

.sidebar-nav a {
    color: rgba(255,255,255,0.78);
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 0.92rem;
    font-weight: 500;
}

.sidebar-nav a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar-nav a.active { background: rgba(255,255,255,0.16); color: #fff; }

.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.15);
    padding-top: 16px;
}

.user-chip { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }

.user-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--sage);
    color: var(--olive);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
    font-family: 'Space Grotesk', sans-serif;
}

.user-name { font-size: 0.88rem; font-weight: 600; }
.user-role { font-size: 0.76rem; color: rgba(255,255,255,0.65); }

.logout-link {
    display: block;
    color: rgba(255,255,255,0.75);
    text-decoration: none;
    font-size: 0.85rem;
}
.logout-link:hover { color: #fff; }

.main-content {
    flex-grow: 1;
    padding: 32px 40px;
    max-width: 980px;
}

/* ---------- Cards / general ---------- */

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px 26px;
    margin-bottom: 22px;
}

.card h3 { margin-top: 0; font-size: 1.05rem; }

/* ---------- Hero status card + pulse signature ---------- */

.status-hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 20px;
}

.status-left { display: flex; align-items: center; gap: 18px; }

.pulse-dot {
    position: relative;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: var(--muted);
    flex-shrink: 0;
}

.pulse-dot.on { background: var(--sage); }
.pulse-dot.on::after {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px solid var(--sage);
    animation: pulse-ring 1.8s ease-out infinite;
}

.pulse-dot.off { background: var(--copper); }

@keyframes pulse-ring {
    0%   { transform: scale(0.6); opacity: 0.9; }
    100% { transform: scale(1.6); opacity: 0; }
}

.status-reading .state-word {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
}

.state-word.on { color: var(--olive); }
.state-word.off { color: var(--copper); }

.status-reading .voltage {
    font-family: 'IBM Plex Mono', monospace;
    color: var(--muted);
    font-size: 0.92rem;
}

.override-note {
    font-size: 0.88rem;
    color: var(--muted);
    margin-top: 4px;
}

/* ---------- Tables ---------- */

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 9px 6px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
td.mono, td .mono { font-family: 'IBM Plex Mono', monospace; font-size: 0.87rem; }

/* ---------- Badges ---------- */

.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.82rem;
}
.badge.on { background: var(--olive-tint); color: var(--olive); }
.badge.off { background: var(--copper-tint); color: var(--copper); }

/* ---------- Schedule day picker ---------- */

.day-checkboxes {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.day-check {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.88rem;
    cursor: pointer;
    user-select: none;
}

.day-check:has(input:checked) {
    background: var(--olive-tint);
    border-color: var(--olive-light);
    color: var(--olive);
    font-weight: 600;
}

.day-check input { width: auto; padding: 0; margin: 0; }

/* ---------- Forms ---------- */

form.inline { display: inline; }

input, select, button {
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    padding: 9px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

button {
    background: var(--olive);
    color: white;
    border: none;
    cursor: pointer;
    font-weight: 600;
}
button:hover { background: var(--olive-light); }
button.danger { background: var(--copper); }
button.danger:hover { background: #9a5217; }

.flash {
    background: var(--olive-tint);
    color: var(--olive);
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 18px;
    font-size: 0.88rem;
}

/* ---------- Login page ---------- */

.login-wrap {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--olive);
}

.login-card {
    background: var(--card);
    border-radius: 18px;
    padding: 42px;
    width: 320px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}

.login-card .brand-mark { font-size: 1.6rem; }
.login-card h2 {
    margin: 6px 0 26px;
    font-size: 1.15rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.login-card label { display: block; margin: 12px 0 4px; font-size: 0.82rem; color: var(--muted); }
.login-card input { width: 100%; }
.login-card button { width: 100%; margin-top: 22px; }

@media (max-width: 800px) {
    .app-shell { flex-direction: column; }
    .sidebar {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        padding: 0;
    }
    .sidebar-brand {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        border: none;
        margin: 0;
        padding: 14px 18px;
    }
    .sidebar-nav {
        flex-direction: row;
        width: 100%;
        gap: 0;
        border-top: 1px solid rgba(255,255,255,0.15);
        border-bottom: 1px solid rgba(255,255,255,0.15);
    }
    .sidebar-nav a {
        flex: 1;
        text-align: center;
        border-radius: 0;
        padding: 12px 8px;
    }
    .sidebar-footer {
        border-top: none;
        padding: 10px 18px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 14px;
    }
    .user-chip { margin-bottom: 0; }
    .main-content { padding: 24px 18px; }
}

@media (max-width: 520px) {
    .sidebar-brand { padding: 12px 14px; }
    .brand-text { font-size: 0.85rem; }
    .sidebar-nav a { padding: 10px 4px; font-size: 0.82rem; }
    .user-chip .user-name, .user-chip .user-role { display: none; }
    .logout-link { font-size: 0.8rem; }

    .main-content { padding: 16px 12px; }

    .card { padding: 16px 16px; margin-bottom: 14px; }
    .card h3 { font-size: 0.95rem; }

    .status-hero { flex-direction: column; align-items: flex-start; }
    .status-hero form { width: 100%; }
    .status-hero form select,
    .status-hero form input,
    .status-hero form button { flex: 1 1 auto; }

    .state-word { font-size: 1.25rem; }
    .voltage { font-size: 0.82rem; }

    table { font-size: 0.82rem; min-width: 0; width: 100%; }
    th, td { padding: 7px 5px; white-space: normal; }

    td form.inline { display: block; margin: 4px 0; }
    td form.inline button { width: 100%; }

    .login-card { width: 90vw; max-width: 320px; padding: 30px 24px; }

    .day-checkboxes { gap: 6px; }
    .day-check { padding: 6px 9px; font-size: 0.82rem; }
}
