/* ========================================================
   My Dacia – Modern Minimalist Dashboard Styles
   ======================================================== */

/* -- CSS Variables -- */
:root {
    --color-bg: #f5f7fa;
    --color-surface: #ffffff;
    --color-primary: #1a73e8;
    --color-primary-hover: #1557b0;
    --color-danger: #dc3545;
    --color-danger-hover: #bb2d3b;
    --color-success: #28a745;
    --color-warning: #ffc107;
    --color-text: #1f2937;
    --color-text-muted: #6b7280;
    --color-border: #e5e7eb;
    --color-nav: #1e293b;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
    --radius: 8px;
    --radius-lg: 12px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --transition: 0.2s ease;
}

/* -- Reset & Base -- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
}

/* -- Navbar -- */
.navbar {
    background: var(--color-nav);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: var(--shadow-md);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: #fff;
    text-decoration: none;
}

.nav-icon {
    width: 24px;
    height: 24px;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.nav-link {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    transition: background var(--transition), color var(--transition);
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.nav-form {
    display: inline;
}

.nav-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-family: var(--font);
}

/* -- Container -- */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* -- Auth Pages -- */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 56px);
    padding: 1rem;
}

.auth-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-icon {
    width: 48px;
    height: 48px;
    color: var(--color-primary);
    margin-bottom: 0.75rem;
}

.auth-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.auth-subtitle {
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

/* -- Forms -- */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.375rem;
    color: var(--color-text);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.9375rem;
    font-family: var(--font);
    transition: border-color var(--transition), box-shadow var(--transition);
    background: var(--color-surface);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.15);
}

.form-row {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.form-row .form-group {
    flex: 1;
    min-width: 140px;
}

.form-group-btn {
    flex: 0 0 auto !important;
    min-width: auto !important;
}

/* -- Buttons -- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9375rem;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: background var(--transition), transform var(--transition);
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
}

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

.btn-danger {
    background: var(--color-danger);
    color: #fff;
}

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

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-full {
    width: 100%;
    justify-content: center;
}

/* -- Alerts -- */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.alert-error {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.alert-success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

/* -- Password Policy -- */
.password-policy {
    background: var(--color-bg);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 1.5rem;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

.password-policy ul {
    margin-left: 1.25rem;
    margin-top: 0.25rem;
}

/* -- Dashboard -- */
.dashboard {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.map-container {
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--color-border);
}

#map {
    width: 100%;
    height: 400px;
}

.dashboard-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.controls-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#historyDate {
    min-width: 170px;
    height: 40px;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    background: var(--color-surface);
    color: var(--color-text);
}

#historyDate:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.15);
}

.controls-left h2 {
    font-size: 1.25rem;
    font-weight: 700;
}

.text-muted {
    color: var(--color-text-muted);
    font-size: 0.8125rem;
}

/* -- Cards -- */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border);
    transition: box-shadow var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-unavailable {
    opacity: 0.75;
    border-style: dashed;
}

.card-unavailable .card-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--color-text-muted);
}

.card-wide {
    grid-column: span 2;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--color-text-muted);
    font-size: 0.8125rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.75rem;
}

.card-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--color-text);
    line-height: 1.2;
}

.card-unit {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    margin-top: 0.125rem;
}

.card-detail {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    margin-top: 0.375rem;
}

/* -- Tyre Grid -- */
.tyre-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.tyre-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    background: var(--color-bg);
    border-radius: var(--radius);
}

.tyre-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text-muted);
}

.tyre-value {
    font-size: 1rem;
    font-weight: 700;
}

/* -- Badges -- */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-admin {
    background: #dbeafe;
    color: #1e40af;
}

.badge-user {
    background: #f3f4f6;
    color: #374151;
}

/* -- Admin -- */
.admin-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.admin-form-card {
    padding: 1.5rem;
}

.admin-form-card h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
}

