/*
 * EV Guardian Dashboard - Custom Design System
 * Aesthetic: Modern Classic (Serif headings + high-tech monospace readout + crisp borders)
 * Color Palette: White, Obsidian Black, Creamy Blue, Creamy Red, Creamy Green, Creamy Orange
 */

@import url('https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,600;0,700;1,400&family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

/* Color variables for Light & Dark modes */
:root {
    --transition-speed: 0.3s;
    --font-serif: 'Lora', Georgia, serif;
    --font-sans: 'Inter', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Base theme colors: Light Cream Mode by default (Modern Minimalist) */
    --bg-primary: #FAF8F5; /* Warm creamy white background */
    --bg-surface: #ffffff;
    --bg-card: #ffffff;
    --bg-sidebar: #F5F1E9; /* Elegant warm cream sidebar */
    --border-color: #E6DFD4; /* Thin cream-beige borders */
    --text-primary: #1F2226; /* Dark slate charcoal */
    --text-secondary: #5D564C; /* Brown-gray body copy */
    --text-muted: #958B7E; /* Soft gray-beige */
    --shadow-sm: 0 2px 8px rgba(31, 34, 38, 0.04);
    --shadow-md: 0 6px 18px rgba(31, 34, 38, 0.06);
    --shadow-lg: 0 16px 36px rgba(31, 34, 38, 0.1);

    /* Creamy Accent Colors (light theme adjustments) */
    --creamy-blue: #2a6bc8;
    --creamy-blue-bg: #ebf3fc;
    --creamy-blue-border: #bcd3f5;

    --creamy-green: #2d8249;
    --creamy-green-bg: #eefaf1;
    --creamy-green-border: #bfebd0;

    --creamy-orange: #c47321;
    --creamy-orange-bg: #fdf6ee;
    --creamy-orange-border: #fadcb9;

    --creamy-red: #c0392b;
    --creamy-red-bg: #fdf2f0;
    --creamy-red-border: #f9d3cc;
}

[data-theme="dark"] {
    /* Base theme colors: Dark Mode */
    --bg-primary: #07080b;
    --bg-surface: #0e1117;
    --bg-card: #131722;
    --bg-sidebar: #0a0c10;
    --border-color: #1f2535;
    --text-primary: #f2edf5;
    --text-secondary: #9aa5b8;
    --text-muted: #5e6b7e;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.5);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.6);
    --shadow-lg: 0 12px 24px rgba(0,0,0,0.7);

    /* Creamy Accent Colors (dark theme adjustments) */
    --creamy-blue: #4a86e8;
    --creamy-blue-bg: rgba(74, 134, 232, 0.1);
    --creamy-blue-border: rgba(74, 134, 232, 0.3);

    --creamy-green: #3fa363;
    --creamy-green-bg: rgba(63, 163, 99, 0.1);
    --creamy-green-border: rgba(63, 163, 99, 0.3);

    --creamy-orange: #e58f3b;
    --creamy-orange-bg: rgba(229, 143, 59, 0.1);
    --creamy-orange-border: rgba(229, 143, 59, 0.3);

    --creamy-red: #d9534f;
    --creamy-red-bg: rgba(217, 83, 79, 0.1);
    --creamy-red-border: rgba(217, 83, 79, 0.3);
}

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

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color var(--transition-speed), color var(--transition-speed);
    overflow-x: hidden;
}

/* Typography styles */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-serif);
    font-weight: 600;
}

.text-mono {
    font-family: var(--font-mono);
}

/* Structural Components */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Header/Top Navigation */
header.top-nav {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    height: 64px;
    background-color: rgba(var(--bg-surface), 0.7);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    z-index: 50;
    transition: background-color var(--transition-speed), border-color var(--transition-speed);
}

.logo-section h1 {
    font-size: 22px;
    letter-spacing: -0.5px;
}

.logo-accent {
    color: var(--creamy-blue);
    font-family: var(--font-sans);
    font-weight: 700;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: 1px solid transparent;
}

.status-badge.connected {
    background-color: var(--creamy-green-bg);
    color: var(--creamy-green);
    border-color: var(--creamy-green-border);
}

.status-badge.disconnected {
    background-color: var(--creamy-red-bg);
    color: var(--creamy-red);
    border-color: var(--creamy-red-border);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: currentColor;
    box-shadow: 0 0 6px currentColor;
}

.theme-toggle-btn {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.theme-toggle-btn:hover {
    background-color: var(--border-color);
}

.profile-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    overflow: hidden;
    cursor: pointer;
}

.profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Sidebar Navigation */
aside.sidebar {
    position: fixed;
    top: 64px;
    left: 0;
    bottom: 0;
    width: 240px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding-top: 16px;
    z-index: 40;
    transition: background-color var(--transition-speed), border-color var(--transition-speed);
}

.sidebar-menu {
    flex: 1;
    list-style: none;
    padding: 0 12px;
}

.sidebar-menu li {
    margin-bottom: 6px;
}

.sidebar-menu a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.sidebar-menu a:hover {
    background-color: var(--bg-surface);
    color: var(--text-primary);
}

.sidebar-menu li.active a {
    background-color: var(--creamy-blue-bg);
    color: var(--creamy-blue);
    border: 1px solid var(--creamy-blue-border);
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sidebar-footer-link {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 13px;
    text-decoration: none;
    transition: color 0.2s;
}

.sidebar-footer-link:hover {
    color: var(--text-primary);
}

.btn-sidebar {
    width: 100%;
    padding: 10px;
    background-color: var(--creamy-blue);
    color: #ffffff;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

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

/* Main Content Area */
main.main-content {
    margin-left: 240px;
    padding: 88px 24px 24px 24px;
    width: calc(100% - 240px);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* Sections visibility */
.view-section {
    display: none;
}

.view-section.active {
    display: block;
    animation: fadeIn 0.3s ease-in-out;
}

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

/* Common Dashboard Title */
.section-title {
    margin-bottom: 24px;
}

.section-title h2 {
    font-size: 28px;
    margin-bottom: 4px;
    font-weight: 700;
}

.section-title p {
    font-size: 14px;
    color: var(--text-secondary);
}

/* Card layout & top-border styling */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 20px;
    position: relative;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* Dynamic border-top accents */
.border-top-blue { border-top: 4px solid var(--creamy-blue); }
.border-top-green { border-top: 4px solid var(--creamy-green); }
.border-top-orange { border-top: 4px solid var(--creamy-orange); }
.border-top-red { border-top: 4px solid var(--creamy-red); }

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.card-title {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    font-weight: 600;
}

.card-icon {
    font-size: 20px;
    color: var(--text-muted);
}

.card-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    font-family: var(--font-mono);
    margin-bottom: 6px;
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.card-unit {
    font-size: 16px;
    font-weight: 400;
    color: var(--text-secondary);
}

.card-footer {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
}

.sparkline-container {
    width: 100px;
    height: 30px;
    margin-top: 8px;
}

/* System Status Dashboard Card */
.status-hero-card {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 32px;
    overflow: hidden;
}

.status-hero-info {
    max-width: 60%;
}

.status-hero-label {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 8px;
}

.status-hero-value {
    font-size: 40px;
    font-weight: 700;
    margin-bottom: 12px;
}

.status-hero-desc {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.status-visual {
    width: 140px;
    height: 140px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.status-ring {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 8px solid var(--border-color);
    position: absolute;
}

.status-ring-active {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 8px solid transparent;
    border-top-color: var(--accent-active, var(--creamy-green));
    border-right-color: var(--accent-active, var(--creamy-green));
    position: absolute;
    transform: rotate(-45deg);
    transition: border-color 0.5s ease;
}

.status-ring-text {
    font-family: var(--font-mono);
    font-size: 18px;
    font-weight: 700;
    text-transform: uppercase;
}

/* Chart Container & Rows */
.chart-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.chart-card {
    height: 350px;
    display: flex;
    flex-direction: column;
}

.chart-card-body {
    flex: 1;
    position: relative;
    min-height: 0;
}

/* Insights Layout */
.insight-grid {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

/* Quick Alert Panel styling */
.alert-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 236px;
    overflow-y: auto;
}

.alert-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background-color: rgba(var(--bg-surface), 0.5);
    font-size: 13px;
    line-height: 1.4;
}

.alert-item-icon {
    font-size: 16px;
    margin-top: 2px;
}

.alert-item.safe {
    border-left: 4px solid var(--creamy-green);
}
.alert-item.warning {
    border-left: 4px solid var(--creamy-orange);
}
.alert-item.danger {
    border-left: 4px solid var(--creamy-red);
}

.alert-item-title {
    font-weight: 600;
    margin-bottom: 2px;
}

.alert-item-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* System Stats Subgrid */
.stats-subgrid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.substat-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 112px;
}

.substat-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.substat-value {
    font-size: 22px;
    font-weight: 700;
    font-family: var(--font-mono);
}

/* Removed battery cell modules and SVG tracking map layouts */

/* Safety Logs View */
.filter-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    gap: 16px;
    flex-wrap: wrap;
}

.search-input {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 16px;
    color: var(--text-primary);
    font-size: 14px;
    width: 280px;
    outline: none;
    transition: border-color 0.2s;
}

.search-input:focus {
    border-color: var(--creamy-blue);
}

.filter-buttons {
    display: flex;
    gap: 8px;
}

.btn-filter {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-filter:hover {
    color: var(--text-primary);
    background-color: var(--border-color);
}

.btn-filter.active {
    background-color: var(--creamy-blue);
    border-color: var(--creamy-blue);
    color: #ffffff;
}

.btn-export {
    display: flex;
    align-items: center;
    gap: 6px;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-export:hover {
    background-color: var(--border-color);
}

.table-container {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

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

.log-table th, .log-table td {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
}

.log-table th {
    background-color: rgba(var(--border-color), 0.2);
    font-family: var(--font-sans);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 1px;
}

.log-table tbody tr {
    transition: background-color 0.2s;
}

.log-table tbody tr:hover {
    background-color: rgba(255,255,255,0.01);
}

[data-theme="light"] .log-table tbody tr:hover {
    background-color: rgba(0,0,0,0.01);
}

.log-status {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    display: inline-block;
}

.log-status.safe { background-color: var(--creamy-green-bg); color: var(--creamy-green); }
.log-status.warning { background-color: var(--creamy-orange-bg); color: var(--creamy-orange); }
.log-status.danger { background-color: var(--creamy-red-bg); color: var(--creamy-red); }

/* Settings/Setup View */
.settings-grid {
    display: grid;
    grid-template-columns: 1.5fr 1.2fr;
    gap: 24px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-input {
    width: 100%;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    font-family: var(--font-mono);
}

.form-input:focus {
    border-color: var(--creamy-blue);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.range-display {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.btn-primary {
    background-color: var(--creamy-blue);
    color: #ffffff;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

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

.btn-danger-outline {
    background: none;
    border: 1px solid var(--creamy-red);
    color: var(--creamy-red);
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-danger-outline:hover {
    background-color: var(--creamy-red-bg);
}

.settings-description {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 12px;
}

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

.toast {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 16px 20px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: flex-start;
    gap: 14px;
    min-width: 320px;
    max-width: 400px;
    transform: translateY(50px);
    opacity: 0;
    animation: toastIn 0.3s forwards ease-out;
    transition: all 0.2s ease;
}

.toast.removing {
    animation: toastOut 0.3s forwards ease-in;
}

@keyframes toastIn {
    to { transform: translateY(0); opacity: 1; }
}

@keyframes toastOut {
    to { transform: translateY(20px); opacity: 0; }
}

.toast.safe { border-left: 5px solid var(--creamy-green); }
.toast.warning { border-left: 5px solid var(--creamy-orange); }
.toast.danger { border-left: 5px solid var(--creamy-red); }

.toast-icon {
    font-size: 20px;
}

.toast.safe .toast-icon { color: var(--creamy-green); }
.toast.warning .toast-icon { color: var(--creamy-orange); }
.toast.danger .toast-icon { color: var(--creamy-red); }

.toast-content {
    flex: 1;
}

.toast-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
}

.toast-message {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.toast-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
}

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

/* Footer Section */
footer.app-footer {
    border-top: 1px solid var(--border-color);
    margin-top: auto;
    padding-top: 20px;
    padding-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text-muted);
}

.footer-links {
    display: flex;
    gap: 16px;
}

.footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s;
}

.footer-links a:hover {
    color: var(--text-primary);
}

/* Utility classes */
.flex-row-center {
    display: flex;
    align-items: center;
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.mb-16 { margin-bottom: 16px; }
.mt-16 { margin-top: 16px; }

/* Responsive adjustments */
@media (max-width: 1024px) {
    aside.sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    aside.sidebar.mobile-open {
        transform: translateX(0);
    }
    main.main-content {
        margin-left: 0;
        width: 100%;
        padding-left: 16px;
        padding-right: 16px;
    }
    header.top-nav {
        padding: 0 16px;
    }
    .hamburger-btn {
        display: flex !important;
    }
    .insight-grid, .battery-layout, .fleet-layout, .settings-grid {
        grid-template-columns: 1fr;
    }
    .chart-grid {
        grid-template-columns: 1fr;
    }
}

.hamburger-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
}

/* Material Symbols Outlined Font Support Override */
.material-symbols-outlined {
    font-family: 'Material Symbols Outlined';
    font-weight: normal;
    font-style: normal;
    font-size: 24px;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    display: inline-block;
    white-space: nowrap;
    word-wrap: normal;
    direction: ltr;
    -webkit-font-smoothing: antialiased;
}
