:root {
    --bg: #0B0F14;
    --sidebar-bg: #0E1319;
    --panel: #131920;
    --panel-border: #232B35;
    --text-primary: #E6EDF3;
    --text-muted: #7C8A9A;
    --accent-on: #2DD4BF;
    --accent-on-dim: rgba(45, 212, 191, 0.12);
    --accent-off: #F87171;
    --accent-off-dim: rgba(248, 113, 113, 0.12);
    --mono: 'IBM Plex Mono', monospace;
    --sans: 'Inter', -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
    font-family: var(--sans);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    background:
        linear-gradient(rgba(11,15,20,0.45), rgba(11,15,20,0.45)),
        url('img/bg-photo.png') center center / cover no-repeat fixed;
}

/* Sidebar */
.sidebar {
    width: 232px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--panel-border);
    padding: 22px 16px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 22px; }
.brand-mark {
    width: 30px; height: 30px; border-radius: 8px;
    background: var(--accent-on-dim);
    display: flex; align-items: center; justify-content: center;
    color: var(--accent-on); font-family: var(--mono); font-weight: 600; font-size: 13px;
}
.brand-text { font-size: 14px; font-weight: 600; line-height: 1.2; }
.brand-text small {
    display: inline-block;
    font-size: 14px;
    font-weight: 500;
    font-family: var(--mono);
    color: hwb(0 2% 2%);
    background: rgba(167,139,250,0.14);
    padding: 2px 8px;
    border-radius: 6px;
    margin-top: 4px;
}

.nav-section-label {
    font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--text-muted); font-weight: 600; padding: 14px 12px 6px;
}
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; border-radius: 8px;
    color: var(--text-muted); text-decoration: none;
    font-size: 13px; font-weight: 500;
    margin-bottom: 2px; cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,0.08); color: var(--text-primary); }
.nav-item:active { background: rgba(45,212,191,0.20); }
.nav-item.active {
    background: var(--accent-on-dim); color: var(--accent-on);
    border-color: rgba(45,212,191,0.4); font-weight: 600;
}

.sidebar-footer {
    margin-top: auto;
    border-top: 1px solid var(--panel-border);
    padding-top: 14px;
    display: flex; align-items: center; gap: 8px;
    font-family: var(--mono); font-size: 11px; color: var(--text-muted);
}
.sidebar-footer-group {
    margin-top: auto;
    border-top: 1px solid var(--panel-border);
    padding-top: 14px;
}
.conn-line {
    display: flex; align-items: center; gap: 8px;
    font-family: var(--mono); font-size: 11px; color: var(--text-muted);
    padding: 0 8px 12px;
}
.pulse-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--accent-on);
    animation: pulse 2s infinite;
    flex-shrink: 0;
}
@keyframes pulse {
    0%   { box-shadow: 0 0 0 0 rgba(45,212,191,0.55); }
    70%  { box-shadow: 0 0 0 6px rgba(45,212,191,0); }
    100% { box-shadow: 0 0 0 0 rgba(45,212,191,0); }
}
@keyframes pulse-white {
    0%   { box-shadow: 0 0 0 0 rgba(255,255,255,0.6); }
    70%  { box-shadow: 0 0 0 6px rgba(255,255,255,0); }
    100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); }
}

