/* Cold storage energy monitoring dashboard */

:root {
    --primary: #2563eb;
    --primary-light: #dbeafe;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --success: #16a34a;
    --warning: #d97706;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    position: relative;
}

body::before,
body::after {
    content: '';
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 380px;
    height: 675px;
    background: url('/static/bazsi.jpg') center/cover no-repeat;
    border-radius: 12px;
    opacity: 0.7;
    pointer-events: none;
    z-index: 0;
}

body::before {
    left: 20px;
}

body::after {
    right: 20px;
}

@media (max-width: 1500px) {
    body::before,
    body::after {
        display: none;
    }
}

.header {
    background: var(--primary);
    color: white;
    padding: 1rem 2rem;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
}

.header h1 {
    grid-column: 2;
    font-size: 1.25rem;
    font-weight: 600;
    text-align: center;
}

.header .header-left {
    grid-column: 1;
    font-size: 0.8rem;
    opacity: 0.85;
}

.header .header-nav {
    grid-column: 3;
    justify-self: end;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
}

@media (min-width: 1500px) {
    .container {
        max-width: none;
        margin: 0 400px;
    }
}

/* Controls bar */
.controls {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.period-buttons {
    display: flex;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}

.period-buttons button {
    padding: 0.5rem 1rem;
    border: none;
    background: var(--card-bg);
    color: var(--text);
    cursor: pointer;
    font-size: 0.9rem;
    border-right: 1px solid var(--border);
    transition: background 0.15s;
}

.period-buttons button:last-child {
    border-right: none;
}

.period-buttons button:hover {
    background: var(--primary-light);
}

.period-buttons button.active {
    background: var(--primary);
    color: white;
}

.date-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.date-nav button {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--card-bg);
    cursor: pointer;
    font-size: 1rem;
}

.date-nav button:hover {
    background: var(--primary-light);
}

.date-nav .date-label {
    font-weight: 600;
    min-width: 200px;
    text-align: center;
}

.btn-refresh {
    margin-left: auto;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--card-bg);
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.btn-refresh:hover {
    background: var(--primary-light);
    color: var(--primary);
}

/* Summary cards */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

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

.card .card-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.card .card-value {
    font-size: 1.5rem;
    font-weight: 700;
    margin-top: 0.25rem;
}

.card .card-unit {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 400;
}

.card .card-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.35rem;
    font-style: italic;
}

/* Chart area */
.chart-container {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.chart-container canvas {
    width: 100% !important;
    max-height: 400px;
}

/* Device filter */
.device-filter {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 0.75rem 0;
}

.device-filter label {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    transition: background 0.15s;
}

.device-filter label:hover {
    background: var(--primary-light);
}

.device-filter label.checked {
    background: var(--primary-light);
    border-color: var(--primary);
}

/* --- Auth pages --- */

.auth-wrap {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: calc(100vh - 60px);
    padding: 3rem 1rem;
}

.auth-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 2rem;
    width: 100%;
    max-width: 420px;
}

.auth-card h2 {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text);
}

.auth-error {
    background: #fee2e2;
    border: 1px solid #fca5a5;
    color: #b91c1c;
    border-radius: 6px;
    padding: 0.6rem 0.9rem;
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.auth-success {
    background: #dcfce7;
    border: 1px solid #86efac;
    color: #15803d;
    border-radius: 6px;
    padding: 0.6rem 0.9rem;
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.auth-info {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 1.25rem;
}

.auth-info-sm {
    font-size: 0.8rem;
    word-break: break-all;
    margin-top: 0.75rem;
}

.auth-info code {
    background: #f1f5f9;
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.85em;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 0.35rem;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
    color: var(--text);
    background: var(--bg);
    transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
}

.form-group-inline {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.form-group-inline label {
    margin-bottom: 0;
    white-space: nowrap;
}

.form-group-inline select {
    width: auto;
}

.btn-primary {
    width: 100%;
    padding: 0.6rem 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s;
    margin-top: 0.5rem;
}

.btn-primary:hover {
    opacity: 0.9;
}

.btn-danger {
    padding: 0.3rem 0.6rem;
    background: #dc2626;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: opacity 0.15s;
}

.btn-danger:hover {
    opacity: 0.85;
}

.totp-qr {
    text-align: center;
    margin: 1rem 0;
}

.totp-qr img {
    max-width: 220px;
    border: 1px solid var(--border);
    border-radius: 6px;
}

/* Header nav (admin/dashboard) */
.header-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-user {
    font-size: 0.8rem;
    opacity: 0.85;
}

.header-link {
    font-size: 0.85rem;
    color: white;
    text-decoration: none;
    opacity: 0.85;
    border: 1px solid rgba(255,255,255,0.4);
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    transition: opacity 0.15s;
}

.header-link:hover {
    opacity: 1;
}

/* Admin page */
.admin-section {
    margin-bottom: 1.5rem;
    padding: 1.5rem;
}

.section-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text);
}

.invite-form {
    margin-bottom: 0;
}

.invite-form .btn-primary {
    width: auto;
    margin-top: 0;
}

.invite-result {
    margin-top: 1rem;
    padding: 0.75rem;
    background: #f0fdf4;
    border: 1px solid #86efac;
    border-radius: 6px;
    font-size: 0.85rem;
}

.invite-result p {
    margin-bottom: 0.4rem;
    color: var(--text-muted);
}

.invite-token {
    display: block;
    width: 100%;
    box-sizing: border-box;
    font-family: monospace;
    font-size: 0.8rem;
    color: var(--text);
    background: #e8f5e9;
    border: 1px solid #86efac;
    padding: 0.5rem 0.6rem;
    border-radius: 4px;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.admin-table th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 2px solid var(--border);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.admin-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.admin-table tr:last-child td {
    border-bottom: none;
}

.role-badge {
    padding: 0.15rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.role-admin {
    background: #dbeafe;
    color: #1d4ed8;
}

.role-viewer {
    background: #f1f5f9;
    color: var(--text-muted);
}

.text-warning {
    color: var(--warning);
    font-size: 0.8rem;
}

.text-muted {
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* Loading */
.loading {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

/* Help page */
.help-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.25rem 1.5rem;
    margin-top: 0.75rem;
}

.help-card ol {
    padding-left: 1.25rem;
    margin: 0 0 0.75rem 0;
}

.help-card li {
    margin-bottom: 0.4rem;
    font-size: 0.9rem;
    line-height: 1.5;
}

.help-card p {
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}

.help-note {
    background: var(--primary-light);
    border-left: 3px solid var(--primary);
    border-radius: 0 4px 4px 0;
    padding: 0.6rem 0.9rem;
    font-size: 0.82rem;
    color: var(--text);
    margin-top: 0.5rem;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }
    .controls {
        flex-direction: column;
        align-items: stretch;
    }
    .period-buttons {
        width: 100%;
    }
    .period-buttons button {
        flex: 1;
    }
    .date-nav {
        justify-content: center;
    }
    .btn-refresh {
        margin-left: 0;
    }
    .summary-cards {
        grid-template-columns: repeat(2, 1fr);
    }
}