/* -- Table -- */
.user-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.user-table th,
.user-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.user-table th {
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.user-table tbody tr:hover {
    background: var(--color-bg);
}

/* -- Status colors -- */
.status-locked {
    color: var(--color-success);
}

.status-unlocked {
    color: var(--color-danger);
}

.status-unknown {
    color: var(--color-text-muted);
}

/* -- Responsive -- */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    .navbar {
        padding: 0 0.75rem;
    }

    .nav-links {
        gap: 0;
    }

    .nav-link {
        padding: 0.5rem;
        font-size: 0.8125rem;
    }

    #map {
        height: 280px;
    }

    .card-grid {
        grid-template-columns: 1fr 1fr;
    }

    .card-wide {
        grid-column: span 2;
    }

    .card-value {
        font-size: 1.375rem;
    }

    .auth-card {
        padding: 1.5rem;
    }

    .form-row {
        flex-direction: column;
    }

    .user-table {
        font-size: 0.8125rem;
    }

    .user-table th,
    .user-table td {
        padding: 0.5rem;
    }
}

@media (max-width: 480px) {
    .card-grid {
        grid-template-columns: 1fr;
    }

    .card-wide {
        grid-column: span 1;
    }

    .dashboard-controls {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* ========================================================
   History & Export Pages
   ======================================================== */

/* -- Page Header -- */
.page-header {
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.page-header p {
    color: var(--color-text-muted);
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* -- Range Controls -- */
.range-controls {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem;
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
}

.range-controls .form-group {
    flex: 1;
    min-width: 130px;
    margin-bottom: 0;
}

.range-controls .form-group-btn {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-end;
    margin-bottom: 0;
}

.range-controls .text-muted {
    align-self: center;
    flex: 0 0 auto;
}

/* -- Charts Grid -- */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(480px, 1fr));
    gap: 1.25rem;
}

.chart-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.chart-card h3 {
    font-size: 0.8125rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    margin-bottom: 1rem;
}

.chart-canvas-wrapper {
    position: relative;
    height: 220px;
}

.chart-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 220px;
    color: var(--color-text-muted);
    font-size: 0.875rem;
    background: var(--color-bg);
    border-radius: var(--radius);
}

/* -- Data Table -- */
.data-table-wrapper {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
    white-space: nowrap;
}

.data-table th {
    background: var(--color-bg);
    padding: 0.625rem 0.875rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--color-border);
    user-select: none;
}

.data-table th.sortable {
    cursor: pointer;
}

.data-table th.sortable:hover {
    background: #edf0f3;
    color: var(--color-text);
}

.data-table .sort-icon {
    display: inline-block;
    margin-left: 0.25rem;
    font-size: 0.7rem;
    opacity: 0.35;
}

.data-table th.sort-asc .sort-icon::after  { content: "▲"; opacity: 1; }
.data-table th.sort-desc .sort-icon::after { content: "▼"; opacity: 1; }
.data-table th:not(.sort-asc):not(.sort-desc) .sort-icon::after { content: "⇅"; }

.data-table td {
    padding: 0.625rem 0.875rem;
    border-bottom: 1px solid var(--color-border);
}

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

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

.data-table td.null-value {
    color: var(--color-text-muted);
}

/* -- Pagination -- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1.25rem;
    border-top: 1px solid var(--color-border);
    background: var(--color-surface);
    font-size: 0.8125rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.pagination-buttons {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* -- Export -- */
.export-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

.export-section-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.export-section-card h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.count-badge {
    display: inline-flex;
    align-items: center;
    background: #dbeafe;
    color: #1e40af;
    border-radius: 999px;
    padding: 0.25rem 0.875rem;
    font-size: 0.8125rem;
    font-weight: 600;
    width: fit-content;
}

.format-options {
    display: flex;
    gap: 1.5rem;
}

.format-option {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.875rem;
    cursor: pointer;
}

/* -- Empty State -- */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--color-text-muted);
}

.empty-state svg {
    margin: 0 auto 0.75rem;
    display: block;
    opacity: 0.35;
}

/* -- Spinner -- */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* -- Responsive (History Pages) -- */
@media (max-width: 900px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }

    .export-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .data-table-wrapper {
        overflow-x: auto;
    }
}
