/* One font, set once */
body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ------------
   The badges (Low, Out, Short, Late, Overdue, Sold, Used, Cost pending)
   use these. They were added in Bootstrap 5.2; without them the badges
   show as white text on white. Uses the theme's own colours. Harmless if
   Bootstrap is upgraded later (5.2+ defines the same classes).
   ------------ */
.text-bg-primary   { color: #fff !important; background-color: rgba(var(--bs-primary-rgb), 1) !important; }
.text-bg-secondary { color: #fff !important; background-color: rgba(var(--bs-secondary-rgb), 1) !important; }
.text-bg-success   { color: #fff !important; background-color: rgba(var(--bs-success-rgb), 1) !important; }
.text-bg-danger    { color: #fff !important; background-color: rgba(var(--bs-danger-rgb), 1) !important; }
.text-bg-warning   { color: #000 !important; background-color: rgba(var(--bs-warning-rgb), 1) !important; }
.text-bg-info      { color: #000 !important; background-color: rgba(var(--bs-info-rgb), 1) !important; }
.text-bg-light     { color: #000 !important; background-color: rgba(var(--bs-light-rgb), 1) !important; }
.text-bg-dark      { color: #fff !important; background-color: rgba(var(--bs-dark-rgb), 1) !important; }

.fw-semibold { font-weight: 600 !important; }

/* Dark yellow that is readable on white (warning text, not badges) */
.text-warning-emphasis { color: #664d03 !important; }


/* Desktop sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    overflow-y: auto;
    z-index: 1030;
}

/* Push page content right of the sidebar (only when a sidebar is shown) */
@media (min-width: 992px) {
    main.has-sidebar {
        margin-left: 260px;
        /* container-fluid is width:100%; with the margin that is wider than
           the window. Auto width fills only the space next to the sidebar. */
        width: auto;
        transition: margin-left 0.2s ease;
    }
}

/* Menu links */
.sidebar-menu .nav-link {
    border-radius: 8px;
    margin-bottom: 2px;
}

.sidebar-menu .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.15);
}

.sidebar-menu .nav-link.active-sub {
    color: #fff !important;
    font-weight: 600;
}

/* Chevron flips when a group is open */
.sidebar-menu .nav-link .fa-chevron-down {
    transition: transform 0.2s;
}

.sidebar-menu .nav-link[aria-expanded="true"] .fa-chevron-down {
    transform: rotate(180deg);
}


/* ------------
   Collapsible desktop sidebar (arrow button in the sidebar header).
   html.sidebar-collapsed is set by sidebar.js and remembered per browser.
   Phones are not affected: they use the slide-out menu instead.
   ------------ */
.sidebar {
    transition: width 0.2s ease;
}

.sidebar-toggle {
    width: 32px;
    height: 32px;
    padding: 0;
    flex-shrink: 0;
}

.sidebar-toggle i {
    transition: transform 0.2s ease;
}

@media (min-width: 992px) {
    html.sidebar-collapsed .sidebar {
        width: 76px;
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
        overflow-x: hidden;
    }

    html.sidebar-collapsed main.has-sidebar {
        margin-left: 76px;
    }

    /* Icons only: hide the words, the group arrows and the sub-menus */
    html.sidebar-collapsed .sidebar .sidebar-label,
    html.sidebar-collapsed .sidebar .collapse,
    html.sidebar-collapsed .sidebar .dropdown-toggle::after {
        display: none !important;
    }

    html.sidebar-collapsed .sidebar .fa-fw.me-2,
    html.sidebar-collapsed .sidebar .fs-4.me-2 {
        margin-right: 0 !important;
    }

    html.sidebar-collapsed .sidebar-menu .nav-link,
    html.sidebar-collapsed .sidebar .dropdown > a {
        justify-content: center !important;
        text-align: center;
    }

    /* Logo on top, arrow underneath, both centred */
    html.sidebar-collapsed .sidebar-header {
        flex-direction: column;
        gap: 0.75rem;
    }

    /* Only the car mark shows in the narrow sidebar */
    html.sidebar-collapsed .sidebar-brand .brand-collapsed {
        display: block;
    }

    /* Arrow points right when collapsed ("open me") */
    html.sidebar-collapsed .sidebar-toggle i {
        transform: rotate(180deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .sidebar,
    .sidebar-toggle i,
    main.has-sidebar {
        transition: none !important;
    }
}

/* =============
   Dashboard tiles and drill-down lists
   ============= */

.dash-tile {
    border-radius: 12px;
    transition: box-shadow 0.15s, transform 0.15s;
}

.dash-tile:hover,
.dash-tile:focus-within {
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.12) !important;
    transform: translateY(-1px);
}

.dash-tile .card-header {
    border-bottom: 0;
    padding-top: 0.9rem;
}

/* The one big number on a tile */
.dash-hero {
    font-size: 2.25rem;
    font-weight: 600;
    line-height: 1.1;
}

.dash-subhead {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--bs-secondary-color, #6c757d);
    margin-bottom: 0.5rem;
}

/* Numbers line up in columns */
.dash-table .num,
.dash-rank .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.dash-table th {
    font-weight: 600;
    font-size: 0.85rem;
}

/* Short ranked lists on tiles */
.dash-rank {
    margin: 0;
    padding-left: 1.25rem;
}

.dash-rank li {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.2rem 0;
    border-bottom: 1px solid var(--bs-border-color-translucent, rgba(0, 0, 0, 0.08));
}

.dash-rank li:last-child {
    border-bottom: 0;
}

ul.dash-rank {
    padding-left: 0;
}

.dash-filter .form-label {
    color: var(--bs-secondary-color, #6c757d);
}

/* Tables inside a tile sit above the tile's link, so on a phone you can
   scroll them sideways without opening the full list by accident. */
.dash-tile .table-responsive {
    position: relative;
    z-index: 2;
}


/* =============
   Sell parts screen
   ============= */
.sell-results {
    max-height: 60vh;
    overflow-y: auto;
}

.sell-results .min-w-0 {
    min-width: 0;
}

.sell-qty-col {
    width: 9rem;
}

.sell-qty {
    width: 8rem;
    margin: 0 auto;
    flex-wrap: nowrap;
}

/* Hide the browser's own up/down arrows: the - and + buttons do that job */
.sell-qty input::-webkit-outer-spin-button,
.sell-qty input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.sell-qty input[type="number"] {
    -moz-appearance: textfield;
}

/* Phones: narrower quantity control so the item name has room */
@media (max-width: 575.98px) {
    .sell-qty-col {
        width: 6.5rem;
    }

    .sell-qty {
        width: 6rem;
    }

    .sell-qty .btn {
        padding-left: 0.4rem;
        padding-right: 0.4rem;
    }
}

.sell-price-input {
    width: 7rem;
    margin-left: auto;
}

.sell-totals dd {
    font-variant-numeric: tabular-nums;
}

@media print {
    .sidebar,
    .navbar,
    .alert {
        display: none !important;
    }

    main.has-sidebar {
        margin-left: 0 !important;
    }

    .sell-receipt {
        box-shadow: none !important;
        border: 0;
    }
}


/* =============
   Camera scanning, receive screen and shelf labels
   ============= */
.min-w-0 {
    min-width: 0;
}

.camera-region {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    border-radius: 8px;
    overflow: hidden;
    background: #000;
}

.camera-region video {
    width: 100% !important;
    display: block;
}

[data-camera-scan][aria-pressed="true"] {
    color: #fff;
    background-color: rgba(var(--bs-danger-rgb), 1);
    border-color: rgba(var(--bs-danger-rgb), 1);
}

/* Shelf labels: about 7 x 3.5 cm each, three across on A4 / Letter */
.label-sheet {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(7cm, 1fr));
    gap: 0.4cm;
}

.shelf-label {
    display: flex;
    gap: 0.25cm;
    align-items: center;
    height: 3.5cm;
    padding: 0.2cm;
    border: 1px dashed #adb5bd;
    border-radius: 6px;
    background: #fff;
    break-inside: avoid;
    page-break-inside: avoid;
    overflow: hidden;
}

.shelf-label-qr {
    flex: 0 0 2.9cm;
    width: 2.9cm;
    height: 2.9cm;
}

.shelf-label-qr svg {
    width: 100%;
    height: 100%;
    display: block;
}

.shelf-label-text {
    min-width: 0;
    line-height: 1.2;
}

.shelf-label-name {
    font-weight: 700;
    font-size: 11pt;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.shelf-label-meta {
    font-size: 8pt;
    color: #495057;
}

.shelf-label-code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 9pt;
    margin-top: 0.1cm;
    word-break: break-all;
}

.shelf-label-price {
    font-weight: 700;
    font-size: 13pt;
    margin-top: 0.1cm;
}

@media print {
    body,
    body.bg-light {
        background: #fff !important;
    }

    main {
        padding: 0 !important;
    }

    .label-sheet {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.3cm;
    }

    .shelf-label {
        border-color: #ced4da;
    }
}

/* Prices and margins page: a row priced below cost */
.price-table tr.price-below-cost .js-price { color: var(--bs-danger); font-weight: 600; }

/* Price tags: about 6 x 3.4 cm, 3 across on A4 / Letter */
.tag-sheet {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(6cm, 1fr));
    gap: 0.3cm;
}

.price-tag {
    border: 1px dashed #adb5bd;
    border-radius: 0.25rem;
    padding: 0.2cm 0.25cm;
    background: #fff;
    height: 3.4cm;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    break-inside: avoid;
    page-break-inside: avoid;
}

.price-tag-name {
    font-weight: 600;
    font-size: 9.5pt;
    line-height: 1.15;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.price-tag-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.2cm;
}

.price-tag-price {
    font-size: 22pt;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
}

.price-tag-qr {
    flex: 0 0 1.5cm;
    width: 1.5cm;
    height: 1.5cm;
}

.price-tag-qr svg {
    width: 100%;
    height: 100%;
    display: block;
}

.price-tag-meta {
    font-size: 7pt;
    color: #495057;
}

.price-tag-code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media print {
    .tag-sheet {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.2cm;
    }
    .price-tag {
        border-color: #ced4da;
    }
}

/* Any QR code drawn inside a sized box (receipts, return slips) */
.qr-box svg { width: 100%; height: 100%; display: block; }

/* Returns: who pays whom */
.return-result { background: var(--bs-light); border: 1px solid #dee2e6; }
.return-result.return-give { background: #fff3cd; border-color: #ffda6a; }
.return-result.return-take { background: #d1e7dd; border-color: #a3cfbb; }
.return-result.return-even { background: #e2e3e5; }

/* Inspection photos */
.photo-preview { width: 72px; height: 72px; object-fit: cover; border-radius: 0.25rem; border: 1px solid #dee2e6; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.75rem; }
.photo-tile img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 0.25rem; border: 1px solid #dee2e6; background: #fff; }
.inspection-checklist .btn-group .btn { white-space: nowrap; }
@media print {
    .photo-grid { grid-template-columns: repeat(3, 1fr); }
    .photo-tile { break-inside: avoid; }
}

/* Repair job: part search drop-down */
.part-results { position: absolute; z-index: 10; left: 0.25rem; right: 0.25rem; max-height: 18rem; overflow-y: auto; }

.photo-removed img { opacity: 0.45; filter: grayscale(1); }


/* =============
   AutoCore look: colours, sidebar, top bar, cards, brand
   Change the colours here to re-theme the whole app.
   ============= */
:root {
    --ac-navy: #0b1730;
    --ac-navy-2: #10264a;
    --ac-blue: #2563eb;
    --ac-blue-soft: #dbeafe;
    --ac-green: #16a34a;
    --ac-green-soft: #dcfce7;
    --ac-page: #f4f6fb;
    --ac-line: #e6eaf1;
    --ac-text-soft: #5b6475;
}

.app-body { background-color: var(--ac-page); }

/* Sidebar and phone menu: deep navy */
.sidebar,
.app-offcanvas,
.app-navbar {
    background: linear-gradient(180deg, var(--ac-navy) 0%, var(--ac-navy-2) 100%);
}

.sidebar-menu .nav-link {
    color: rgba(255, 255, 255, 0.85) !important;
    padding: 0.6rem 0.85rem;
    border-radius: 10px;
}

.sidebar-menu .nav-link.active {
    background-color: var(--ac-blue);
    color: #fff !important;
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.35);
}

.sidebar-menu .nav-link:hover:not(.active) {
    background-color: rgba(255, 255, 255, 0.08);
}

.sidebar hr,
.app-offcanvas hr { border-color: rgba(255, 255, 255, 0.15); }

/* Brand: car mark + AutoCore + line under it */
.brand { line-height: 1.1; }
.brand-mark { color: #60a5fa; display: block; height: auto; }
.brand-name { font-size: 1.65rem; font-weight: 700; letter-spacing: -0.01em; }
.brand-auto { color: #fff; }
.brand-core { color: #3b82f6; }
.brand-tagline {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.62rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    margin-top: 0.15rem;
}
.sidebar-brand { display: block; }
.sidebar-brand .brand-collapsed { display: none; }
.sidebar-brand .brand-collapsed .brand-mark { margin: 0 auto; }
.brand-inline { display: inline-flex; align-items: center; gap: 0.4rem; }
.brand-inline .brand-name { font-size: 1.25rem; }

/* Dark strip with the brand on the sign-in and setup pages */
.brand-strip { background: linear-gradient(180deg, var(--ac-navy) 0%, var(--ac-navy-2) 100%); }

/* Top bar (desktop): the person's menu on the right */
.app-topbar {
    margin: -1rem -0.75rem 1.25rem;
    padding: 0.6rem 1.5rem;
    background-color: #fff;
    border-bottom: 1px solid var(--ac-line);
    position: sticky;
    top: 0;
    z-index: 1020;
}

.user-menu .dropdown-toggle { color: inherit; }
.user-menu .dropdown-toggle::after { margin-left: 0.4rem; color: var(--ac-text-soft); }
.user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background-color: var(--ac-navy-2);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 600;
    flex-shrink: 0;
}
.user-text { display: inline-flex; flex-direction: column; line-height: 1.2; }
.user-name { font-weight: 600; color: #111827; }
.user-role { font-size: 0.78rem; color: var(--ac-text-soft); }
.app-navbar .user-name { color: #fff; }
.app-navbar .user-role { color: rgba(255, 255, 255, 0.7); }
.app-navbar .user-avatar { background-color: var(--ac-blue); }

/* Cards: white, rounded, soft shadow */
.card {
    border-color: var(--ac-line);
    border-radius: 14px;
}
.card > .card-header:first-child { border-radius: 14px 14px 0 0; }
.card > .card-footer:last-child { border-radius: 0 0 14px 14px; }

/* Dashboard welcome */
.welcome-title { font-size: 1.9rem; font-weight: 700; color: #111827; }
.welcome-sub { color: var(--ac-text-soft); font-size: 1.05rem; }
.welcome-date { color: var(--ac-text-soft); padding-top: 0.6rem; white-space: nowrap; }

/* Sales cards */
.kpi-card {
    border: 1px solid var(--ac-line);
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
    transition: box-shadow 0.15s, transform 0.15s;
}
.kpi-card:hover,
.kpi-card:focus {
    box-shadow: 0 0.5rem 1rem rgba(16, 24, 40, 0.1);
    transform: translateY(-1px);
}
.kpi-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 12px;
    font-size: 1.4rem;
    flex-shrink: 0;
}
.kpi-green { background-color: var(--ac-green-soft); color: var(--ac-green); }
.kpi-blue { background-color: var(--ac-blue-soft); color: var(--ac-blue); }
.kpi-title { color: #374151; font-weight: 500; }
.kpi-amount { font-size: 1.75rem; font-weight: 700; color: #111827; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi-compare { color: var(--ac-text-soft); font-size: 0.85rem; }

@media print {
    .app-topbar { display: none !important; }
}


/* Register: Last sale card. On paper only the receipt shows (the Register
   above it is d-print-none); the card's own buttons are d-print-none too. */
@media print {
    .last-sale { margin-top: 0 !important; }
    .last-sale > .card-body { padding: 0; }
}

.pay-choice legend { font-size: 1rem; font-weight: 500; float: none; width: auto; }
.pay-choice .btn { padding-top: 0.55rem; padding-bottom: 0.55rem; }


/* =============
   Vehicles: status badges, extra card colours, photos, window sticker
   ============= */
/* One colour per stock status (set in vehicle_service.STATUS_BADGES). */
.vbadge { display: inline-block; padding: 0.3em 0.65em; border-radius: 6px; font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.vbadge-green  { background: #dcfce7; color: #15803d; }
.vbadge-blue   { background: #dbeafe; color: #1d4ed8; }
.vbadge-amber  { background: #fef3c7; color: #b45309; }
.vbadge-purple { background: #ede9fe; color: #6d28d9; }
.vbadge-red    { background: #fee2e2; color: #b91c1c; }
.vbadge-grey   { background: #f1f5f9; color: #475569; }
.vbadge-dark   { background: #334155; color: #fff; }

/* Extra colours for the status cards (kpi-green / kpi-blue already exist). */
.kpi-amber  { background-color: #fef3c7; color: #d97706; }
.kpi-purple { background-color: #ede9fe; color: #7c3aed; }
.kpi-red    { background-color: #fee2e2; color: #dc2626; }
.kpi-selected { border-color: var(--ac-blue); box-shadow: 0 0 0 2px var(--ac-blue-soft); }

/* Car photos in lists: small, cropped to the same size. */
.vehicle-thumb { width: 72px; }
.vehicle-thumb img { width: 64px; height: 44px; object-fit: cover; border-radius: 6px; display: block; }
.vehicle-thumb-empty { display: inline-flex; align-items: center; justify-content: center; width: 64px; height: 44px;
                       border-radius: 6px; background: #f1f5f9; color: #94a3b8; }
.vehicle-thumb-lg, .vehicle-thumb-lg img, .vehicle-thumb-lg .vehicle-thumb-empty { width: 120px; height: 80px; }
.vehicle-thumb-lg { flex-shrink: 0; }

/* Window sticker: one page, big and clear. */
.window-sticker { max-width: 34rem; border: 2px solid #111827; }
@media print {
    .window-sticker { border: 2px solid #000; box-shadow: none; max-width: none; }
}

/* Cards: text gets SMALLER instead of wrapping when a card is narrow.
   Each card is a "container"; sizes below follow the card's own width
   (cqi = 1% of the card's width), between a minimum and the normal size.
   Browsers too old for this simply keep the normal sizes above. */
.kpi-card { container-type: inline-size; }
.kpi-card .card-body { flex-wrap: nowrap; }
.kpi-title, .kpi-amount, .kpi-compare, .kpi-change {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;   /* last resort on very narrow cards: "..." */
}
.kpi-icon   { width: clamp(34px, 16cqi, 56px); height: clamp(34px, 16cqi, 56px); font-size: clamp(0.95rem, 6cqi, 1.4rem); }
.kpi-title  { font-size: clamp(0.72rem, 5.2cqi, 1rem); }
.kpi-amount { font-size: clamp(1rem, 9cqi, 1.75rem); }
.kpi-compare, .kpi-change { font-size: clamp(0.68rem, 4.4cqi, 0.85rem); }

/* "vs last week" line under the sales cards */
.kpi-change { font-weight: 600; margin-top: 0.1rem; }
.kpi-change-up   { color: #15803d; }
.kpi-change-down { color: #b91c1c; }
.kpi-change-same, .kpi-change-new, .kpi-change-none { color: var(--ac-text-soft); font-weight: 500; }

/* Xtreme Auto logo (picture) in the menu and on the sign-in page */
.brand-logo-img { display: block; height: auto; max-width: 100%; }
.brand-logo-full { width: 156px; margin: 0 auto; }

/* Register: Last sale card. On paper only the receipt shows (the Register
   above it is d-print-none); the card's own buttons are d-print-none too. */
@media print {
    .last-sale { margin-top: 0 !important; }
    .last-sale > .card-body { padding: 0; }
}


/* Dashboard: Quick links. On staff dashboards (no money row) the card is full width,
   so the links sit side by side instead of in one long list. */
.quick-links .list-group-item { border-left: 0; border-right: 0; }
@media (min-width: 768px) {
    .quick-links-wide { flex-direction: row; flex-wrap: wrap; }
    .quick-links-wide .list-group-item { flex: 1 1 33%; border-top: 0; }
}
