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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #0f1117;
    color: #e0e0e0;
    min-height: 100vh;
}

/* Top bar */
.topbar {
    background: #1a1d27;
    border-bottom: 1px solid #2a2d3a;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
}
.topbar h1 { font-size: 20px; font-weight: 700; color: #3b82f6; }
.topbar-sub { font-size: 13px; color: #666; flex: 1; }
.topbar .status { display: flex; align-items: center; gap: 8px; font-size: 13px; }

.status-dot {
    width: 10px; height: 10px; border-radius: 50%;
    background: #ef4444; transition: background 0.3s;
}
.status-dot.connected { background: #22c55e; }

/* Panel Section */
.panel-section {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 16px; padding: 16px 24px;
}
.panel-info-card, .sensor-card {
    background: #1a1d27; border: 1px solid #2a2d3a;
    border-radius: 10px; padding: 20px;
}
.panel-header {
    display: flex; justify-content: space-between;
    align-items: flex-start; margin-bottom: 16px;
}
.panel-name { font-size: 18px; font-weight: 700; color: #fff; }
.panel-meta { font-size: 12px; color: #555; margin-top: 4px; }

.panel-mode-big {
    font-size: 20px; font-weight: 800; padding: 8px 20px;
    border-radius: 10px; text-transform: uppercase; letter-spacing: 1px;
    background: #2a2d3a; color: #888;
}
.panel-mode-big.arm { background: rgba(239,68,68,0.15); color: #ef4444; border: 1px solid rgba(239,68,68,0.3); }
.panel-mode-big.home { background: rgba(245,158,11,0.15); color: #f59e0b; border: 1px solid rgba(245,158,11,0.3); }
.panel-mode-big.disarmed { background: rgba(34,197,94,0.15); color: #22c55e; border: 1px solid rgba(34,197,94,0.3); }
.panel-mode-big.sos { background: rgba(220,38,38,0.3); color: #fca5a5; border: 1px solid rgba(220,38,38,0.5); animation: pulse 1s infinite; }

@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:0.6; } }

.panel-stats {
    display: grid; grid-template-columns: repeat(5, 1fr);
    gap: 10px; margin-bottom: 16px;
}
.stat { background: #12141c; border-radius: 8px; padding: 10px; text-align: center; }
.stat-label { font-size: 10px; color: #555; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 14px; font-weight: 700; color: #e0e0e0; margin-top: 2px; }
.stat-value.ok { color: #22c55e; }
.stat-value.warn { color: #f59e0b; }
.stat-value.danger { color: #ef4444; }

.panel-controls { display: flex; gap: 8px; }
.btn-ctrl {
    flex: 1; padding: 10px 8px; border: none; border-radius: 8px;
    font-size: 12px; font-weight: 700; cursor: pointer;
    transition: opacity 0.15s, transform 0.1s; text-transform: uppercase;
}
.btn-ctrl:hover { opacity: 0.85; }
.btn-ctrl:active { transform: scale(0.96); }
.btn-arm { background: #ef4444; color: #fff; }
.btn-home { background: #f59e0b; color: #000; }
.btn-disarm { background: #22c55e; color: #000; }
.btn-sos { background: #7f1d1d; color: #fca5a5; border: 2px solid #ef4444; }

/* Sensors */
.sensors-list { margin-bottom: 12px; }
.sensor-item {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px; border-bottom: 1px solid #1e2130; font-size: 13px;
}
.sensor-icon {
    width: 28px; height: 28px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; flex-shrink: 0;
}
.sensor-icon.entry { background: rgba(59,130,246,0.15); color: #3b82f6; }
.sensor-icon.motion { background: rgba(245,158,11,0.15); color: #f59e0b; }
.sensor-icon.wired { background: rgba(107,114,128,0.15); color: #9ca3af; }
.sensor-icon.remote { background: rgba(168,85,247,0.15); color: #a855f7; }
.sensor-icon.other { background: rgba(34,197,94,0.15); color: #22c55e; }
.sensor-item .sensor-name { flex: 1; }
.sensor-item .sensor-zone { color: #555; font-size: 11px; font-family: monospace; }

.zone-config { margin-top: 10px; }
.zone-config select {
    background: #12141c; color: #e0e0e0; border: 1px solid #2a2d3a;
    border-radius: 4px; padding: 4px 8px; font-size: 12px;
}

.sensor-row, .msg-row {
    display: flex; justify-content: space-between;
    padding: 5px 0; border-bottom: 1px solid #1e2130; font-size: 13px;
}
.sensor-label, .msg-label { color: #666; font-weight: 600; }
.msg-text { font-style: italic; color: #e0e0e0; }
.state-open { color: #ef4444 !important; font-weight: 700; }
.state-closed { color: #22c55e !important; }

/* Filter */
.filter-bar {
    padding: 8px 24px; background: #12141c;
    border-bottom: 1px solid #1e2130; font-size: 13px;
}
.poll-label { display: flex; align-items: center; gap: 6px; cursor: pointer; color: #555; }

/* Main */
.main {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 20px; padding: 16px 24px; max-width: 1600px; margin: 0 auto;
}
.section-title {
    font-size: 13px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.5px; color: #555; margin-bottom: 10px;
}

/* Alarm cards — enriched */
.alarms { display: flex; flex-direction: column; gap: 10px; }

.alarm-card {
    border-radius: 8px; padding: 16px;
    animation: fadeIn 0.25s ease; border-left: 4px solid;
}
.alarm-card.critical { background: rgba(239,68,68,0.08); border-left-color: #ef4444; }
.alarm-card.warn { background: rgba(245,158,11,0.08); border-left-color: #f59e0b; }
.alarm-card.info { background: rgba(107,114,128,0.08); border-left-color: #6b7280; }

.alarm-type { font-size: 16px; font-weight: 700; margin-bottom: 6px; }
.alarm-card.critical .alarm-type { color: #ef4444; }
.alarm-card.warn .alarm-type { color: #f59e0b; }
.alarm-card.info .alarm-type { color: #9ca3af; }

.alarm-location { font-size: 13px; color: #ccc; margin-bottom: 4px; }
.alarm-detail { font-size: 12px; color: #888; line-height: 1.6; margin-bottom: 10px; }
.alarm-detail b { color: #aaa; }
.alarm-actions { display: flex; gap: 8px; }

.btn {
    padding: 6px 14px; border: none; border-radius: 4px;
    font-size: 12px; font-weight: 600; cursor: pointer; transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn-ack { background: #3b82f6; color: #fff; }
.btn-close-ev { background: #4b5563; color: #fff; }
.btn-silence { background: #dc2626; color: #fff; }

/* Event log */
.event-log { overflow-x: auto; }
.event-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.event-table th {
    text-align: left; padding: 8px 8px; background: #1a1d27;
    color: #555; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.3px; position: sticky; top: 0;
}
.event-table td { padding: 6px 8px; border-top: 1px solid #1e2130; }
.event-table tr.new-row { animation: fadeIn 0.2s ease; }

.badge {
    display: inline-block; padding: 2px 8px;
    border-radius: 10px; font-size: 11px; font-weight: 600;
}
.badge.critical { background: rgba(239,68,68,0.2); color: #ef4444; }
.badge.warn { background: rgba(245,158,11,0.2); color: #f59e0b; }
.badge.info { background: rgba(107,114,128,0.2); color: #9ca3af; }
.badge.new { background: rgba(59,130,246,0.2); color: #3b82f6; }
.badge.acked { background: rgba(245,158,11,0.2); color: #f59e0b; }
.badge.closed { background: rgba(107,114,128,0.2); color: #6b7280; }

.empty-state { text-align: center; color: #333; padding: 30px; font-size: 13px; }

/* Login overlay */
.login-overlay {
    position: fixed; inset: 0; z-index: 2000;
    background: radial-gradient(circle at 30% 20%, #1a1d2e 0%, #0a0c14 70%);
    display: flex; align-items: center; justify-content: center;
}
.login-card {
    background: #1a1d27;
    border: 1px solid #2a2d3a;
    border-radius: 14px;
    padding: 32px 28px;
    width: 100%;
    max-width: 340px;
    display: flex; flex-direction: column; gap: 12px;
    box-shadow: 0 18px 60px rgba(0,0,0,0.6);
}
.login-title {
    font-size: 28px; font-weight: 700; color: #3b82f6;
    text-align: center; letter-spacing: -0.5px;
}
.login-sub {
    font-size: 13px; color: #6b7280;
    text-align: center; margin-bottom: 14px;
}
.login-card input {
    background: #0f1117;
    border: 1px solid #2a2d3a;
    color: #e0e0e0;
    padding: 11px 14px;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
}
.login-card input:focus { border-color: #3b82f6; }
.login-card button {
    background: #3b82f6;
    color: #fff;
    border: 0;
    padding: 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 4px;
    transition: background 0.15s;
}
.login-card button:hover { background: #2563eb; }
.login-card button:disabled { background: #6b7280; cursor: not-allowed; }
.login-error {
    color: #ef4444;
    font-size: 12px;
    min-height: 14px;
    text-align: center;
}

/* Top bar user chip + logout */
.user-chip {
    font-size: 12px;
    color: #93c5fd;
    background: #1e3a5f;
    padding: 4px 10px;
    border-radius: 10px;
    margin-left: 8px;
}
.btn-logout {
    background: transparent;
    color: #888;
    border: 1px solid #444;
    padding: 4px 12px;
    font-size: 12px;
    border-radius: 6px;
    cursor: pointer;
    margin-left: 8px;
}
.btn-logout:hover { color: #ef4444; border-color: #ef4444; }

/* Camera viewer modal */
.camera-modal {
    position: fixed; inset: 0; z-index: 1000;
    display: flex; align-items: center; justify-content: center;
}
.camera-modal-backdrop {
    position: absolute; inset: 0;
    background: rgba(0, 0, 0, 0.78);
}
.camera-modal-body {
    position: relative;
    background: #1a1d27;
    border: 1px solid #2a2d3a;
    border-radius: 10px;
    padding: 14px;
    width: 920px; max-width: 92vw; max-height: 92vh;
    display: flex; flex-direction: column; gap: 10px;
}
.camera-modal-header {
    display: flex; justify-content: space-between; align-items: center;
    color: #e0e0e0; font-size: 15px; font-weight: 600;
}
.camera-modal-close {
    background: transparent; border: 0; color: #888;
    font-size: 26px; cursor: pointer; line-height: 1; padding: 0 6px;
}
.camera-modal-close:hover { color: #fff; }
#camera-modal-video {
    width: 100%; max-height: 70vh; background: #000; border-radius: 6px;
}
.camera-modal-status { color: #6b7280; font-size: 12px; min-height: 1em; }
.camera-modal-status.error { color: #ef4444; }

/* Live cameras panel */
.cameras-section { padding: 0 16px 4px; }
.cameras-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 10px;
}
.camera-tile {
    display: flex; align-items: center; gap: 10px;
    background: #1a1d27; border: 1px solid #2a2d3a; border-radius: 8px;
    padding: 10px 12px; cursor: pointer;
    transition: border-color .15s, background .15s;
}
.camera-tile:hover { background: #212531; border-color: #3b82f6; }
.camera-tile.off { opacity: .55; }
.camera-tile-thumb {
    font-size: 22px; width: 40px; height: 40px; flex: 0 0 40px;
    display: flex; align-items: center; justify-content: center;
    background: #11131a; border-radius: 6px;
}
.camera-tile-info { flex: 1; min-width: 0; }
.camera-tile-name {
    color: #e0e0e0; font-size: 13px; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.camera-tile-meta {
    color: #6b7280; font-size: 11px; margin-top: 2px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.camera-tile-play { color: #3b82f6; font-size: 16px; flex: 0 0 auto; }
.btn-camera {
    background: #1e3a5f; color: #93c5fd;
    border: 1px solid #3b82f6;
}
.btn-camera:hover { background: #2a4d7f; color: #fff; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 900px) {
    .main, .panel-section { grid-template-columns: 1fr; }
    .panel-stats { grid-template-columns: repeat(3, 1fr); }
}

/* Quality selector in camera modal */
.camera-modal-bar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 10px; padding: 6px 2px 0;
}
.camera-quality { display: flex; gap: 6px; flex: 0 0 auto; }
.btn-quality {
    background: #1a1d27; border: 1px solid #2a2d3a; color: #9ca3af;
    font-size: 12px; padding: 4px 10px; border-radius: 6px; cursor: pointer;
}
.btn-quality.on { border-color: #3b82f6; color: #3b82f6; font-weight: 600; }
.btn-quality:disabled { opacity: .4; cursor: not-allowed; }
.camera-modal-actions { display: flex; gap: 6px; align-items: center; flex: 0 0 auto; }
