:root {
    --bg: #0f1420;
    --panel: #171e2e;
    --border: #2a3346;
    --text: #e6e9ef;
    --muted: #8b93a7;
    --accent: #ffb020;
    --accent-dark: #cc8a12;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
}

header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    margin: 0;
    font-size: 1.25rem;
}

.user-box {
    display: flex;
    align-items: center;
    gap: .75rem;
    font-size: .9rem;
    color: var(--muted);
}

.user-box button {
    background: var(--border);
    color: var(--text);
    border: none;
    border-radius: 6px;
    padding: .4rem .8rem;
    cursor: pointer;
}

#panel-login {
    max-width: 360px;
    margin: 3rem auto;
}

#panel-change-password {
    max-width: 360px;
    margin: 1.5rem auto 0;
}

.user-box button {
    white-space: nowrap;
}

main {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 1.5rem;
    padding: 1.5rem;
    align-items: start;
}

@media (max-width: 800px) {
    main { grid-template-columns: 1fr; }
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.25rem;
}

#panel-admin, #panel-user-dashboard, #panel-tariffs {
    grid-column: 1 / -1;
}

.panel h2 {
    margin-top: 0;
    font-size: 1rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .05em;
}

.field-row {
    display: flex;
    flex-direction: column;
    gap: .25rem;
    margin-bottom: .75rem;
}

.field-row label {
    font-size: .8rem;
    color: var(--muted);
}

input, select {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 6px;
    padding: .5rem;
    font-size: 1rem;
    color-scheme: dark;
}

.btn-flash {
    width: 100%;
    padding: 1.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: .1em;
    background: var(--accent);
    color: #1a1200;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    margin-top: .5rem;
}

.btn-flash:active {
    background: var(--accent-dark);
}

.last-reading {
    margin-top: 1rem;
    font-size: .9rem;
    color: var(--muted);
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: end;
    margin-bottom: 1rem;
}

.filters label {
    display: flex;
    flex-direction: column;
    gap: .25rem;
    font-size: .8rem;
    color: var(--muted);
}

.filters button {
    background: var(--border);
    color: var(--text);
    border: none;
    border-radius: 6px;
    padding: .55rem 1rem;
    cursor: pointer;
}

.filters button:hover {
    background: var(--accent);
    color: #1a1200;
}

.dashboard-picker {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem 1.25rem;
    margin-bottom: 1rem;
}

.dashboard-picker label {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: .9rem;
}

.dashboard-picker input:disabled + span {
    color: var(--muted);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
    margin-top: 1.25rem;
}

.dashboard-window {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .9rem;
}

.dashboard-window h3 {
    margin: 0 0 .6rem;
    font-size: .9rem;
    color: var(--text);
}

.dashboard-window .chart-wrap {
    height: 140px;
    margin-bottom: .75rem;
}

.dashboard-window table {
    font-size: .78rem;
    margin-top: 0;
}

.dashboard-window th, .dashboard-window td {
    padding: .3rem .4rem;
}

.device-status {
    margin-top: .75rem;
    font-size: .85rem;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: .5rem;
}

.device-status .dot {
    width: .55rem;
    height: .55rem;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--muted);
}

.device-status.online .dot { background: #3ecf72; }
.device-status.stale .dot { background: var(--accent); }
.device-status.offline .dot { background: #ff6b6b; }

.dashboard-window .device-status {
    margin-top: 0;
    margin-bottom: .6rem;
    font-size: .78rem;
}

.btn-delete {
    background: transparent;
    color: #ff6b6b;
    border: 1px solid #ff6b6b;
    border-radius: 6px;
    padding: .3rem .6rem;
    font-size: .8rem;
    cursor: pointer;
}

.btn-delete:hover {
    background: #ff6b6b;
    color: #1a0000;
}

.period-summary {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem 1.5rem;
    margin-bottom: 1rem;
    font-size: .9rem;
    color: var(--muted);
}

.period-summary strong {
    color: var(--text);
    font-size: 1.05rem;
}

.chart-wrap {
    position: relative;
    width: 100%;
    height: 280px;
    margin-bottom: 1rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1.25rem;
    font-size: .9rem;
}

th, td {
    text-align: left;
    padding: .5rem .6rem;
    border-bottom: 1px solid var(--border);
}

th {
    color: var(--muted);
    font-weight: 600;
}

.print-only {
    display: none;
}

@media print {
    body * {
        visibility: hidden;
    }

    #panel-history, #panel-history * {
        visibility: visible;
    }

    #panel-history {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        border: none;
        padding: 0;
    }

    .filters, .btn-delete, #table-readings th:last-child, #table-readings td:last-child {
        display: none !important;
    }

    .print-only {
        display: block;
        margin-bottom: 1rem;
        font-size: .85rem;
        color: #000;
    }

    body, .panel {
        background: #fff;
        color: #000;
    }

    th, td {
        border-bottom: 1px solid #ccc;
    }

    th {
        color: #000;
    }

    .chart-wrap {
        height: 220px;
    }
}
