/* ═══════════════════════════════════════════════════════════════════════════
   MyVWOnline — Dark Theme Stylesheet
   ═══════════════════════════════════════════════════════════════════════════ */

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

:root {
    --bg: #0d1117;
    --card: #161b22;
    --border: #30363d;
    --text: #e6edf3;
    --text2: #8b949e;
    --text3: #484f58;
    --green: #238636;
    --green-bright: #3fb950;
    --blue: #1f6feb;
    --blue-bright: #388bfd;
    --red: #b91c1c;
    --red-bright: #f85149;
    --yellow: #d29922;
    --orange: #db6d28;
    --radius: 10px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
}

html { scroll-behavior: smooth; }

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

a { color: var(--blue-bright); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.875rem; font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, border-color .15s, opacity .15s;
    font-family: var(--font);
    line-height: 1.4;
}
.btn:hover { text-decoration: none; opacity: 0.9; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn-primary:hover { background: #2ea043; }
.btn-blue { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-blue:hover { background: #1a60d2; }
.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn-danger:hover { background: #991b1b; }
.btn-outline { background: transparent; color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: #21262d; border-color: var(--text2); }
.btn-ghost { background: transparent; color: var(--text2); border: none; padding: 6px 10px; }
.btn-ghost:hover { color: var(--text); background: #21262d; }

.btn-sm { padding: 4px 12px; font-size: 0.8rem; }
.btn-lg { padding: 12px 28px; font-size: 1rem; }
.btn-block { width: 100%; }

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}
.card-title { font-size: 0.8rem; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 12px; }

/* ── Badges ────────────────────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem; font-weight: 500;
}
.badge-green { background: rgba(35,134,54,0.2); color: var(--green-bright); }
.badge-blue { background: rgba(31,111,235,0.2); color: var(--blue-bright); }
.badge-red { background: rgba(185,28,28,0.2); color: var(--red-bright); }
.badge-yellow { background: rgba(210,153,34,0.2); color: var(--yellow); }
.badge-gray { background: rgba(139,148,158,0.15); color: var(--text2); }

/* ── Stat Rows ─────────────────────────────────────────────────────────────── */
.stat-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid #21262d; }
.stat-row:last-child { border-bottom: none; }
.stat-label { color: var(--text2); font-size: 0.85rem; }
.stat-value { font-weight: 600; font-size: 0.95rem; }

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.85rem; color: var(--text2); margin-bottom: 4px; font-weight: 500; }
.form-control {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.9rem;
    font-family: var(--font);
    transition: border-color .15s;
}
.form-control:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(31,111,235,0.15); }
select.form-control { cursor: pointer; appearance: auto; }
textarea.form-control { resize: vertical; min-height: 80px; }

/* ── Alerts ────────────────────────────────────────────────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    font-size: 0.9rem;
    margin-bottom: 16px;
    border: 1px solid;
}
.alert-success { background: rgba(35,134,54,0.1); border-color: var(--green); color: var(--green-bright); }
.alert-error { background: rgba(185,28,28,0.1); border-color: var(--red); color: var(--red-bright); }
.alert-info { background: rgba(31,111,235,0.1); border-color: var(--blue); color: var(--blue-bright); }
.alert-warning { background: rgba(210,153,34,0.1); border-color: var(--yellow); color: var(--yellow); }

/* ── Modals ────────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
    opacity: 0; pointer-events: none;
    transition: opacity .2s;
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }
.modal {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    width: 90%; max-width: 480px;
    max-height: 90vh; overflow-y: auto;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-header h3 { margin: 0; }
.modal-close { background: none; border: none; color: var(--text2); font-size: 1.5rem; cursor: pointer; padding: 0; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* ── Tabs ──────────────────────────────────────────────────────────────────── */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    gap: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 20px;
}
.tab {
    padding: 10px 16px;
    font-size: 0.85rem;
    color: var(--text2);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    background: none;
    border-top: none; border-left: none; border-right: none;
    font-family: var(--font);
    transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--blue); font-weight: 500; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── SOC Ring ──────────────────────────────────────────────────────────────── */
.soc-ring {
    position: relative;
    width: 120px; height: 120px;
    margin: 0 auto;
}
.soc-ring canvas { width: 120px; height: 120px; }
.soc-ring .soc-text {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.soc-ring .soc-percent { font-size: 1.8rem; font-weight: 700; line-height: 1; }
.soc-ring .soc-label { font-size: 0.7rem; color: var(--text2); }

/* ── Tables ────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.data-table th {
    text-align: left; padding: 10px 12px;
    background: #0d1117; color: var(--text2);
    font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
table.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #21262d;
    color: var(--text);
}
table.data-table tr:hover td { background: rgba(255,255,255,0.02); }

/* ── Pagination ────────────────────────────────────────────────────────────── */
.pagination { display: flex; gap: 4px; align-items: center; justify-content: center; margin-top: 16px; }
.pagination button {
    padding: 6px 12px;
    background: var(--card); border: 1px solid var(--border); border-radius: 6px;
    color: var(--text2); cursor: pointer; font-size: 0.85rem; font-family: var(--font);
}
.pagination button:hover { background: #21262d; color: var(--text); }
.pagination button.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Grid Layout ───────────────────────────────────────────────────────────── */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

/* ── App Header / Navigation ───────────────────────────────────────────────── */
.app-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 20px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 100;
}
.app-header .logo { font-size: 1.15rem; font-weight: 700; color: var(--text); text-decoration: none; }
.app-header .logo em { font-style: normal; color: var(--green-bright); }
.app-nav { display: flex; align-items: center; gap: 8px; }
.app-nav a {
    color: var(--text2); text-decoration: none; font-size: 0.85rem;
    padding: 6px 12px; border-radius: 6px; transition: background .15s, color .15s;
}
.app-nav a:hover, .app-nav a.active { color: var(--text); background: #21262d; }
.user-menu { position: relative; }
.user-menu-btn {
    background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
    color: var(--text2); padding: 6px 12px; cursor: pointer; font-size: 0.85rem; font-family: var(--font);
}
.user-menu-btn:hover { color: var(--text); border-color: var(--text2); }
.user-dropdown {
    position: absolute; right: 0; top: 110%; min-width: 180px;
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    display: none; z-index: 200;
}
.user-dropdown.open { display: block; }
.user-dropdown a {
    display: block; padding: 10px 16px; color: var(--text2); font-size: 0.85rem;
    border-bottom: 1px solid #21262d; text-decoration: none;
}
.user-dropdown a:last-child { border-bottom: none; }
.user-dropdown a:hover { background: #21262d; color: var(--text); }

/* ── Hamburger (mobile) ────────────────────────────────────────────────────── */
.hamburger {
    display: none;
    background: none; border: none; color: var(--text); font-size: 1.5rem;
    cursor: pointer; padding: 4px;
}
@media (max-width: 768px) {
    .hamburger { display: block; }
    .app-nav {
        position: fixed; top: 49px; left: 0; right: 0; bottom: 0;
        background: var(--card); flex-direction: column; align-items: stretch;
        padding: 16px; gap: 4px;
        transform: translateX(-100%); transition: transform .2s;
        z-index: 99;
    }
    .app-nav.open { transform: translateX(0); }
    .app-nav a { padding: 12px 16px; font-size: 1rem; }
}

/* ── Login / Register Card ─────────────────────────────────────────────────── */
.auth-container {
    display: flex; align-items: center; justify-content: center;
    min-height: calc(100vh - 60px); padding: 20px;
}
.auth-card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 32px;
    width: 100%; max-width: 400px;
}
.auth-card h2 { margin-bottom: 4px; }
.auth-card .sub { color: var(--text2); font-size: 0.9rem; margin-bottom: 24px; }
.auth-card .links { text-align: center; margin-top: 16px; font-size: 0.85rem; }

/* ── Dashboard ─────────────────────────────────────────────────────────────── */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; padding: 20px; max-width: 1200px; margin: 0 auto; }
.dash-header { padding: 20px 20px 0; max-width: 1200px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; }
.dash-header h1 { font-size: 1.5rem; }

/* ── Vehicle Card (dashboard) ──────────────────────────────────────────────── */
.vehicle-card { cursor: pointer; transition: border-color .15s, transform .15s; }
.vehicle-card:hover { border-color: var(--text2); transform: translateY(-2px); }
.vehicle-card .vc-top { display: flex; align-items: center; gap: 16px; margin-bottom: 12px; }
.vehicle-card .vc-info h3 { font-size: 1rem; margin-bottom: 2px; }
.vehicle-card .vc-info .vin { font-size: 0.75rem; color: var(--text3); font-family: monospace; }
.vehicle-card .vc-info .sync { font-size: 0.75rem; color: var(--text2); margin-top: 4px; }
.vehicle-card .vc-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.vehicle-card .vc-stat { text-align: center; }
.vehicle-card .vc-stat .val { font-weight: 600; font-size: 1.1rem; }
.vehicle-card .vc-stat .lbl { font-size: 0.7rem; color: var(--text2); }

/* ── Vehicle Detail ────────────────────────────────────────────────────────── */
.vehicle-detail { max-width: 1200px; margin: 0 auto; padding: 20px; }
.vehicle-detail .vd-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 8px; }
.vehicle-detail .vd-header h1 { font-size: 1.4rem; }
.vehicle-detail .vd-header .vin { font-size: 0.8rem; color: var(--text3); font-family: monospace; }

/* ── Overview Grid ─────────────────────────────────────────────────────────── */
.overview-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }

/* ── Doors SVG ─────────────────────────────────────────────────────────────── */
.doors-svg { max-width: 200px; margin: 0 auto; }
.doors-svg .door-closed { fill: var(--green); opacity: 0.3; }
.doors-svg .door-open { fill: var(--red-bright); opacity: 0.6; }
.doors-svg .door-outline { stroke: var(--border); stroke-width: 2; fill: none; }

/* ── Charts ────────────────────────────────────────────────────────────────── */
.chart-container { position: relative; width: 100%; }
.chart-container canvas { width: 100% !important; height: 250px; }
.chart-toolbar { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.chart-toolbar button {
    padding: 4px 10px; background: var(--card); border: 1px solid var(--border);
    border-radius: 6px; color: var(--text2); cursor: pointer; font-size: 0.8rem;
    font-family: var(--font);
}
.chart-toolbar button.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.chart-toolbar button:hover { border-color: var(--text2); }

/* ── Loading ───────────────────────────────────────────────────────────────── */
.loading {
    display: flex; align-items: center; justify-content: center;
    padding: 40px; color: var(--text2);
}
.spinner {
    width: 24px; height: 24px;
    border: 3px solid var(--border); border-top-color: var(--blue);
    border-radius: 50%; animation: spin 0.8s linear infinite;
    margin-right: 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toggle Switch ─────────────────────────────────────────────────────────── */
.toggle {
    position: relative; width: 44px; height: 24px; display: inline-block;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider {
    position: absolute; inset: 0; cursor: pointer;
    background: var(--border); border-radius: 24px; transition: background .2s;
}
.toggle .slider::before {
    content: ''; position: absolute;
    width: 18px; height: 18px; left: 3px; bottom: 3px;
    background: var(--text); border-radius: 50%; transition: transform .2s;
}
.toggle input:checked + .slider { background: var(--green); }
.toggle input:checked + .slider::before { transform: translateX(20px); }

/* ── Search Input ──────────────────────────────────────────────────────────── */
.search-box {
    position: relative; margin-bottom: 16px;
}
.search-box input {
    width: 100%; padding: 8px 12px 8px 36px;
    background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
    color: var(--text); font-size: 0.9rem; font-family: var(--font);
}
.search-box input:focus { outline: none; border-color: var(--blue); }
.search-box::before {
    content: '\1F50D'; position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
    font-size: 0.85rem; color: var(--text3);
}

/* ── Utility ───────────────────────────────────────────────────────────────── */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text2); }
.text-green { color: var(--green-bright); }
.text-red { color: var(--red-bright); }
.text-blue { color: var(--blue-bright); }
.text-sm { font-size: 0.8rem; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-wrap { flex-wrap: wrap; }
.inline-flex { display: inline-flex; align-items: center; gap: 6px; }
.hidden { display: none !important; }

/* ── Page container ────────────────────────────────────────────────────────── */
.page-container { max-width: 1200px; margin: 0 auto; padding: 20px; }

/* ── Admin stats ───────────────────────────────────────────────────────────── */
.admin-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 24px; }
.admin-stat { text-align: center; }
.admin-stat .val { font-size: 2rem; font-weight: 700; color: var(--blue-bright); }
.admin-stat .lbl { font-size: 0.8rem; color: var(--text2); }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .overview-grid { grid-template-columns: 1fr; }
    .auth-card { padding: 24px 16px; }
    .dash-header { flex-direction: column; align-items: flex-start; gap: 8px; }
    .tabs { gap: 0; }
    .tab { padding: 10px 10px; font-size: 0.8rem; }
}