/* User menu */
.user-menu { position: relative; }
.user-menu-trigger {
    width: 100%; display: flex; align-items: center; gap: 10px;
    background: none; border: 1px solid transparent; border-radius: 8px;
    padding: 8px; cursor: pointer; color: var(--text-primary); font-family: var(--sans);
    text-align: left;
}
.user-menu-trigger:hover { background: rgba(255,255,255,0.03); border-color: var(--panel-border); }
.user-avatar {
    width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
    background: var(--accent-on-dim); color: var(--accent-on);
    display: flex; align-items: center; justify-content: center;
    font-family: var(--mono); font-size: 12px; font-weight: 600;
}
.user-name { flex: 1; font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chevron { width: 14px; height: 14px; color: var(--text-muted); flex-shrink: 0; }

.user-dropdown {
    position: absolute; bottom: calc(100% + 6px); left: 0; right: 0;
    background: #0B0F14; border: 1px solid var(--panel-border); border-radius: 8px;
    padding: 6px; display: none; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.user-dropdown.open { display: block; }
.user-dropdown-item {
    width: 100%; display: flex; align-items: center; gap: 8px;
    background: none; border: none; color: var(--accent-off);
    padding: 8px 10px; border-radius: 6px; cursor: pointer;
    font-family: var(--sans); font-size: 13px; font-weight: 500;
}
.user-dropdown-item svg { width: 15px; height: 15px; }
.user-dropdown-item:hover { background: var(--accent-off-dim); }

/* Modal popup */
.modal-overlay {
    display: none; position: fixed; inset: 0; background: rgba(5,8,11,0.7);
    align-items: center; justify-content: center; z-index: 100;
}
.modal-overlay.open { display: flex; }
.modal-box {
    background: var(--panel); border: 1px solid var(--panel-border); border-radius: 12px;
    padding: 24px; width: 100%; max-width: 320px;
}
.modal-title { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.modal-desc { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.btn.danger { background: var(--accent-off-dim); border-color: var(--accent-off); color: var(--accent-off); text-decoration: none; display: inline-flex; align-items: center; }

/* Main content */
.main { flex: 1; padding: 28px 36px 60px; max-width: 1040px; }
.page-header { margin-bottom: 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-header h1 { font-size: 19px; font-weight: 600; margin: 0 0 4px; text-shadow: 0 1px 4px rgba(0,0,0,0.65); }
.page-header .device-tag { font-family: var(--mono); font-size: 15px; color: #B9C4D0; text-shadow: 0 1px 4px rgba(0,0,0,0.65); }

.grid { display: grid; grid-template-columns: 300px 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 900px) { .grid { grid-template-columns: 1fr; } .sidebar { position: relative; height: auto; } body { flex-direction: column; } }

.panel { background: var(--panel); border: 1px solid var(--panel-border); border-radius: 10px; padding: 20px; }
.panel-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); font-weight: 600; margin-bottom: 14px; }

/* Mode kontrol relay: Auto / Manual ON / Manual OFF (dashboard) */
.relay-card { display: flex; flex-direction: column; align-items: center; text-align: center; }
.mode-group { display: flex; gap: 8px; width: 100%; }
.mode-btn {
    flex: 1; padding: 10px 8px; border-radius: 8px; border: 1px solid var(--panel-border);
    background: #0B0F14; color: var(--text-muted); font-family: var(--mono);
    font-size: 12px; font-weight: 600; cursor: pointer; transition: all 0.15s;
}
.mode-btn:hover { border-color: var(--accent-on); color: var(--accent-on); }
.mode-btn.active { font-weight: 700; box-shadow: 0 0 0 1px currentColor inset; }
.mode-btn.auto.active { color: #60A5FA; background: rgba(96,165,250,0.14); border-color: #60A5FA; }
.mode-btn.on.active { color: var(--accent-on); background: var(--accent-on-dim); border-color: var(--accent-on); }
.mode-btn.off.active { color: var(--accent-off); background: var(--accent-off-dim); border-color: var(--accent-off); }
.relay-state { margin-top: 16px; font-family: var(--mono); font-size: 22px; font-weight: 700; letter-spacing: 0.05em; padding: 10px 24px; border-radius: 24px; }
.relay-state.on  { color: var(--accent-on); background: var(--accent-on-dim); }
.relay-state.off { color: var(--accent-off); background: var(--accent-off-dim); }
.relay-hint { color: var(--text-muted); font-size: 12px; margin-top: 10px; }

/* Setpoint mode auto (dashboard) */
.setpoint-field label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.setpoint-input-wrap { position: relative; display: flex; align-items: center; }
.setpoint-input-wrap .text-input { width: 100%; padding-right: 30px; }
.setpoint-input-wrap .unit { position: absolute; right: 12px; font-size: 12px; color: var(--text-muted); pointer-events: none; }

.readout-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 180px)); gap: 14px; }
.readout { background: #0B0F14; border: 1px solid var(--panel-border); border-radius: 8px; padding: 14px; }
.readout-value { font-family: var(--mono); font-size: 26px; font-weight: 500; line-height: 1; }
.readout-value .unit { font-size: 15px; color: var(--text-muted); margin-left: 2px; }
.readout-name { font-size: 12px; color: var(--text-muted); margin-top: 8px; }

.chart-panel { margin-top: 16px; }
.chart-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.last-update { font-family: var(--mono); font-size: 11px; color: var(--text-muted); }
canvas { max-height: 260px; }

/* Table (history page) */
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th {
    text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--text-primary); font-weight: 700; padding: 12px;
    background: #0B0F14; border-bottom: 2px solid var(--accent-on);
}
table.data-table th:first-child { border-top-left-radius: 8px; }
table.data-table th:last-child { border-top-right-radius: 8px; }
table.data-table td { padding: 10px 12px; border-bottom: 1px solid rgba(35,43,53,0.6); font-family: var(--mono); }
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tbody tr:nth-child(odd) td { background: #4A3B0F; }
table.data-table tbody tr:nth-child(even) td { background: #163D28; }
table.data-table tr:hover td { background: rgba(45,212,191,0.22); }

.toolbar { display: flex; gap: 10px; margin-bottom: 16px; align-items: center; flex-wrap: wrap; }

.pagination {
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: 12px; margin-top: 18px; padding-top: 16px;
    border-top: 1px solid var(--panel-border);
}
.pagination-info { font-size: 12px; color: var(--text-muted); font-family: var(--mono); }
.pagination-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pagination-jump { display: flex; align-items: center; gap: 6px; }
.pagination-input { width: 64px; text-align: center; padding: 8px 6px; }
.btn.disabled { opacity: 0.35; pointer-events: none; cursor: default; }
.select-input, .btn {
    background: #0B0F14; border: 1px solid var(--panel-border); color: var(--text-primary);
    padding: 8px 12px; border-radius: 8px; font-family: var(--sans); font-size: 13px;
}
.text-input {
    background: #0B0F14; border: 1px solid var(--panel-border); color: var(--text-primary);
    padding: 10px 12px; border-radius: 8px; font-family: var(--mono); font-size: 13px;
}
.btn { cursor: pointer; font-weight: 600; }
.btn:hover { border-color: var(--accent-on); color: var(--accent-on); }
.btn.primary { background: var(--accent-on-dim); border-color: var(--accent-on); color: var(--accent-on); }

/* Devices page */
.device-list { display: flex; flex-direction: column; gap: 12px; }
.device-row {
    display: flex; align-items: center; justify-content: space-between;
    background: #0B0F14; border: 1px solid var(--panel-border); border-radius: 10px; padding: 14px 18px;
}
.device-row-left { display: flex; align-items: center; gap: 14px; }
.device-icon {
    width: 36px; height: 36px; border-radius: 8px; background: var(--accent-on-dim);
    display: flex; align-items: center; justify-content: center; color: var(--accent-on);
}
.device-id { font-family: var(--mono); font-size: 13px; font-weight: 600; }
.device-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.status-pill { font-family: var(--mono); font-size: 12px; font-weight: 600; padding: 4px 12px; border-radius: 20px; }
.status-pill.on { color: var(--accent-on); background: var(--accent-on-dim); }
.status-pill.off { color: var(--accent-off); background: var(--accent-off-dim); }

.online-badge {
    display: inline-flex; align-items: center; gap: 8px;
    font-family: var(--mono); font-size: 14px; font-weight: 700;
    padding: 7px 16px; border-radius: 20px; letter-spacing: 0.03em;
}
.online-badge.online { color: #FFFFFF; background: #16A34A; }
.online-badge.offline { color: #FFFFFF; background: #DC2626; }
.online-badge .status-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; background: currentColor; }
.online-badge.online .status-dot { animation: pulse-white 2s infinite; }

/* Settings page */
.settings-group { margin-bottom: 22px; }
.settings-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 0; border-bottom: 1px solid rgba(35,43,53,0.6);
}
.settings-row:last-child { border-bottom: none; }
.settings-row-label { font-size: 13px; }
.settings-row-desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.settings-row-value { font-family: var(--mono); font-size: 13px; color: var(--text-muted); }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); font-size: 13px; }
