/* Design System CSS Variables */
:root {
    --bg-base: #f5f5f7;
    --bg-sidebar: #ffffff;
    --bg-surface: #ffffff;
    --bg-card-hover: #fcfcfd;
    --border-color: #e5e5ea;
    --border-hover: #cbd5e1;
    
    --text-primary: #1d1d1f;
    --text-secondary: #48484a;
    --text-muted: #8e8e93;
    
    --primary: #4f46e5;
    --primary-glow: rgba(79, 70, 229, 0.12);
    --primary-hover: #4338ca;
    
    --success: #16a34a;
    --success-glow: rgba(22, 163, 74, 0.12);
    --warning: #ea580c;
    --warning-glow: rgba(234, 88, 12, 0.12);
    --danger: #dc2626;
    --danger-glow: rgba(220, 38, 38, 0.12);
    --info: #0284c7;
    --info-glow: rgba(2, 132, 199, 0.12);

    --font-heading: 'Outfit', 'Inter', sans-serif;
    --font-body: 'Inter', sans-serif;
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Theme (Pure Grays / Neutral) */
[data-theme="dark"] {
    --bg-base: #121212;
    --bg-sidebar: #1c1c1e;
    --bg-surface: #1c1c1e;
    --bg-card-hover: #262629;
    --border-color: #2c2c2e;
    --border-hover: #3a3a3c;
    
    --text-primary: #f5f5f7;
    --text-secondary: #aeaeb2;
    --text-muted: #636366;
    
    --primary: #818cf8;
    --primary-glow: rgba(129, 140, 248, 0.15);
    --primary-hover: #6366f1;
    
    --success: #4ade80;
    --success-glow: rgba(74, 222, 128, 0.15);
    --warning: #fb923c;
    --warning-glow: rgba(251, 146, 60, 0.15);
    --danger: #f87171;
    --danger-glow: rgba(248, 113, 113, 0.15);
    --info: #38bdf8;
    --info-glow: rgba(56, 189, 248, 0.15);
}

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

body {
    background-color: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    height: 100vh;
    overflow: hidden;
}

/* App Container Layout */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header Bar */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 28px;
    background-color: var(--bg-sidebar);
    border-bottom: 1px solid var(--border-color);
    height: 70px;
    z-index: 10;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 28px;
    color: var(--primary);
    filter: drop-shadow(0 2px 4px var(--primary-glow));
}

.logo-text h1 {
    font-family: var(--font-heading);
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.logo-text p {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
    margin-top: -2px;
}

.header-status {
    display: flex;
    align-items: center;
    gap: 20px;
}

.live-sync-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-base);
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
}

.sync-dot {
    width: 6px;
    height: 6px;
    background-color: var(--success);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--success);
}

.blinking {
    animation: pulse-dot 2s infinite;
}

.sync-text {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
}

.badge-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.state-online {
    background-color: var(--success-glow);
    color: var(--success);
    border: 1px solid rgba(22, 163, 74, 0.2);
}
.state-online .badge-dot {
    background-color: var(--success);
    box-shadow: 0 0 6px var(--success);
}

.state-battery {
    background-color: var(--warning-glow);
    color: var(--warning);
    border: 1px solid rgba(234, 88, 12, 0.2);
    animation: alert-flash 1.5s infinite;
}
.state-battery .badge-dot {
    background-color: var(--warning);
    box-shadow: 0 0 6px var(--warning);
}

.state-offline {
    background-color: var(--danger-glow);
    color: var(--danger);
    border: 1px solid rgba(220, 38, 38, 0.2);
}
.state-offline .badge-dot {
    background-color: var(--danger);
    box-shadow: 0 0 6px var(--danger);
}

/* Workspace Layout */
.main-layout {
    display: flex;
    flex: 1;
    height: calc(100vh - 70px);
    overflow: hidden;
}

/* Sidebar Navigation */
.sidebar {
    width: 250px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 24px 16px;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 12px 16px;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-family: var(--font-body);
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    text-align: left;
    transition: var(--transition);
}

.nav-btn:hover {
    background-color: var(--bg-surface);
    color: var(--text-primary);
}

.nav-btn.active {
    background-color: var(--primary);
    color: #ffffff;
    box-shadow: 0 4px 14px var(--primary-glow);
}

