/* ===================================================================
   ระบบขายรถมือสอง — Custom styles layered on top of Bootstrap 5.3
   Theme is driven by [data-theme="light"|"dark"] on <html>, kept in
   sync with Bootstrap's own [data-bs-theme] attribute by app.js.
   =================================================================== */

:root {
    --sidebar-width: 240px;
    --sidebar-collapsed-width: 64px;
    --navbar-height: 56px;
}

:root[data-theme="light"] {
    --app-bg: #f1f5f9;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --text-muted: #64748b;
    --sidebar-bg: #1e293b;
    --sidebar-text: #cbd5e1;
    --sidebar-text-active: #ffffff;
    --sidebar-active-bg: #2563eb;
    --navbar-bg: #ffffff;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

:root[data-theme="dark"] {
    --app-bg: #0b1220;
    --card-bg: #131c2e;
    --border-color: #24304a;
    --text-muted: #94a3b8;
    --sidebar-bg: #0a0f1c;
    --sidebar-text: #94a3b8;
    --sidebar-text-active: #ffffff;
    --sidebar-active-bg: #2563eb;
    --navbar-bg: #131c2e;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

body {
    background-color: var(--app-bg);
    color-scheme: light;
}
:root[data-theme="dark"] body {
    color-scheme: dark;
}

/* ---------------- Login page ---------------- */
.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e293b 0%, #2563eb 100%);
}
.login-wrapper { width: 100%; max-width: 400px; padding: 16px; }
.login-card { border: none; border-radius: 16px; }

/* ---------------- Top navbar ---------------- */
.app-navbar {
    height: var(--navbar-height);
    background-color: var(--navbar-bg);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 1030;
}

/* ---------------- Layout ---------------- */
.app-layout {
    display: flex;
    min-height: calc(100vh - var(--navbar-height));
}

.app-sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    position: sticky;
    top: var(--navbar-height);
    height: calc(100vh - var(--navbar-height));
    overflow-y: auto;
    transition: transform 0.2s ease;
}

.sidebar-link {
    color: var(--sidebar-text) !important;
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.925rem;
}
.sidebar-link i { font-size: 1.05rem; width: 20px; text-align: center; }
.sidebar-link:hover { background-color: rgba(255, 255, 255, 0.08); color: var(--sidebar-text-active) !important; }
.sidebar-link.active { background-color: var(--sidebar-active-bg); color: var(--sidebar-text-active) !important; }
.sidebar-divider { border-color: rgba(255, 255, 255, 0.1); margin: 10px 4px; }

.app-main {
    flex-grow: 1;
    padding: 24px;
    min-width: 0;
}

@media (max-width: 767.98px) {
    .app-sidebar {
        position: fixed;
        left: 0;
        transform: translateX(-100%);
        z-index: 1040;
        box-shadow: var(--shadow);
    }
    .app-sidebar.show { transform: translateX(0); }
    .app-main { padding: 16px; }
}

/* Icon-only sidebar mode, toggled by the navbar hamburger button on desktop and persisted
   in localStorage; the html[data-sidebar-collapsed] attribute is applied pre-paint (see
   includes/header.php) to avoid a layout flash on load. */
@media (min-width: 768px) {
    html[data-sidebar-collapsed="true"] .app-sidebar { width: var(--sidebar-collapsed-width); }
    html[data-sidebar-collapsed="true"] .sidebar-link { justify-content: center; padding: 10px 0; }
    html[data-sidebar-collapsed="true"] .sidebar-link i { width: auto; font-size: 1.2rem; }
    html[data-sidebar-collapsed="true"] .sidebar-link span { display: none; }
}

/* ---------------- Cards / widgets ---------------- */
.card {
    background-color: var(--card-bg);
    border-color: var(--border-color);
}

.kpi-card { border-radius: 14px; border: 1px solid var(--border-color); }
.kpi-icon {
    width: 48px; height: 48px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.4rem;
}
.kpi-value { font-size: 1.6rem; font-weight: 700; }
.kpi-label { color: var(--text-muted); font-size: 0.85rem; }

.text-muted-soft { color: var(--text-muted) !important; }

.settings-hub-card { transition: transform 0.15s ease, box-shadow 0.15s ease; }
.settings-hub-card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(15, 23, 42, 0.12); border-color: var(--sidebar-active-bg); }

