/* ============================================================
   Lupe's Garage — Custom Styles
   ============================================================ */

/* ---------- CSS Variables ---------- */
:root {
    --sidebar-bg:       #0f0f1a;
    --sidebar-width:    260px;
    --accent:           #e63946;
    --accent-hover:     #c1121f;
    --sidebar-text:     #c8c8d8;
    --sidebar-hover-bg: rgba(230, 57, 70, 0.12);
    --sidebar-active-bg:#e63946;
    --card-shadow:      0 2px 12px rgba(0,0,0,0.08);
    --body-bg:          #f4f5f7;
    --topbar-bg:        #0f0f1a;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

body {
    background-color: var(--body-bg);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 0.925rem;
    color: #333;
}

/* ---------- Sidebar (desktop: fixed) ---------- */
.sidebar-wrapper {
    width: var(--sidebar-width) !important;
    background-color: var(--sidebar-bg) !important;
    border-right: 1px solid rgba(255,255,255,0.05) !important;
    position: fixed !important;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    z-index: 1040;
    overflow: hidden;          /* wrapper never scrolls — inner nav does */
    transition: transform 0.3s ease;
    display: flex !important;
    flex-direction: column !important;
}

/* The Bootstrap offcanvas-body fills remaining space */
.sidebar-wrapper .offcanvas-body {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 1 0 !important;
    min-height: 0 !important;  /* allow flex children to shrink */
    padding: 0 !important;
    overflow: hidden !important;
}

/* Nav links are the only scrollable area */
.sidebar-wrapper .sidebar-nav {
    flex: 1 1 0 !important;
    overflow-y: auto !important;
    min-height: 0 !important;
}

/* Footer always sticks to the bottom — no scroll needed */
.sidebar-wrapper .sidebar-footer {
    flex-shrink: 0 !important;
    padding-bottom: 1rem !important;
}

@media (min-width: 992px) {
    .sidebar-wrapper {
        transform: none !important;
        visibility: visible !important;
    }
}

/* Never let Bootstrap's offcanvas backdrop darken the screen */
.offcanvas-backdrop { display: none !important; }
body.offcanvas-open { overflow: auto !important; padding-right: 0 !important; }

/* ---------- Main Content ---------- */
.main-content {
    min-height: 100vh;
    padding-top: 1.5rem;
    padding-bottom: 2rem;
}

@media (min-width: 992px) {
    .main-content {
        margin-left: var(--sidebar-width);
        padding-top: 1.5rem;
    }
}

@media (max-width: 991.98px) {
    .main-content {
        margin-left: 0;
        padding-top: 0;
    }
}

/* ---------- Mobile Top Bar ---------- */
.mobile-topbar {
    background-color: var(--topbar-bg) !important;
    padding: 0.6rem 1rem;
    position: sticky;
    top: 0;
    z-index: 1030;
}

/* ---------- Brand ---------- */
/* ---------- Dividers ---------- */
.sidebar-divider {
    border-color: rgba(255,255,255,0.08);
    margin: 0.3rem 1rem;
}

/* ---------- User Avatar ---------- */
.sidebar-user {
    padding: 0.4rem 0.75rem;
}
.avatar-circle {
    width: 34px;
    height: 34px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 0.9rem;
    flex-shrink: 0;
}

/* ---------- Role Badges ---------- */
.role-badge-admin   { background: #e63946; color: #fff; padding: 2px 8px; border-radius: 20px; font-size: 0.72rem; font-weight: 600; }
.role-badge-office  { background: #f4a261; color: #fff; padding: 2px 8px; border-radius: 20px; font-size: 0.72rem; font-weight: 600; }
.role-badge-tech    { background: #457b9d; color: #fff; padding: 2px 8px; border-radius: 20px; font-size: 0.72rem; font-weight: 600; }
.role-badge-chofer,
.role-badge-ayudante_mecanico,
.role-badge-ayudante_general { background: #2a9d8f; color: #fff; padding: 2px 8px; border-radius: 20px; font-size: 0.72rem; font-weight: 600; }
.role-badge-viewer  { background: #6c757d; color: #fff; padding: 2px 8px; border-radius: 20px; font-size: 0.72rem; font-weight: 600; }

/* ---------- Nav Section Labels ---------- */
.sidebar-section-label {
    text-transform: uppercase;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: rgba(255,255,255,0.3);
    padding: 0.25rem 0.5rem 0.15rem;
    margin-bottom: 0;
}

/* ---------- Sidebar Links ---------- */
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.45rem 0.75rem;
    border-radius: 8px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.875rem;
    transition: background 0.18s, color 0.18s;
    margin-bottom: 1px;
}
.sidebar-link i {
    width: 20px;
    text-align: center;
    font-size: 0.95rem;
    flex-shrink: 0;
}
.sidebar-link:hover {
    background: var(--sidebar-hover-bg);
    color: #fff;
}
.sidebar-link.active {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 2px 8px rgba(230,57,70,0.4);
}
.sidebar-link.active i { color: #fff; }
.text-danger-light { color: #ff8a8a !important; }
.text-danger-light:hover { color: #ff4444 !important; }
.text-accent { color: var(--accent) !important; }

/* ---------- Cards ---------- */
.card {
    border: none;
    box-shadow: var(--card-shadow);
    border-radius: 10px;
}
.card-header {
    background: #fff;
    border-bottom: 1px solid #eee;
    border-radius: 10px 10px 0 0 !important;
    font-weight: 600;
    padding: 0.9rem 1.2rem;
}
.card-header.collapsed-header {
    border-bottom: none;
    border-radius: 10px !important;
}

/* ---------- Stat Cards ---------- */
.stat-card {
    border-left: 4px solid var(--accent);
    transition: transform 0.15s, box-shadow 0.15s;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.12);
}
.stat-card .stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}
.stat-card .stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    line-height: 1;
}
.stat-card .stat-label {
    font-size: 0.8rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.stat-icon-red    { background: rgba(230,57,70,0.12);  color: var(--accent); }
.stat-icon-blue   { background: rgba(30,120,230,0.12); color: #1e78e6; }
.stat-icon-green  { background: rgba(34,197,94,0.12);  color: #16a34a; }
.stat-icon-orange { background: rgba(249,115,22,0.12); color: #ea580c; }
.stat-icon-purple { background: rgba(147,51,234,0.12); color: #9333ea; }

/* ---------- Status Badges ---------- */
.badge-status-open        { background: #1e78e6; color: #fff; }
.badge-status-in_progress { background: #f97316; color: #fff; }
.badge-status-completed   { background: #16a34a; color: #fff; }
.badge-status-cancelled   { background: #9ca3af; color: #fff; }

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: capitalize;
}

/* ---------- Tables ---------- */
.table-hover > tbody > tr:hover {
    background-color: rgba(230, 57, 70, 0.04);
}
.table th {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #888;
    font-weight: 700;
    border-bottom-width: 1px;
}

/* ---------- Buttons ---------- */
.btn-accent {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.btn-accent:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #fff;
}
.btn-primary {
    background: #1e78e6;
    border-color: #1e78e6;
}
.btn-primary:hover {
    background: #1460b8;
    border-color: #1460b8;
}

/* ---------- Page Header ---------- */
.page-header {
    background: #fff;
    border-bottom: 1px solid #e9ecef;
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
    border-radius: 10px;
    box-shadow: var(--card-shadow);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
}
.page-header h1 {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0;
}

/* Dashboard + button */
.btn-add-vehicle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 1.15rem;
    text-decoration: none;
    box-shadow: 0 3px 10px rgba(230,57,70,.35);
    transition: background .15s, transform .15s;
    flex-shrink: 0;
}
.btn-add-vehicle:hover { background: var(--accent-hover); color: #fff; transform: scale(1.08); }
.btn-counter-sale {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: transparent;
    color: var(--accent);
    font-size: 1.15rem;
    text-decoration: none;
    border: 2px solid var(--accent);
    box-shadow: 0 3px 10px rgba(230,57,70,.15);
    transition: background .15s, color .15s, transform .15s;
    flex-shrink: 0;
}
.btn-counter-sale:hover { background: var(--accent); color: #fff; transform: scale(1.08); }

/* ---------- Forms ---------- */
.form-label { font-weight: 600; font-size: 0.875rem; }
.form-control:focus, .form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 0.2rem rgba(230,57,70,0.15);
}

/* ---------- Login Page ---------- */
.login-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #0f0f1a 0%, #1a1a2e 50%, #16213e 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
    overflow: hidden;
}
.login-header {
    background: linear-gradient(135deg, var(--accent) 0%, #c1121f 100%);
    padding: 2.5rem 2rem 2rem;
    text-align: center;
    color: #fff;
}
.login-header .logo-icon {
    width: 70px;
    height: 70px;
    background: rgba(255,255,255,0.15);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    margin: 0 auto 1rem;
    border: 2px solid rgba(255,255,255,0.3);
}
.login-header h1 { font-size: 1.6rem; font-weight: 700; margin: 0; }
.login-header p  { opacity: 0.85; margin: 0.25rem 0 0; font-size: 0.9rem; }
.login-body { padding: 2rem; }

/* ---------- Repeating Rows (Parts/Labor) ---------- */
.repeating-row {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    position: relative;
}
.remove-row-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: none;
    border: none;
    color: #dc3545;
    cursor: pointer;
    font-size: 1rem;
    padding: 2px 6px;
    border-radius: 4px;
}
.remove-row-btn:hover { background: #fee2e2; }

/* ---------- Totals Box ---------- */
.totals-box {
    background: #1a1a2e;
    color: #fff;
    border-radius: 10px;
    padding: 1.2rem 1.5rem;
}
.totals-box .totals-row {
    display: flex;
    justify-content: space-between;
    padding: 0.3rem 0;
    font-size: 0.9rem;
}
.totals-box .totals-row.total-line {
    border-top: 1px solid rgba(255,255,255,0.2);
    margin-top: 0.5rem;
    padding-top: 0.75rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
}

/* ---------- Setup / Admin Misc ---------- */
.setup-page {
    min-height: 100vh;
    background: var(--body-bg);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 3rem 1rem;
}
.connection-status-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
}
.dot-green  { background: #16a34a; box-shadow: 0 0 6px #16a34a; }
.dot-red    { background: #dc3545; box-shadow: 0 0 6px #dc3545; }
.dot-grey   { background: #9ca3af; }

/* ---------- Hidden Rows (invoice visibility toggle) ---------- */
.row-hidden td { opacity: .45; }
.row-hidden td:first-child { text-decoration: line-through; }

/* ---------- Print Styles ---------- */
@media print {
    .sidebar-wrapper, .mobile-topbar, .btn, .no-print, #fchat-tray { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .card { box-shadow: none !important; border: 1px solid #ddd !important; }
    /* hide the interactive screen view when printing the report */
    .rpt-screen { display: none !important; }
}

/* ---------- Report Print Layout ---------- */
.rpt-print {
    font-family: Arial, sans-serif;
    font-size: 12px;
    color: #111;
}
.rpt-print-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 2px solid #111;
    padding-bottom: .5rem;
    margin-bottom: .75rem;
}
.rpt-print-title  { font-size: 20px; font-weight: 700; }
.rpt-print-period { font-size: 13px; color: #444; margin-top: 2px; }
.rpt-print-meta   { font-size: 11px; color: #666; }

.rpt-print-summary {
    display: flex;
    gap: .5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.rpt-sum-box {
    flex: 1;
    min-width: 100px;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: .35rem .5rem;
    text-align: center;
}
.rpt-sum-label { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: #666; }
.rpt-sum-val   { font-size: 15px; font-weight: 700; margin-top: 1px; }
.rpt-sum-pos   { border-color: #28a745; }
.rpt-sum-pos .rpt-sum-val { color: #28a745; }
.rpt-sum-neg   { border-color: #dc3545; }
.rpt-sum-neg .rpt-sum-val { color: #dc3545; }

.rpt-print-section-title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    border-bottom: 1px solid #111;
    margin: .9rem 0 .4rem;
    padding-bottom: 2px;
}
.rpt-print-group-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: #555;
    margin: .5rem 0 .2rem;
}
.rpt-print-empty { color: #777; font-style: italic; font-size: 11px; }

.rpt-print-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: .3rem;
    font-size: 11px;
}
.rpt-print-table thead th {
    background: #111;
    color: #fff;
    padding: 3px 6px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
    text-align: left;
}
.rpt-print-table thead th.text-end { text-align: right; }
.rpt-print-table td {
    padding: 3px 6px;
    border-bottom: 1px solid #eee;
    vertical-align: middle;
}
.rpt-print-table td.text-end  { text-align: right; }
.rpt-print-table td.text-nowrap { white-space: nowrap; }
.rpt-print-table tfoot td {
    border-top: 1.5px solid #111;
    font-weight: 700;
    padding: 3px 6px;
    background: #f0f0f0;
}
.rpt-print-table tfoot td.text-end { text-align: right; }

.rpt-print-exp-total {
    text-align: right;
    font-size: 11px;
    font-weight: 600;
    color: #333;
    margin-top: .25rem;
    margin-bottom: .5rem;
}

/* ---------- Invoice Print ---------- */
.invoice-print { font-family: Arial, sans-serif; font-size: 13px; color: #111; }
.inv-header { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 3px solid #111; padding-bottom: .75rem; margin-bottom: 1rem; page-break-inside: avoid; break-inside: avoid; }
.inv-logo { max-height: 70px; max-width: 190px; object-fit: contain; display: block; }
.inv-shop-name { font-size: 22px; font-weight: 700; letter-spacing: -.3px; }
.inv-shop-contact { font-size: 12px; color: #444; margin-top: 2px; }
.inv-title { font-size: 28px; font-weight: 800; text-align: right; letter-spacing: 2px; text-transform: uppercase; }
.inv-meta { display: flex; gap: .5rem; justify-content: flex-end; font-size: 13px; margin-top: 2px; }
.inv-meta-label { color: #666; }
.inv-meta-val { font-weight: 600; }
.inv-parties { display: flex; gap: 2rem; margin-bottom: 1rem; page-break-inside: avoid; break-inside: avoid; }
.inv-bill-to, .inv-vehicle { flex: 1; }
.inv-section-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: #666; border-bottom: 1px solid #ccc; padding-bottom: 2px; margin-bottom: 4px; break-after: avoid; page-break-after: avoid; }
.inv-customer-name { font-size: 15px; font-weight: 700; }
.inv-vin { font-size: 12px; color: #666; font-family: monospace; }
.inv-complaint { font-size: 13px; color: #333; margin-bottom: .75rem; padding: .4rem .5rem; background: #f8f8f8; border-left: 3px solid #ccc; page-break-inside: avoid; break-inside: avoid; }
.inv-table { width: 100%; border-collapse: collapse; margin-bottom: .5rem; font-size: 13px; }
.inv-table thead { display: table-header-group; }
.inv-table th { background: #111; color: #fff; padding: 5px 8px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.inv-table td { padding: 5px 8px; border-bottom: 1px solid #eee; }
.inv-table tr { page-break-inside: avoid; break-inside: avoid; }
.inv-table tfoot td { border-top: 2px solid #111; font-weight: 700; padding: 6px 8px; background: #f5f5f5; }
.inv-table tfoot { page-break-inside: avoid; break-inside: avoid; }
.inv-subtotal-row td { font-weight: 700; background: #f5f5f5 !important; }
.inv-totals { margin-left: auto; width: 310px; margin-top: .75rem; border: 1px solid #ccc; page-break-inside: avoid; break-inside: avoid; }
.inv-total-row { display: flex; justify-content: space-between; padding: 5px 10px; border-bottom: 1px solid #eee; font-size: 13px; }
.inv-subtotal { font-weight: 600; }
.inv-grand-total { font-size: 15px; font-weight: 800; background: #111; color: #fff; border: none; }
.inv-paid { color: #1a7a1a; }
.inv-balance-due { font-weight: 700; background: #fff3cd; }
.inv-balance-zero { font-weight: 700; background: #d4edda; color: #155724; }
.inv-notes-block { font-size: 12px; color: #333; }
.inv-note-item { padding: .3rem .5rem; border-left: 3px solid #ccc; margin-bottom: .4rem; background: #f8f8f8; page-break-inside: avoid; break-inside: avoid; }
.inv-footer { text-align: center; margin-top: 1.5rem; font-size: 13px; color: #666; border-top: 1px solid #ccc; padding-top: .5rem; page-break-inside: avoid; break-inside: avoid; }
.inv-disclaimers { margin-top: 1.5rem; border-top: 1px solid #ccc; padding-top: .75rem; font-size: 10px; color: #555; line-height: 1.5; page-break-inside: avoid; break-inside: avoid; }
.inv-disclaimers-title { font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; margin-bottom: .35rem; }
.inv-signature-block { margin-top: 2rem; page-break-inside: avoid; break-inside: avoid; }
.inv-sig-row { display: flex; gap: 3rem; }
.inv-sig-field { flex: 1; }
.inv-sig-line { border-bottom: 1px solid #333; height: 2rem; margin-bottom: .3rem; }
.inv-sig-label { font-size: 10px; color: #555; text-transform: uppercase; letter-spacing: .04em; }
/* ---------- Cover Page ---------- */
.cover-print { font-family: Arial, sans-serif; font-size: 16px; color: #111; }
.cover-parties { display: flex; gap: 2rem; margin: 1.25rem 0; }
.cover-section { flex: 1; }
.cover-name { font-size: 19px; font-weight: 700; margin-bottom: .25rem; }
.cover-vin { font-family: monospace; font-size: 1.35em; font-weight: 700; letter-spacing: .05em; margin-bottom: .4rem; }
.overview-vin-block { margin-bottom: .75rem; }
.overview-vin-label { font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted,#adb5bd); margin-bottom: .1rem; }
.overview-vin-value { font-family: monospace; font-size: 1.45em; font-weight: 800; letter-spacing: .06em; line-height: 1.1; }
.cover-sig-row { display: flex; gap: 2rem; margin-top: 3rem; }
.cover-sig-block { flex: 1; }
.cover-sig-line { border-bottom: 1px solid #111; margin-bottom: .35rem; height: 2rem; }
.cover-sig-label { font-size: 14px; color: #555; }
.cover-disclaimer { margin-top: 1.5rem; padding-top: .75rem; border-top: 1px solid #ccc; font-size: 13px; color: #555; line-height: 1.5; }

/* VIN display */
.vin-display { font-family: monospace; font-size: 1.05em; font-weight: 700; letter-spacing: .04em; }
.vin-prefix  { color: inherit; }
.vin-suffix  { color: var(--accent, #e67e22); }

@page {
    size: letter;
    margin: 0.55in 0.5in;
    @top-left   { content: none; }
    @top-center { content: none; }
    @top-right  { content: none; }
}
@media print {
    .invoice-print { display: block !important; zoom: 78%; }
    /* Tighten spacing so signature block stays on page 1 */
    .inv-header        { padding-bottom: .5rem; margin-bottom: .6rem; }
    .inv-parties       { margin-bottom: .6rem; }
    .inv-complaint     { margin-bottom: .5rem; padding: .3rem .5rem; }
    .inv-table         { margin-bottom: .3rem; }
    .inv-table th,
    .inv-table td      { padding: 4px 7px; }
    .inv-totals        { margin-top: .5rem; }
    .inv-total-row     { padding: 4px 9px; }
    .inv-footer        { margin-top: .8rem; padding-top: .35rem; }
    .inv-disclaimers   { margin-top: .8rem; padding-top: .5rem; }
    .inv-signature-block { margin-top: 1.2rem; }
}

/* ---------- Scrollbar (WebKit) ---------- */
.sidebar-wrapper::-webkit-scrollbar { width: 4px; }
.sidebar-wrapper::-webkit-scrollbar-track { background: transparent; }
.sidebar-wrapper::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }

/* ---------- Tab Filters ---------- */
.filter-tabs .nav-link {
    color: #555;
    border-radius: 20px;
    padding: 0.35rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
}
.filter-tabs .nav-link.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.filter-tabs .nav-link:hover:not(.active) {
    background: rgba(230,57,70,0.08);
    color: var(--accent);
}

/* ---------- Responsive tweaks ---------- */
@media (max-width: 575.98px) {
    .page-header h1 { font-size: 1.1rem; }
    .stat-card .stat-value { font-size: 1.4rem; }
}

/* ---------- Language switcher ---------- */
.lang-btn {
    color: rgba(255,255,255,0.5);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-decoration: none;
    padding: 2px 6px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}
.lang-btn:hover {
    color: #fff;
    background: rgba(255,255,255,0.1);
}
.lang-btn.lang-active {
    color: #fff;
    background: var(--accent);
}

/* ---------- WO Chat Widget (inline panel) ---------- */
.chat-panel {
    display: flex;
    flex-direction: column;
    min-height: 380px;
    height: 460px;
    overflow: hidden;
    background: #fff;
}
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 18px;
    background: #f4f6f9;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
}
/* Ensure bubbles render on desktop */
.chat-messages .d-flex { min-width: 0; width: 100%; }
.chat-bubble {
    max-width: min(78%, 520px);
    padding: 9px 13px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.45;
    word-break: break-word;
    position: relative;
}
.chat-bubble-mine {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
    margin-left: auto;
}
.chat-bubble-theirs {
    background: #ffffff;
    color: #1a1a2e;
    border-bottom-left-radius: 4px;
    border: 1px solid #e0e3e8;
    box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.chat-sender {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    margin-bottom: 4px;
    opacity: 0.75;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.chat-role-badge {
    font-size: 0.62rem;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: .04em;
    vertical-align: middle;
}
.chat-role-admin   { background: #1e2329; color: #fff; }
.chat-role-office  { background: #f4a261; color: #fff; }
.chat-role-tech    { background: #ffc107; color: #212529; }
.chat-time {
    font-size: 0.67rem;
    opacity: 0.55;
    margin-top: 5px;
    text-align: right;
}
.chat-bubble-theirs .chat-time { text-align: left; }
.chat-img {
    max-width: 240px;
    max-height: 200px;
    border-radius: 8px;
    cursor: zoom-in;
    display: block;
}
.chat-file-link {
    color: inherit;
    text-decoration: underline;
    font-size: 0.82rem;
    word-break: break-all;
}
.chat-bubble-mine .chat-file-link { color: rgba(255,255,255,0.9); }
.chat-compose {
    padding: 8px 10px;
    border-top: 1px solid rgba(0,0,0,0.1);
    background: #fff;
    display: flex;
    gap: 6px;
    align-items: flex-end;
    flex-shrink: 0;
}
.chat-compose textarea {
    flex: 1;
    resize: none;
    border: 1px solid #dee2e6;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 0.88rem;
    line-height: 1.4;
    min-height: 38px;
    max-height: 100px;
    overflow-y: auto;
    background: #f8f9fa;
}
.chat-compose textarea:focus { outline: none; border-color: var(--accent); background: #fff; box-shadow: 0 0 0 2px rgba(230,57,70,.12); }
.chat-attach-btn {
    background: none;
    border: 1px solid #dee2e6;
    border-radius: 20px;
    padding: 6px 10px;
    cursor: pointer;
    color: #6c757d;
    font-size: 0.88rem;
    white-space: nowrap;
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 0;
}
.chat-attach-btn:hover { border-color: var(--accent); color: var(--accent); }
.chat-paste-preview {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: #f0f4ff;
    border-top: 1px solid #d0d9f0;
    font-size: 0.82rem;
    color: #444;
    flex-shrink: 0;
}
.chat-paste-thumb {
    height: 48px;
    width: auto;
    max-width: 80px;
    border-radius: 4px;
    object-fit: cover;
    border: 1px solid #ccc;
}
.chat-paste-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-paste-clear {
    background: none;
    border: none;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    color: #888;
    padding: 0 2px;
    flex-shrink: 0;
}
.chat-paste-clear:hover { color: #dc3545; }
.chat-send-btn {
    background: var(--accent);
    border: none;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    color: #fff;
    cursor: pointer;
    font-size: 0.95rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
}
.chat-send-btn:hover   { background: var(--accent-hover); }
.chat-send-btn:disabled { opacity: 0.6; cursor: default; }
.chat-text { white-space: pre-wrap; }

/* Dashboard messages panel — grouped by WO */
.dash-msg-panel {
    max-height: 460px;
    overflow-y: auto;
}
.dash-msg-item {
    padding: 10px 14px;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    cursor: pointer;
    transition: background .1s;
    color: inherit;
}
.dash-msg-item:hover { background: rgba(230,57,70,.05); }
.dash-msg-wo {
    font-size: 0.78rem;
    color: var(--accent);
    font-weight: 700;
    text-decoration: none;
}
.dash-msg-sender { font-size: 0.8rem; font-weight: 600; color: #333; }
.dash-msg-body   { font-size: 0.83rem; color: #666; }
.dash-msg-time   { font-size: 0.7rem; color: #999; }
.dash-msg-count  { font-size: 0.68rem; }
.dash-wo-unread  { font-size: 0.68rem; }
.dash-msg-unread { background: rgba(230,57,70,.04); }
.dash-msg-unread .dash-msg-body { font-weight: 600; color: #212529; }
#active-table tr.wo-new-message td { background: rgba(25,135,84,.12) !important; }
#active-table tr.wo-new-message { border-left: 3px solid #198754 !important; }

/* ---------- Floating chat tray (admin — Messenger multi-pane style) ---------- */
#fchat-tray {
    position: fixed;
    bottom: 0;
    right: 0;
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    z-index: 1050;
    gap: 8px;
    padding: 0 12px;
    pointer-events: none;
}
#fchat-tray > * { pointer-events: all; }

/* Sidebar chat badge */
.sidebar-chat-badge {
    margin-left: auto;
    background: var(--accent);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 800;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    pointer-events: none;
}
#sidebar-chat-btn.fchat-sidebar-active {
    background: rgba(255,255,255,.08);
    color: var(--accent);
}

/* Contact list panel — anchored to sidebar bottom */
#fchat-list-panel {
    position: fixed;
    bottom: 0;
    left: var(--sidebar-width, 240px);
    width: 300px;
    height: 420px;
    background: #fff;
    border-radius: 0 10px 0 0;
    box-shadow: 4px -2px 20px rgba(0,0,0,.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
    z-index: 1051;
    animation: fchat-panel-in .15s ease;
}
@keyframes fchat-panel-in {
    from { opacity: 0; transform: translateX(-10px); }
    to   { opacity: 1; transform: translateX(0); }
}
#fchat-list-header {
    background: #1e2329;
    color: #fff;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    font-weight: 700;
    font-size: 0.9rem;
}
#fchat-list-close {
    background: none;
    border: none;
    color: rgba(255,255,255,.7);
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
}
#fchat-list-close:hover { color: #fff; }
#fchat-wo-list-body {
    flex: 1;
    overflow-y: auto;
}
.fchat-wo-list-inner { padding: 4px 0; }
.fchat-wo-item {
    padding: 9px 14px;
    cursor: pointer;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    border-bottom: 1px solid rgba(0,0,0,.05);
    font-size: 0.86rem;
    transition: background .1s;
}
.fchat-wo-item:hover { background: rgba(230,57,70,.06); }
.fchat-wo-item.fchat-win-open { background: rgba(230,57,70,.04); }
.fchat-wo-info { flex: 1; min-width: 0; }
.fchat-wo-num { display: block; font-weight: 700; color: var(--accent); }
.fchat-wo-vehicle { font-size: 0.78rem; color: #555; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fchat-wo-owner { font-size: 0.75rem; color: #888; }

/* Individual chat windows */
.fchat-window {
    width: 300px;
    height: 420px;
    background: #fff;
    border-radius: 10px 10px 0 0;
    box-shadow: 0 -2px 20px rgba(0,0,0,.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
    animation: fchat-panel-in .15s ease;
}
.fchat-window.fchat-minimized { height: auto; }
.fchat-win-header {
    background: #1e2329;
    color: #fff;
    padding: 9px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    cursor: pointer;
    user-select: none;
    gap: 6px;
}
.fchat-win-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}
.fchat-win-wo-num {
    display: block;
    font-size: 0.82rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.fchat-win-wo-num a { color: #fff; text-decoration: none; }
.fchat-win-wo-num a:hover { text-decoration: underline; }
.fchat-win-vehicle {
    display: block;
    font-size: 0.72rem;
    color: rgba(255,255,255,.6);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.fchat-win-btns { display: flex; gap: 2px; flex-shrink: 0; }
.fchat-win-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,.7);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    padding: 2px 5px;
    border-radius: 4px;
    transition: background .1s, color .1s;
}
.fchat-win-btn:hover { background: rgba(255,255,255,.15); color: #fff; }
.fchat-win-unread-badge {
    background: var(--accent);
    color: #fff;
    font-size: 0.62rem;
    font-weight: 800;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    margin-left: 4px;
    flex-shrink: 0;
}
.fchat-win-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}
.fchat-window.fchat-minimized .fchat-win-body { display: none; }
.fchat-win-messages {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    background: #f4f6f9;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
}
.fchat-win-messages .d-flex { min-width: 0; width: 100%; }
.fchat-win-compose {
    display: flex;
    align-items: flex-end;
    gap: 5px;
    padding: 6px 7px;
    border-top: 1px solid rgba(0,0,0,.08);
    background: #fff;
    flex-shrink: 0;
}
.fchat-win-input {
    flex: 1;
    resize: none;
    border: 1px solid #dee2e6;
    border-radius: 16px;
    padding: 6px 11px;
    font-size: 0.83rem;
    line-height: 1.4;
    min-height: 32px;
    max-height: 76px;
    overflow-y: auto;
    background: #f8f9fa;
    font-family: inherit;
}
.fchat-win-input:focus { outline: none; border-color: var(--accent); background: #fff; }
.fchat-win-send {
    background: var(--accent);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    color: #fff;
    cursor: pointer;
    font-size: 0.82rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
}
.fchat-win-send:disabled { opacity: 0.6; cursor: default; }
.fchat-win-send:not(:disabled):hover { background: var(--accent-hover); }
.fchat-attach-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #6c757d;
    font-size: 0.95rem;
    padding: 4px;
    flex-shrink: 0;
}
.fchat-attach-btn:hover { color: var(--accent); }

/* Mobile: stack vertically */
@media (max-width: 600px) {
    #fchat-tray {
        flex-direction: column-reverse;
        align-items: flex-end;
        padding: 0 8px;
        gap: 0;
    }
    #fchat-list-panel {
        left: 0;
        width: calc(100vw - 16px);
        height: 380px;
        border-radius: 10px 10px 0 0;
    }
    .fchat-window {
        width: calc(100vw - 16px);
        height: 380px;
    }
}

/* ---------- In-app message toast notifications ---------- */
#msg-toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}
.msg-toast {
    pointer-events: all;
    min-width: 280px;
    max-width: 340px;
    background: #1e2329;
    color: #f0f0f0;
    border-radius: 10px;
    padding: 0.75rem 1rem;
    box-shadow: 0 4px 18px rgba(0,0,0,.35);
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    opacity: 0;
    transform: translateY(-12px);
    transition: opacity .22s ease, transform .22s ease;
}
.msg-toast.show {
    opacity: 1;
    transform: translateY(0);
}
.msg-toast-icon {
    font-size: 1.1rem;
    color: var(--accent);
    flex-shrink: 0;
    margin-top: 2px;
}
.msg-toast-body {
    flex: 1;
    min-width: 0;
}
.msg-toast-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: 1px;
}
.msg-toast-text {
    font-size: 0.88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.msg-toast-wo {
    font-size: 0.75rem;
    color: var(--accent);
    margin-top: 3px;
    font-weight: 600;
}
.msg-toast-actions {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex-shrink: 0;
}
.msg-toast-actions a,
.msg-toast-actions button {
    font-size: 0.75rem;
    border: none;
    border-radius: 5px;
    padding: 2px 8px;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
}
.msg-toast-actions .btn-view {
    background: var(--accent);
    color: #fff;
}
.msg-toast-actions .btn-dismiss {
    background: rgba(255,255,255,.12);
    color: #ccc;
}
.msg-toast-actions .btn-dismiss:hover {
    background: rgba(255,255,255,.2);
}

/* ---------- Intake photo drop zone ---------- */
.intake-drop-zone {
    border: 2px dashed var(--border);
    border-radius: 10px;
    padding: 1.5rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: border-color .2s, background .2s;
}
.intake-drop-zone:hover,
.intake-drop-zone.drag-over {
    border-color: var(--accent);
    background: rgba(220, 53, 69, .05);
}
.intake-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: .5rem;
}
.intake-thumb {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    background: var(--surface-2);
}
.intake-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.intake-thumb-remove {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(0,0,0,.65);
    color: #fff;
    border: none;
    font-size: .8rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
