:root {
    --bg: #070b16;
    --card: rgba(15, 23, 42, 0.78);
    --card-border: rgba(148, 163, 184, 0.18);
    --text: #f8fafc;
    --muted: #94a3b8;
    --soft: #cbd5e1;
    --primary: #38bdf8;
    --primary-dark: #0284c7;
    --green: #22c55e;
    --green-dark: #16a34a;
    --red: #ef4444;
    --red-dark: #dc2626;
    --yellow: #facc15;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    --radius: 22px;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    min-height: 100vh;
    margin: 0;
    background:
        radial-gradient(circle at top left, rgba(56, 189, 248, 0.18), transparent 32rem),
        radial-gradient(circle at bottom right, rgba(34, 197, 94, 0.12), transparent 30rem),
        var(--bg);
    color: var(--text);
    font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    overflow-x: hidden;
}

.background-glow {
    position: fixed;
    width: 26rem;
    height: 26rem;
    border-radius: 999px;
    filter: blur(90px);
    opacity: 0.18;
    z-index: -1;
}

.glow-one {
    top: 8rem;
    left: -8rem;
    background: #38bdf8;
}

.glow-two {
    right: -10rem;
    bottom: 3rem;
    background: #22c55e;
}

.glass-card {
    background: var(--card);
    border: 1px solid var(--card-border);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

.app-header {
    width: calc(100% - 32px);
    margin: 16px auto 0;
    padding: 22px 24px;
    border-radius: var(--radius);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    color: var(--primary);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.app-header h1 {
    margin: 0;
    font-size: clamp(28px, 4vw, 44px);
    line-height: 1;
    letter-spacing: -0.04em;
}

.app-header p {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 15px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.refresh-pill {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 11px 14px;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid var(--card-border);
    border-radius: 999px;
    color: var(--soft);
    font-size: 14px;
    white-space: nowrap;
}

.pulse-dot {
    width: 9px;
    height: 9px;
    border-radius: 999px;
    background: var(--green);
    box-shadow: 0 0 0 rgba(34, 197, 94, 0.5);
    animation: pulse 1.8s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55);
    }

    70% {
        box-shadow: 0 0 0 9px rgba(34, 197, 94, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
    }
}

.page-layout {
    width: calc(100% - 32px);
    margin: 18px auto 32px;
}

.controls-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    margin-bottom: 18px;
}

.device-card {
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
}

.device-info {
    display: flex;
    align-items: center;
    gap: 14px;
}

.device-icon {
    width: 54px;
    height: 54px;
    display: grid;
    place-items: center;
    border-radius: 18px;
    background:
        linear-gradient(135deg, rgba(56, 189, 248, 0.24), rgba(34, 197, 94, 0.12));
    border: 1px solid rgba(148, 163, 184, 0.18);
    font-size: 25px;
}

.device-card h2 {
    margin: 0;
    font-size: 21px;
}

.device-card p {
    margin: 5px 0 0;
    color: var(--muted);
}

.button-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

button,
.primary-btn,
.secondary-btn,
.ghost-btn,
.danger-btn {
    border: 0;
    border-radius: 15px;
    padding: 12px 17px;
    color: white;
    font-size: 15px;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
    transition:
        transform 0.18s ease,
        opacity 0.18s ease,
        box-shadow 0.18s ease;
}

button:hover,
.primary-btn:hover,
.secondary-btn:hover,
.ghost-btn:hover,
.danger-btn:hover {
    transform: translateY(-1px);
    opacity: 0.95;
}

.primary-btn {
    background: linear-gradient(135deg, var(--green), var(--green-dark));
    box-shadow: 0 12px 30px rgba(34, 197, 94, 0.22);
}

.secondary-btn {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    box-shadow: 0 12px 30px rgba(56, 189, 248, 0.2);
}

.ghost-btn {
    background: rgba(148, 163, 184, 0.12);
    border: 1px solid rgba(148, 163, 184, 0.18);
}

.danger-btn {
    background: linear-gradient(135deg, var(--red), var(--red-dark));
    box-shadow: 0 12px 30px rgba(239, 68, 68, 0.2);
}

.grafana-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.grafana-card {
    min-height: 420px;
    border-radius: var(--radius);
    overflow: hidden;
}

.panel-header {
    min-height: 82px;
    padding: 16px 18px;
    background: rgba(2, 6, 23, 0.42);
    border-bottom: 1px solid var(--card-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.panel-header h2 {
    margin: 0;
    font-size: 20px;
    letter-spacing: -0.02em;
}

.panel-header p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 14px;
}

.range-select {
    min-width: 130px;
    border: 1px solid rgba(148, 163, 184, 0.24);
    border-radius: 14px;
    background: rgba(2, 6, 23, 0.9);
    color: var(--text);
    padding: 11px 12px;
    font-size: 15px;
    outline: none;
}

.range-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.14);
}

.grafana-frame {
    display: block;
    width: 100%;
    height: 350px;
    border: 0;
    background: #020617;
}

.empty-panel {
    height: 350px;
    display: grid;
    place-content: center;
    text-align: center;
    padding: 24px;
    color: var(--muted);
}

.empty-panel div {
    font-size: 42px;
    margin-bottom: 10px;
}

.empty-panel h3 {
    margin: 0 0 8px;
    color: var(--text);
}

.empty-panel p {
    margin: 0;
}

