
:root {
    /* Color Palette */
    --bg-base: #0f172a;        /* Deep slate background */
    --bg-surface: #1e293b;     /* Card background */
    --bg-input: #0b1120;       /* Darker input background */
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    --border-color: #334155;
    --border-hover: #475569;
    
    --accent-red: #ef4444;
    --accent-red-hover: #dc2626;
    --accent-red-glow: rgba(239, 68, 68, 0.25);
    
    --accent-green: #10b981;
    --accent-yellow: #f59e0b;
    --accent-blue: #3b82f6;

    /* Shadows & Radii */
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
    
    --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-glow: 0 0 15px var(--accent-red-glow);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background-color: var(--bg-base);
    color: var(--text-main);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Utilities */
.text-main { color: var(--text-main); }
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent-red); }
.text-sm { font-size: 0.875rem; }
.text-center { text-align: center; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.flex-1 { flex: 1; }
.w-100 { width: 100%; }
.h-100 { height: 100%; }
.max-w-md { max-width: 500px; margin-inline: auto; }
.justify-center { justify-content: center; }

h1, h2, h3, h4 {
    font-weight: 600;
    letter-spacing: -0.025em;
    color: #ffffff;
}

/* Cards & Layout */
.card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 24px;
    box-shadow: var(--shadow-card);
}

.center-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 40px);
}

/* Typography elements */
.brand-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    border-radius: 20px;
    background: linear-gradient(135deg, rgba(239,68,68,0.2) 0%, rgba(239,68,68,0) 100%);
    color: var(--accent-red);
    margin-bottom: 20px;
    border: 1px solid rgba(239,68,68,0.3);
    box-shadow: var(--shadow-glow);
}

.brand-icon-small {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: rgba(239,68,68,0.15);
    color: var(--accent-red);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    font-family: inherit;
}

.btn-primary {
    background-color: var(--accent-red);
    color: #ffffff;
    box-shadow: 0 2px 4px rgba(239, 68, 68, 0.3);
}

.btn-primary:hover {
    background-color: var(--accent-red-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(239, 68, 68, 0.4);
}

.btn-outline {
    background-color: transparent;
    border-color: var(--border-color);
    color: var(--text-main);
}

.btn-outline:hover {
    border-color: var(--border-hover);
    background-color: rgba(255, 255, 255, 0.05);
}

.btn-danger {
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--accent-red);
    border-color: rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    background-color: var(--accent-red);
    color: #ffffff;
}

.btn-safe {
    background-color: rgba(148, 163, 184, 0.1);
    color: var(--text-muted);
    border-color: var(--border-color);
}

.btn-safe:hover {
    background-color: rgba(148, 163, 184, 0.2);
    color: var(--text-main);
}

.btn-block { width: 100%; }
.btn-lg { padding: 12px 24px; font-size: 1.05rem; }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.btn-xs { padding: 4px 8px; font-size: 0.75rem; }

/* Forms */
.security-form .form-group {
    margin-bottom: 16px;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="time"],
select {
    width: 100%;
    padding: 10px 14px;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: inherit;
    transition: all 0.2s ease;
}