.nav-btn .btn-icon {
    font-size: 18px;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border-color);
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.6;
}

/* Main Content Area */
.content-container {
    flex: 1;
    padding: 30px;
    overflow-y: auto;
    background-color: var(--bg-base);
}

.tab-pane {
    display: none;
    animation: fade-in 0.3s ease-out;
}

.tab-pane.active {
    display: block;
}

.section-title {
    margin: 28px 0 16px 0;
}

.section-title h2 {
    font-family: var(--font-heading);
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.3px;
    color: var(--text-primary);
}

/* Metric Cards (Realtime Section) */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    margin-bottom: 24px;
}

.metric-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
    min-height: 190px;
}

.metric-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
}

.metric-card h3 {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 12px;
}

/* Grid Status Card */
.card-status-body {
    display: flex;
    align-items: center;
    gap: 20px;
    flex: 1;
}

.status-icon {
    font-size: 48px;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.3));
}

.status-title {
    font-family: var(--font-heading);
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
}

.status-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.outage-timer-box {
    margin-top: 14px;
    padding: 10px 16px;
    background-color: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: var(--radius-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.timer-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--danger);
    text-transform: uppercase;
}

.timer-value {
    font-family: var(--font-heading);
    font-size: 20px;
    font-weight: 700;
    color: var(--danger);
    font-variant-numeric: tabular-nums;
}

/* Battery Ring Gauge */
.card-battery {
    align-items: center;
}

.battery-gauge-container {
    position: relative;
    width: 100px;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.battery-ring {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.ring-bg {
    fill: none;
    stroke: var(--bg-base);
    stroke-width: 8;
}

.ring-fill {
    fill: none;
    stroke: var(--success);
    stroke-width: 8;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.6s ease-out, stroke 0.3s;
}

.battery-val-box {
    position: absolute;
    display: flex;
    align-items: baseline;
}

.battery-pct {
    font-family: var(--font-heading);
    font-size: 28px;
    font-weight: 700;
}

.battery-unit {
    font-size: 14px;
    color: var(--text-secondary);
    margin-left: 2px;
}

.battery-status-text {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 10px;
    font-weight: 500;
}

/* Autonomy Card */
.autonomy-value-container {
    display: flex;
    align-items: baseline;
    margin: 10px 0;
}

.autonomy-val {
    font-family: var(--font-heading);
    font-size: 48px;
    font-weight: 800;
    color: var(--info);
    line-height: 1;
}

.autonomy-unit {
    font-size: 18px;
    color: var(--text-secondary);
    font-weight: 600;
    margin-left: 6px;
}

.autonomy-status-bar {
    width: 100%;
    height: 6px;
    background-color: var(--bg-base);
    border-radius: 3px;
    margin: 14px 0 8px 0;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    background-color: var(--info);
    border-radius: 3px;
    transition: width 0.6s ease-out;
}

.autonomy-desc {
    font-size: 11px;
    color: var(--text-muted);
}

/* Statistics Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 28px;
}

.stat-mini-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.mini-icon {
    font-size: 24px;
    padding: 8px;
    background-color: var(--bg-base);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.mini-value {
    font-family: var(--font-heading);
    font-size: 18px;
    font-weight: 700;
}

.mini-label {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
    font-weight: 500;
}

/* Charts Section */
.charts-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
}

.chart-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
}

.chart-card h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.chart-wrapper {
    position: relative;
    height: 260px;
    width: 100%;
}