/* ---------------- Simple CSS bar charts (no chart library) ---------------- */
.bar-chart { display: flex; align-items: flex-end; gap: 10px; height: 200px; padding-top: 10px; }
.bar-chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar-chart-bar {
    width: 100%;
    max-width: 42px;
    background: linear-gradient(180deg, #3b82f6, #2563eb);
    border-radius: 6px 6px 0 0;
    min-height: 2px;
    transition: height 0.3s ease;
}
.bar-chart-label { font-size: 0.75rem; color: var(--text-muted); margin-top: 6px; text-align: center; }
.bar-chart-value { font-size: 0.72rem; color: var(--text-muted); margin-bottom: 2px; }

/* ---------------- Grouped revenue/profit comparison bars (dashboard trend) ---------------- */
.bar-chart-legend { display: flex; gap: 18px; margin-bottom: 10px; font-size: 0.8rem; color: var(--text-muted); }
.bar-chart-legend-item { display: flex; align-items: center; gap: 6px; }
.bar-chart-legend-swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.bar-chart-bar-pair { display: flex; align-items: flex-end; gap: 4px; height: 100%; }
.bar-chart-bar-pair .bar-chart-bar { width: 22px; max-width: 22px; background: none; border-radius: 4px 4px 0 0; }
.bar-chart-pair-values { display: flex; flex-direction: column; align-items: center; gap: 1px; margin-bottom: 2px; }
.bar-chart-pair-values span { font-size: 0.62rem; line-height: 1.1; color: var(--text-muted); }

.hbar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.hbar-label { width: 130px; font-size: 0.85rem; flex-shrink: 0; }
.hbar-track { flex-grow: 1; background: var(--app-bg); border-radius: 6px; height: 18px; overflow: hidden; }
.hbar-fill { height: 100%; background: linear-gradient(90deg, #2563eb, #3b82f6); border-radius: 6px; }
.hbar-value { width: 50px; text-align: right; font-size: 0.8rem; color: var(--text-muted); }

/* ---------------- Per-branch mini trend rows (dashboard "all branches" comparison) ---------------- */
.branch-trend-row { display: flex; align-items: center; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--app-bg); }
.branch-trend-row:last-child { border-bottom: none; }
.branch-trend-label { width: 140px; flex-shrink: 0; font-size: 0.85rem; font-weight: 600; }
.branch-trend-label .branch-trend-total { display: block; font-weight: 400; font-size: 0.75rem; color: var(--text-muted); }
.bar-chart-sm { height: 70px; flex-grow: 1; gap: 6px; }
.bar-chart-sm .bar-chart-bar { max-width: 28px; }
.bar-chart-sm .bar-chart-value { font-size: 0.65rem; }
.bar-chart-sm .bar-chart-label { font-size: 0.68rem; }

/* ---------------- Car image upload preview ---------------- */
.img-upload-preview { width: 90px; height: 68px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border-color); position: relative; }

/* ---------------- Car list cover thumbnail (click to open gallery) ---------------- */
.car-thumb-sm { width: 72px; height: 56px; object-fit: cover; border-radius: 4px; border: 1px solid var(--border-color); cursor: pointer; }
.car-thumb-sm-placeholder { width: 72px; height: 56px; border-radius: 4px; cursor: pointer; }
#carImageCarouselInner img { width: 100%; max-height: 480px; object-fit: contain; background: var(--app-bg); }

/* No `overflow: hidden` here on purpose — it used to clip any dropdown-menu that opened near
   the top/bottom edge of a short table (especially the last couple of rows). Corners are
   rounded per-cell instead so the card still looks rounded without clipping child content. */
.table-responsive-card { background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 12px; }
.table-responsive-card > table { margin-bottom: 0; }
.table-responsive-card > table > thead > tr:first-child > th:first-child { border-top-left-radius: 11px; }
.table-responsive-card > table > thead > tr:first-child > th:last-child { border-top-right-radius: 11px; }
.table-responsive-card > table > tbody > tr:last-child > td:first-child { border-bottom-left-radius: 11px; }
.table-responsive-card > table > tbody > tr:last-child > td:last-child { border-bottom-right-radius: 11px; }

/* ---------------- Mobile card view (replaces the table below the md breakpoint) ---------------- */
.mobile-card-list { display: flex; flex-direction: column; gap: 10px; }
.mobile-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px;
}
.mobile-card-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; font-size: 0.85rem; }
.mobile-card-facts .label { color: var(--text-muted); }
.mobile-card-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------------- Car full detail report (shared by print window + PDF rasterization) ----------------
   Kept as real classes (not an inline <style> string) so car-full-report-pdf.js can render
   this markup into a plain, attached DOM node and have html2canvas compute correct styles
   from it — jsPDF's built-in fonts can't draw Thai glyphs, so the report text always has to
   be rendered by the browser first. */
.car-report-print { font-family: "Tahoma", "Leelawadee UI", sans-serif; font-size: 12.5px; color: #000; background: #fff; }
.car-report-print .doc-header { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid #333; padding-bottom: 10px; margin-bottom: 14px; }
.car-report-print .doc-header h1 { font-size: 19px; margin: 0 0 4px 0; }
.car-report-print .doc-header .company-name { font-size: 14px; font-weight: bold; margin: 0 0 2px 0; }
.car-report-print .doc-header .meta { font-size: 11.5px; color: #444; }
.car-report-print .doc-header img { width: 120px; height: 90px; object-fit: cover; border: 1px solid #999; border-radius: 4px; }
.car-report-print h3 { font-size: 13px; margin: 16px 0 6px 0; border-bottom: 1px solid #999; padding-bottom: 3px; }
.car-report-print table.kv { width: 100%; border-collapse: collapse; }
.car-report-print table.kv th { width: 22%; background: #f0f0f0; font-weight: normal; text-align: left; border: 1px solid #999; padding: 5px 7px; }
.car-report-print table.kv td { width: 28%; border: 1px solid #999; padding: 5px 7px; }
.car-report-print table.itemized { width: 100%; border-collapse: collapse; }
.car-report-print table.itemized th, .car-report-print table.itemized td { border: 1px solid #999; padding: 5px 7px; text-align: left; }
.car-report-print table.itemized th { background: #f0f0f0; }
.car-report-print table.itemized tfoot td { background: #f7f7f7; }
.car-report-print .text-end { text-align: right; }
.car-report-print .text-muted { color: #666; }