.toast {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 50;
    max-width: 360px;
    padding: 15px 18px;
    border-radius: 16px;
    background: rgba(2, 6, 23, 0.92);
    border: 1px solid rgba(148, 163, 184, 0.22);
    box-shadow: var(--shadow);
    color: var(--text);
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition:
        opacity 0.22s ease,
        transform 0.22s ease;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.login-page {
    display: grid;
    place-items: center;
    padding: 20px;
}

.login-shell {
    width: min(100%, 420px);
}

.login-card {
    border-radius: 28px;
    padding: 34px;
    text-align: left;
}

.login-icon {
    width: 64px;
    height: 64px;
    display: grid;
    place-items: center;
    border-radius: 22px;
    background: linear-gradient(135deg, var(--primary), var(--green));
    color: white;
    font-size: 34px;
    margin-bottom: 18px;
}

.login-card h1 {
    margin: 0;
    font-size: 34px;
    letter-spacing: -0.04em;
}

.login-card p {
    margin: 8px 0 24px;
    color: var(--muted);
}

.login-form {
    display: grid;
    gap: 10px;
}

.login-form label {
    color: var(--soft);
    font-size: 14px;
    font-weight: 700;
}

.login-form input {
    width: 100%;
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 15px;
    background: rgba(2, 6, 23, 0.78);
    color: var(--text);
    padding: 14px 15px;
    font-size: 16px;
    outline: none;
}

.login-form input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.14);
}

.full-width {
    width: 100%;
    margin-top: 12px;
}

.login-error {
    border: 1px solid rgba(239, 68, 68, 0.35);
    background: rgba(239, 68, 68, 0.12);
    color: #fecaca;
    padding: 12px 14px;
    border-radius: 14px;
    margin-bottom: 16px;
}

@media (max-width: 900px) {
    .app-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .header-actions {
        justify-content: flex-start;
    }

    .controls-grid,
    .grafana-grid {
        grid-template-columns: 1fr;
    }

    .device-card {
        align-items: flex-start;
        flex-direction: column;
    }

    .button-row {
        justify-content: flex-start;
    }
}

@media (max-width: 500px) {
    .app-header,
    .page-layout {
        width: calc(100% - 20px);
    }

    .app-header {
        padding: 18px;
    }

    .panel-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .range-select {
        width: 100%;
    }

    .grafana-frame,
    .empty-panel {
        height: 300px;
    }

    .header-actions {
        width: 100%;
    }

    .refresh-pill,
    .secondary-btn,
    .ghost-btn {
        width: 100%;
        justify-content: center;
        text-align: center;
    }
}
.shelly-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    margin-bottom: 18px;
}

.shelly-device {
    border-radius: var(--radius);
    padding: 20px;
}

.device-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 14px;
}

.device-top h2 {
    margin: 0;
    font-size: 24px;
    letter-spacing: -0.03em;
}

.device-top p {
    margin: 5px 0 0;
    color: var(--muted);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 900;
}

.status-badge.online {
    background: rgba(34, 197, 94, 0.14);
    color: #86efac;
    border: 1px solid rgba(34, 197, 94, 0.25);
}

.status-badge.offline {
    background: rgba(239, 68, 68, 0.14);
    color: #fecaca;
    border: 1px solid rgba(239, 68, 68, 0.25);
}

.device-meta {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.device-meta span {
    background: rgba(2, 6, 23, 0.45);
    border: 1px solid rgba(148, 163, 184, 0.14);
    border-radius: 999px;
    padding: 8px 11px;
    color: var(--muted);
    font-size: 13px;
}

.device-meta strong {
    color: var(--text);
}

.channel-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.channel-card {
    background: rgba(2, 6, 23, 0.38);
    border: 1px solid rgba(148, 163, 184, 0.14);
    border-radius: 18px;
    padding: 15px;
}

.channel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 14px;
}

.channel-header h3 {
    margin: 0;
    font-size: 18px;
}

.channel-state {
    margin: 4px 0 0;
    font-size: 13px;
    font-weight: 800;
}

.state-on {
    color: #86efac;
}

.state-off {
    color: #fecaca;
}

.power-dot {
    width: 13px;
    height: 13px;
    border-radius: 999px;
    margin-top: 5px;
}

.power-dot.on {
    background: var(--green);
    box-shadow: 0 0 18px rgba(34, 197, 94, 0.75);
}

.power-dot.off {
    background: var(--red);
    box-shadow: 0 0 18px rgba(239, 68, 68, 0.6);
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 15px;
}

.metric-grid div {
    background: rgba(15, 23, 42, 0.65);
    border-radius: 13px;
    padding: 10px;
}

.metric-grid span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 4px;
}

.metric-grid strong {
    font-size: 16px;
}

.device-error {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.25);
    color: #fecaca;
    border-radius: 16px;
    padding: 14px;
}

@media (max-width: 1100px) {
    .shelly-grid,
    .channel-grid {
        grid-template-columns: 1fr;
    }
}

.logout-form {
    margin: 0;
}

.logout-form button {
    font-family: inherit;
}

.error-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 20px;
}

.error-shell {
    width: min(100%, 600px);
}

.error-card {
    border-radius: 32px;
    padding: 48px;
    text-align: center;
}

.error-code {
    font-size: 110px;
    font-weight: 900;
    line-height: 1;
    margin-bottom: 18px;
    background: linear-gradient(135deg, var(--primary), var(--green));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.error-card h1 {
    margin: 0 0 12px;
    font-size: 42px;
    letter-spacing: -0.04em;
}

.error-card p {
    color: var(--muted);
    margin-bottom: 28px;
    font-size: 18px;
}