/* Heatmap Custom Styling */
.heatmap-container {
    height: 260px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.heatmap-svg {
    width: 100%;
    height: 100%;
}

.heatmap-cell {
    transition: stroke 0.1s;
    cursor: pointer;
}

.heatmap-cell:hover {
    stroke: var(--text-primary);
    stroke-width: 1.5;
}

.heatmap-legend {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    font-size: 10px;
    color: var(--text-muted);
}

.legend-box {
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

/* Logs and History Section */
.history-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    gap: 16px;
}

.search-box {
    flex: 1;
    max-width: 400px;
}

.search-box input {
    width: 100%;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 14px;
    transition: var(--transition);
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.action-btn {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 20px;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 8px;
}

.action-btn:hover {
    background-color: var(--bg-card-hover);
    border-color: var(--border-hover);
}

.logs-layout {
    display: grid;
    grid-template-columns: 2.2fr 1.2fr;
    gap: 24px;
    align-items: start;
}

.log-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.log-card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.log-card-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

/* Tables styling */
.table-container {
    max-height: 600px;
    overflow-y: auto;
}

.log-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 13.5px;
}

.log-table th {
    background-color: var(--bg-base);
    padding: 14px 20px;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1;
}

.log-table td {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.log-table tr:hover td {
    background-color: var(--bg-card-hover);
}

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

/* Table statuses badges */
.table-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
}

.tb-active {
    background-color: var(--danger-glow);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.tb-completed {
    background-color: var(--success-glow);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

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

/* System Events journal wrapper */
.events-log-wrapper {
    padding: 12px;
    max-height: 600px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background-color: var(--bg-base);
    border-radius: var(--radius-md);
}

.event-log-item {
    padding: 12px 14px;
    border-radius: var(--radius-md);
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: var(--transition);
}

.event-log-item:hover {
    border-color: var(--border-hover);
}

.event-item-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
}

.event-item-time {
    color: var(--text-muted);
    font-weight: 500;
}

.event-item-type {
    font-weight: 700;
    text-transform: uppercase;
    font-size: 9px;
    padding: 2px 6px;
    border-radius: 4px;
}

.type-status_change {
    background-color: rgba(99, 102, 241, 0.15);
    color: var(--primary);
}

.type-comm_loss {
    background-color: var(--danger-glow);
    color: var(--danger);
}

.type-comm_restore {
    background-color: var(--success-glow);
    color: var(--success);
}

.type-system {
    background-color: rgba(94, 234, 212, 0.15);
    color: #14b8a6;
}

.event-item-desc {
    font-size: 12.5px;
    color: var(--text-primary);
    font-weight: 500;
}

/* Configuration & Settings Section */
.settings-layout {
    display: grid;
    grid-template-columns: 2.2fr 1.2fr;
    gap: 24px;
    align-items: start;
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.settings-section-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
}

.section-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.section-card-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

/* Form Styles */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group.span-2 {
    grid-column: span 2;
}

.form-group.span-3 {
    grid-column: span 2;
}

.form-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

.form-group input {
    background-color: var(--bg-base);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 13.5px;
    transition: var(--transition);
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.settings-action-row {
    margin-top: 14px;
    display: flex;
    justify-content: flex-end;
}

.form-secondary-btn {
    background-color: var(--bg-base);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-size: 12.5px;
    font-weight: 500;
    font-family: var(--font-body);
    cursor: pointer;
    transition: var(--transition);
}

.form-secondary-btn:hover {
    color: var(--text-primary);
    border-color: var(--border-hover);
    background-color: var(--bg-sidebar);
}

.form-submit-row {
    display: flex;
    justify-content: flex-end;
}

.primary-submit-btn {
    background-color: var(--primary);
    color: #ffffff;
    border: none;
    padding: 14px 28px;
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    box-shadow: 0 4px 14px var(--primary-glow);
    transition: var(--transition);
}

.primary-submit-btn:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

/* Switch styling */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-base);
    border: 1px solid var(--border-color);
    transition: .3s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: var(--text-muted);
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary-glow);
    border-color: var(--primary);
}

input:checked + .slider:before {
    transform: translateX(20px);
    background-color: var(--primary);
}

/* Diagnostics & Simulator Card */
.diagnostics-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
}

.simulator-desc {
    font-size: 12.5px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 20px;
}

.simulator-buttons-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.sim-btn {
    width: 100%;
    padding: 12px;
    border-radius: var(--radius-md);
    border: none;
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 12.5px;
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
}

.sim-btn-danger {
    background-color: var(--danger-glow);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}
.sim-btn-danger:hover {
    background-color: rgba(239, 68, 68, 0.25);
}

.sim-btn-success {
    background-color: var(--success-glow);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.2);
}
.sim-btn-success:hover {
    background-color: rgba(16, 185, 129, 0.25);
}

.sim-btn-warning {
    background-color: var(--warning-glow);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.2);
}
.sim-btn-warning:hover {
    background-color: rgba(245, 158, 11, 0.25);
}