input::placeholder { color: #475569; }

input:focus, select:focus {
    outline: none;
    border-color: var(--accent-red);
    box-shadow: 0 0 0 3px var(--accent-red-glow);
}

.inline-form {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}
.inline-form input {
    flex: 1;
    min-width: 180px;
}

/* Authentication Pages */
.intro-section {
    max-width: 500px;
    text-align: center;
    padding: 40px;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    padding: 32px;
}

.auth-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.auth-header h1 {
    margin: 0;
    font-size: 1.5rem;
}

.form-footer {
    text-align: center;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.link-subtle {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.link-subtle:hover {
    color: var(--text-main);
}

/* Error Page */
.error-icon { margin-bottom: 16px; }
.error-code {
    font-size: 5rem;
    font-weight: 700;
    color: var(--accent-red);
    line-height: 1;
    margin-bottom: 8px;
    text-shadow: var(--shadow-glow);
}

/* Dashboard Layout */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 24px;
    box-shadow: var(--shadow-card);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand h2 { margin: 0; font-size: 1.25rem; }

.user-controls {
    display: flex;
    align-items: center;
    gap: 16px;
}

.dashboard-grid {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

@media (min-width: 992px) {
    .dashboard-grid {
        flex-direction: row;
        align-items: flex-start;
    }
    .dashboard-main-col { flex: 1; min-width: 0; }
    .dashboard-side-col { width: 350px; flex-shrink: 0; }
}

/* Sections & Devices */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.section-header h3 { margin: 0; font-size: 1.1rem; }

.badge {
    background-color: rgba(255,255,255,0.05);
    border: 1px solid var(--border-color);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
}
.badge-subtle {
    border-color: rgba(239, 68, 68, 0.3);
    color: var(--accent-red);
}

.device-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

@media (min-width: 768px) {
    .device-grid { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
}

.device-card {
    padding: 20px;
    background: linear-gradient(180deg, var(--bg-surface) 0%, rgba(30, 41, 59, 0.6) 100%);
}

.device-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.device-title-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}
.device-title-wrapper h4 { margin: 0; font-size: 1.1rem; }

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.status-dot.online { background-color: var(--accent-green); box-shadow: 0 0 8px rgba(16,185,129,0.5); }
.status-dot.offline { background-color: var(--text-muted); }

.status-badge {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 4px;
}
.status-badge.online {
    background-color: rgba(16,185,129,0.1);
    color: var(--accent-green);
    border: 1px solid rgba(16,185,129,0.2);
}
.status-badge.offline {
    background-color: rgba(148,163,184,0.1);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

/* Device Controls (Inner Forms) */
.device-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.control-form {
    background-color: rgba(0,0,0,0.15);
    border: 1px solid var(--border-color);
    padding: 12px;
    border-radius: var(--radius-sm);
}

.control-form label {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 8px;
    letter-spacing: 0.05em;
}

.input-group {
    display: flex;
    gap: 8px;
    align-items: center;
}

.time-group input[type="time"] { padding: 8px; }

.alarm-actions {
    display: flex;
    gap: 10px;
    padding: 0;
    background: transparent;
    border: none;
    margin-top: 4px;
}

/* Alerts Panel */
.alerts-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 600px;
    overflow-y: auto;
    padding-right: 4px;
}

.alerts-container::-webkit-scrollbar { width: 6px; }
.alerts-container::-webkit-scrollbar-track { background: transparent; }
.alerts-container::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }

.alert-item {
    display: flex;
    gap: 12px;
    padding: 16px;
    background-color: var(--bg-input);
    border-radius: var(--radius-sm);
    border-left: 3px solid transparent;
}

.alert-item.type-motion { 
    border-left-color: var(--accent-red);
    background: linear-gradient(90deg, rgba(239,68,68,0.05) 0%, var(--bg-input) 100%);
}
.alert-item.type-motion .alert-icon { color: var(--accent-red); }

.alert-item.type-light { 
    border-left-color: var(--accent-yellow);
    background: linear-gradient(90deg, rgba(245,158,11,0.05) 0%, var(--bg-input) 100%);
}
.alert-item.type-light .alert-icon { color: var(--accent-yellow); }

.alert-item.type-manual { 
    border-left-color: var(--accent-blue);
}
.alert-item.type-manual .alert-icon { color: var(--accent-blue); }

.alert-icon { flex-shrink: 0; margin-top: 2px; }

.alert-content { flex: 1; min-width: 0; }

.alert-content .timestamp {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.alert-content .message {
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 8px;
    word-wrap: break-word;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

/* Mobile Adjustments */
@media (max-width: 600px) {
    .user-controls .greeting { display: none; }
    .inline-form { flex-direction: column; }
    .alarm-actions { flex-direction: column; }
}