.sim-btn-info {
    background-color: var(--info-glow);
    color: var(--info);
    border: 1px solid rgba(6, 182, 212, 0.2);
}
.sim-btn-info:hover {
    background-color: rgba(6, 182, 212, 0.25);
}

.diagnostics-status {
    border-top: 1px solid var(--border-color);
    padding-top: 16px;
    margin-top: 16px;
}

.diagnostics-status h4 {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.diagnostics-status ul {
    list-style: none;
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.diagnostics-status strong {
    color: var(--text-secondary);
}

/* Toast/Toaster Notifications */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
}

.toast {
    background-color: var(--bg-surface);
    border-left: 4px solid var(--primary);
    border-top: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 16px 20px;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    box-shadow: 0 10px 25px rgba(0,0,0,0.4);
    font-size: 13.5px;
    font-weight: 500;
    min-width: 300px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    animation: slide-in-toast 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.toast-success {
    border-left-color: var(--success);
}

.toast-error {
    border-left-color: var(--danger);
}

.toast-warning {
    border-left-color: var(--warning);
}

.toast-close {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 16px;
    font-weight: 700;
    margin-left: 12px;
    transition: var(--transition);
}

.toast-close:hover {
    color: var(--text-primary);
}

/* Keyframes animations */
@keyframes pulse-dot {
    0% { transform: scale(0.9); opacity: 0.6; }
    50% { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(0.9); opacity: 0.6; }
}

@keyframes alert-flash {
    0% { background-color: var(--warning-glow); border-color: rgba(245, 158, 11, 0.3); }
    50% { background-color: rgba(245, 158, 11, 0.25); border-color: rgba(245, 158, 11, 0.6); }
    100% { background-color: var(--warning-glow); border-color: rgba(245, 158, 11, 0.3); }
}

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

@keyframes slide-in-toast {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ==========================================
   Responsive & Mobile Optimization
   ========================================== */

@media (max-width: 992px) {
    .metrics-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 18px;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }
}

@media (max-width: 768px) {
    /* Global layout adjustments to allow scrolling */
    body {
        overflow: auto;
        height: auto;
    }
    
    .app-container {
        height: auto;
        min-height: 100vh;
    }
    
    .main-layout {
        flex-direction: column;
        height: auto;
        overflow: visible;
    }
    
    .content-container {
        padding: 20px 16px 95px 16px; /* Added large bottom padding to clear the fixed bottom nav bar */
        overflow-y: visible;
    }

    /* App Header Adjustments */
    .app-header {
        padding: 12px 16px;
        height: auto;
        min-height: 60px;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: 8px;
    }
    
    .logo-area {
        gap: 8px;
    }
    
    .logo-icon {
        font-size: 22px;
    }
    
    .logo-text h1 {
        font-size: 16px;
    }
    
    .logo-text p {
        display: none; /* Hide subtitle to save space */
    }
    
    .header-status {
        gap: 8px;
    }
    
    .live-sync-indicator {
        padding: 4px 8px;
        border-radius: 12px;
    }
    
    .sync-text {
        font-size: 9px;
    }
    
    .status-badge {
        padding: 4px 10px;
        font-size: 11px;
    }

    /* Sidebar Navigation converted to bottom bar */
    .sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 65px;
        flex-direction: row;
        padding: 8px 12px;
        border-top: 1px solid var(--border-color);
        border-right: none;
        z-index: 100;
        background-color: var(--bg-sidebar);
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
    }
    
    .nav-menu {
        flex-direction: row;
        width: 100%;
        justify-content: space-around;
        gap: 8px;
    }
    
    .nav-btn {
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        padding: 6px 4px;
        font-size: 10px;
        text-align: center;
        flex: 1;
        border-radius: var(--radius-md);
        height: auto;
    }
    
    .nav-btn:hover {
        background-color: var(--bg-base);
    }
    
    .nav-btn.active {
        box-shadow: none; /* Avoid shadow bleed-out on small buttons */
    }
    
    .nav-btn .btn-icon {
        font-size: 18px;
    }
    
    .nav-btn .btn-label {
        font-size: 9.5px;
        font-weight: 600;
    }
    
    .sidebar-footer {
        display: none; /* Hide version details from bottom menu */
    }

    /* Tab content specific overrides */
    .section-title {
        margin: 16px 0 12px 0;
    }
    
    .metrics-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .metric-card {
        min-height: auto;
        padding: 20px;
    }
    
    .card-battery {
        align-items: flex-start;
    }
    
    .card-battery h3 {
        align-self: flex-start;
    }
    
    .battery-gauge-container {
        align-self: center;
        margin: 10px 0;
    }
    
    .battery-status-text {
        align-self: center;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    .stat-mini-card {
        padding: 12px;
        gap: 10px;
    }
    
    .mini-icon {
        font-size: 20px;
        padding: 6px;
    }
    
    .mini-value {
        font-size: 16px;
    }
    
    .charts-row {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .chart-card {
        padding: 16px;
    }
    
    .chart-wrapper {
        height: 220px;
    }
    
    .heatmap-container {
        height: auto;
        min-height: 180px;
    }
    
    /* Logs and history responsive table */
    .history-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    
    .search-box {
        max-width: none;
    }
    
    .action-btn {
        width: 100%;
        justify-content: center;
    }
    
    .logs-layout {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .table-container {
        max-height: 450px;
        overflow-x: auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    }
    
    .log-table th, .log-table td {
        padding: 10px 14px;
        font-size: 12px;
        white-space: nowrap; /* Prevent ugly column text wrapping */
    }
    
    .events-log-wrapper {
        max-height: 400px;
    }

    /* Configuration and Diagnostics */
    .settings-layout {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .settings-section-card, .diagnostics-card {
        padding: 16px;
    }
    
    .form-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .form-group.span-2, .form-group.span-3 {
        grid-column: auto;
    }
    
    .settings-action-row, .form-submit-row {
        justify-content: stretch;
        margin-top: 10px;
    }
    
    .form-secondary-btn, .primary-submit-btn {
        width: 100%;
        text-align: center;
        justify-content: center;
        padding: 12px 20px;
    }

    /* Notification Toasts */
    .toast-container {
        bottom: 80px; /* Stand clear of the bottom navigation bar */
        left: 16px;
        right: 16px;
    }
    
    .toast {
        min-width: auto;
        width: 100%;
    }
}

@media (max-width: 480px) {
    .app-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .header-status {
        width: 100%;
        justify-content: space-between;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .content-container {
        padding: 16px 12px 90px 12px;
    }
    
    .heatmap-legend {
        justify-content: center;
        margin-top: 14px;
    }
}

/* Modale de modification d'une coupure */
.custom-dialog {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    background-color: var(--bg-surface);
    color: var(--text-primary);
    max-width: 500px;
    width: 90%;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1100;
}

.custom-dialog::backdrop {
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    animation: fade-in-backdrop 0.2s ease-out;
}

.dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.dialog-header h3 {
    font-family: var(--font-heading);
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.dialog-close-btn {
    background: transparent;
    border: none;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
}

.dialog-close-btn:hover {
    color: var(--text-primary);
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

/* Boutons d'actions pour chaque ligne de l'historique */
.row-actions {
    display: flex;
    gap: 8px;
}

.action-icon-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 6px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.action-icon-btn:hover {
    background-color: var(--bg-base);
    border-color: var(--border-hover);
}

.btn-edit:hover {
    color: var(--primary);
    border-color: var(--primary);
}

.btn-delete:hover {
    color: var(--danger);
    border-color: var(--danger);
    background-color: var(--danger-glow);
}

/* Select styling */
.form-select {
    background-color: var(--bg-base);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 13.5px;
    transition: var(--transition);
    appearance: none;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2348484a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 16px;
    padding-right: 40px;
    width: 100%;
}

.form-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

@keyframes fade-in-backdrop {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Authentication Screen Overlay */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(15, 23, 42, 0.85); /* Smooth dark overlay */
    z-index: 9999; /* Higher than everything else */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fade-in-backdrop 0.3s ease-out;
}

.login-card-container {
    background-color: var(--bg-sidebar);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    animation: fade-in 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.login-logo {
    text-align: center;
    margin-bottom: 30px;
}

.login-logo-icon {
    font-size: 44px;
    display: block;
    margin-bottom: 12px;
    color: var(--primary);
    filter: drop-shadow(0 2px 8px var(--primary-glow));
}

.login-logo h2 {
    font-family: var(--font-heading);
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.login-logo p {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
    font-weight: 500;
}

.login-form-box {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
}

.login-instruction {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
    text-align: center;
    margin-bottom: 8px;
}

.login-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.login-group label {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-secondary);
}

.login-group input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: 14px;
    transition: var(--transition);
    background-color: var(--bg-base);
    color: var(--text-primary);
}

.login-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.login-submit-btn {
    width: 100%;
    padding: 14px 20px;
    background-color: var(--primary);
    color: #ffffff;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 12px var(--primary-glow);
    margin-top: 8px;
}

.login-submit-btn:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

.login-submit-btn:active {
    transform: translateY(0);
}

.login-error-message {
    background-color: var(--danger-glow);
    color: var(--danger);
    border: 1px solid rgba(220, 38, 38, 0.2);
    border-radius: var(--radius-md);
    padding: 12px;
    font-size: 13px;
    font-weight: 500;
    text-align: center;
    animation: shake 0.3s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

/* Sidebar Logout Button specific styles */
.btn-logout-sidebar:hover {
    background-color: var(--danger-glow) !important;
    color: var(--danger) !important;
}

/* ==========================================
   Sober Redesign & SVG Icon Styling
   ========================================== */

/* SVG generic configuration */
.logo-svg,
.nav-svg,
.stat-mini-svg,
.section-title-svg,
.btn-action-svg,
.login-logo-svg,
.table-action-svg,
.toast-svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    display: inline-block;
    vertical-align: middle;
}

/* Specific SVG scale adjustments */
.logo-svg {
    width: 24px;
    height: 24px;
    color: var(--primary);
}

.nav-svg {
    width: 18px;
    height: 18px;
}

.stat-mini-svg {
    width: 24px;
    height: 24px;
    color: var(--text-secondary);
}

.svg-warning-icon {
    color: var(--warning);
}

.section-title-svg {
    width: 22px;
    height: 22px;
    color: var(--primary);
}

.login-logo-svg {
    width: 48px;
    height: 48px;
    color: var(--primary);
}

.table-action-svg {
    width: 16px;
    height: 16px;
}

.toast-svg {
    width: 18px;
    height: 18px;
}

/* Flex aligned title with icon */
.header-with-icon {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Theme Toggle Button Styles */
.theme-toggle-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: var(--transition);
    padding: 0;
    margin-right: 12px;
}

.theme-toggle-btn:hover {
    background-color: var(--bg-card-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
    transform: scale(1.05);
}

.theme-toggle-btn:active {
    transform: scale(0.95);
}

.theme-icon {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

/* Visibility based on theme */
.theme-toggle-btn .sun-icon {
    display: none;
}
.theme-toggle-btn .moon-icon {
    display: block;
}

[data-theme="dark"] .theme-toggle-btn .sun-icon {
    display: block;
    color: #f59e0b; /* Amber warning color for the sun in dark mode is a premium accent! */
}
[data-theme="dark"] .theme-toggle-btn .moon-icon {
    display: none;
}

/* Additional dark mode specific overrides to improve legibility and contrast */
[data-theme="dark"] .metric-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] .sidebar {
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
}

[data-theme="dark"] .app-header {
    background-color: var(--bg-sidebar);
    border-bottom: 1px solid var(--border-color);
}

[data-theme="dark"] input, 
[data-theme="dark"] select, 
[data-theme="dark"] textarea {
    background-color: #121212 !important;
    color: #ffffff !important;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] input:focus, 
[data-theme="dark"] select:focus {
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 3px var(--primary-glow) !important;
}

[data-theme="dark"] .log-card, 
[data-theme="dark"] .diagnostics-card,
[data-theme="dark"] .custom-dialog {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
}

[data-theme="dark"] .log-table th {
    background-color: #121212;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
}

[data-theme="dark"] .log-table td {
    border-bottom: 1px solid var(--border-color);
}

[data-theme="dark"] .log-table tr:hover {
    background-color: var(--bg-card-hover);
}

[data-theme="dark"] .empty-state {
    color: var(--text-muted);
}

[data-theme="dark"] .form-secondary-btn {
    background-color: #1c1c1e;
    border-color: var(--border-color);
    color: var(--text-primary);
}

[data-theme="dark"] .form-secondary-btn:hover {
    background-color: var(--bg-card-hover);
    border-color: var(--border-hover);
}


