/* ═══════════════════════════════════════════════════════
   PlumbPro Dispatch - Main Stylesheet
   ═══════════════════════════════════════════════════════ */

:root {
    --sidebar-width: 240px;
    --topbar-height: 60px;
    --bg-dark: #0f1923;
    --bg-sidebar: #131f2e;
    --bg-card: #ffffff;
    --accent-blue: #1a6fc4;
    --accent-blue-light: #2d8de8;
    --accent-red: #dc3545;
    --accent-orange: #fd7e14;
    --accent-green: #198754;
    --accent-purple: #6f42c1;
    --text-primary: #1a2433;
    --text-muted: #6c7a8d;
    --border-color: #e2e8f0;
    --hover-bg: #f0f6ff;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,.10);
    --shadow-lg: 0 8px 24px rgba(0,0,0,.12);
    --radius: 10px;
    --radius-sm: 6px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #f0f4f9;
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
}

/* ─── Sidebar pre-collapsed (applied via <head> script before first paint) ── */
/* Mirrors .sidebar.collapsed + .main-wrapper.sidebar-collapsed but with       */
/* transition:none so the page is rendered directly in the collapsed state.     */
html.sidebar-pre-collapsed .sidebar {
    width: 64px !important;
    overflow: visible !important;
    transition: none !important;
}
html.sidebar-pre-collapsed .sidebar .logo-text,
html.sidebar-pre-collapsed .sidebar .menu-label,
html.sidebar-pre-collapsed .sidebar .menu-item span,
html.sidebar-pre-collapsed .sidebar .sidebar-footer { display: none !important; }
html.sidebar-pre-collapsed .sidebar .menu-item {
    justify-content: center !important;
    padding: 10px !important;
}
html.sidebar-pre-collapsed .sidebar .menu-item i { width: auto !important; margin: 0 !important; }
html.sidebar-pre-collapsed .main-wrapper {
    margin-left: 64px !important;
    width: calc(100vw - 64px) !important;
    max-width: calc(100vw - 64px) !important;
    transition: none !important;
}

/* ─── Sidebar ─────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    min-height: 100vh;
    position: fixed;
    left: 0; top: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: width 0.25s ease, transform 0.25s ease;
    overflow: hidden;
}

.sidebar.collapsed { width: 64px; }

.sidebar-header {
    padding: 20px 16px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
}

.logo-icon {
    width: 38px; height: 38px;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-blue-light));
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 16px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(26,111,196,0.4);
}

.logo-text { overflow: hidden; }
.logo-title {
    display: block;
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    white-space: nowrap;
    line-height: 1.2;
}
.logo-sub {
    display: block;
    color: rgba(255,255,255,0.4);
    font-size: 10px;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sidebar.collapsed .logo-text,
.sidebar.collapsed .menu-label,
.sidebar.collapsed .menu-item span,
.sidebar.collapsed .sidebar-footer { display: none; }

.sidebar-menu {
    flex: 1;
    padding: 16px 10px;
    overflow-y: auto;
    overflow-anchor: none; /* prevent CSS scroll anchoring from shifting position */
}

.menu-label {
    color: rgba(255,255,255,0.3);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 4px 10px 8px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    color: rgba(255,255,255,0.6);
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s;
    margin-bottom: 2px;
    white-space: nowrap;
    scroll-margin: 0; /* prevent the browser adding margin when scrolling this into view */
}

.menu-item i { width: 18px; text-align: center; flex-shrink: 0; font-size: 15px; }

.menu-item:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

.menu-item.active {
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-blue-light));
    color: #fff;
    box-shadow: 0 2px 8px rgba(26,111,196,0.3);
}

.menu-item.new-job-btn {
    background: rgba(26,111,196,0.15);
    color: var(--accent-blue-light);
    border: 1px solid rgba(26,111,196,0.2);
}
.menu-item.new-job-btn:hover { background: var(--accent-blue); color: #fff; }

.menu-item.emergency-btn {
    background: rgba(220,53,69,0.12);
    color: #ff6b7a;
    border: 1px solid rgba(220,53,69,0.2);
}
.menu-item.emergency-btn:hover { background: var(--accent-red); color: #fff; }

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid rgba(255,255,255,0.06);
}
.version-info { color: rgba(255,255,255,0.25); font-size: 11px; }
.tech-url-block {
    background: rgba(255,255,255,0.06);
    border-radius: 8px;
    padding: 8px 10px;
    margin-bottom: 10px;
}
.tech-url-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: rgba(255,255,255,0.4);
    margin-bottom: 4px;
}
.tech-url-value {
    font-size: 11px;
    color: rgba(255,255,255,0.8);
    word-break: break-all;
    font-family: 'Consolas', 'Courier New', monospace;
    user-select: all;
    cursor: text;
}

/* ─── Pre-init guard ──────────────────────────────────── */
/* Keeps main-wrapper invisible until JS finishes (clock, Tom Select).
   Set by <head> script before first paint; removed after all init runs.
   Safety fallback: auto-reveals after 1.5 s if scripts are unexpectedly slow. */
html.pre-init .main-wrapper {
    opacity: 0;
    animation: pre-init-reveal 0.01s 1.5s forwards;
}
@keyframes pre-init-reveal { to { opacity: 1; } }

/* ─── Main Layout ─────────────────────────────────────── */
.main-wrapper {
    margin-left: var(--sidebar-width);
    /* Cap width so the flex-column children can never push past the viewport */
    width: calc(100vw - var(--sidebar-width));
    max-width: calc(100vw - var(--sidebar-width));
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.25s ease, width 0.25s ease, max-width 0.25s ease;
}

.main-wrapper.sidebar-collapsed {
    margin-left: 64px;
    width: calc(100vw - 64px);
    max-width: calc(100vw - 64px);
}

/* ─── Topbar ──────────────────────────────────────────── */
.topbar {
    height: var(--topbar-height);
    background: #fff;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.topbar-left { display: flex; align-items: center; gap: 16px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.sidebar-toggle {
    background: none; border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
}
.sidebar-toggle:hover { background: var(--hover-bg); color: var(--text-primary); }

.breadcrumb-nav { color: var(--text-primary); font-size: 16px; font-weight: 600; }
.breadcrumb-item-custom { color: var(--text-muted); font-size: 14px; }

.topbar-date {
    color: var(--text-muted);
    font-size: 14px;
    padding: 4px 10px;
    background: #f8fafc;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    /* Reserve space so adding clock text never shifts neighboring flex items */
    min-width: 155px;
    text-align: center;
}

/* ─── User Pill (topbar) ──────────────────────────────── */
.user-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #f0f4f8;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 5px 10px 5px 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}
.user-pill-signout {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px; height: 24px;
    border-radius: 50%;
    background: #e2e8f0;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 12px;
    transition: background 0.15s, color 0.15s;
    margin-left: 2px;
}
.user-pill-signout:hover { background: #fee2e2; color: #dc3545; }

/* ─── Live Indicator ──────────────────────────────────── */
.live-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}
.live-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #22c55e;
    animation: live-pulse 2.4s ease-in-out infinite;
    flex-shrink: 0;
}
@keyframes live-pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(34,197,94,.5); }
    50%       { opacity: 0.6; box-shadow: 0 0 0 4px rgba(34,197,94,0); }
}

/* Flash a stat card when its value changes via live poll */
.stat-live-flash {
    animation: stat-flash 0.8s ease-out;
}
@keyframes stat-flash {
    0%   { box-shadow: 0 0 0 3px rgba(34,197,94,.7); }
    100% { box-shadow: none; }
}

/* Briefly highlight a jobs-table row when any badge changes via live poll */
.row-live-updated {
    animation: row-flash 2s ease-out;
}
@keyframes row-flash {
    0%   { background: rgba(34,197,94,.15); }
    100% { background: transparent; }
}

/* ─── Trial Banner ────────────────────────────────────── */
.trial-banner {
    background: #fffbeb;
    border-bottom: 1px solid #fde68a;
    color: #78350f;
    font-size: 12px;
    padding: 5px 24px;
    text-align: center;
}

/* ─── Flash Messages ──────────────────────────────────── */
.flash-container {
    padding: 12px 24px 0;
}
.flash-alert {
    border-radius: var(--radius-sm);
    font-size: 14px;
}

/* ─── Page Content ────────────────────────────────────── */
.page-content {
    padding: 24px;
    flex: 1;
}

/* ─── Cards ───────────────────────────────────────────── */
.card {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: 15px;
}

/* ─── Stat Cards ──────────────────────────────────────── */
.stat-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 20px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s, box-shadow 0.15s;
    position: relative;
    overflow: hidden;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.stat-card-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.stat-card-value {
    font-size: 32px;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 4px;
}
.stat-card-label { color: var(--text-muted); font-size: 14px; }

.stat-blue .stat-card-icon { background: #dbeafe; color: var(--accent-blue); }
.stat-blue .stat-card-value { color: var(--accent-blue); }

.stat-orange .stat-card-icon { background: #ffedd5; color: var(--accent-orange); }
.stat-orange .stat-card-value { color: var(--accent-orange); }

.stat-green .stat-card-icon { background: #dcfce7; color: var(--accent-green); }
.stat-green .stat-card-value { color: var(--accent-green); }

.stat-red .stat-card-icon { background: #fee2e2; color: var(--accent-red); }
.stat-red .stat-card-value { color: var(--accent-red); }

.stat-purple .stat-card-icon { background: #ede9fe; color: var(--accent-purple); }
.stat-purple .stat-card-value { color: var(--accent-purple); }

.stat-gray .stat-card-icon { background: #f1f5f9; color: var(--text-muted); }
.stat-gray .stat-card-value { color: var(--text-primary); }

/* ─── Status Badges ───────────────────────────────────── */
.badge-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-pending { background: #fef3c7; color: #92400e; }
.badge-in_progress { background: #dbeafe; color: #1e40af; }
.badge-completed { background: #dcfce7; color: #166534; }
.badge-invoiced { background: #ede9fe; color: #5b21b6; }

.badge-priority-low { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.badge-priority-normal { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.badge-priority-urgent { background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; }
.badge-priority-emergency { background: #dc3545; color: #fff; border: 1px solid #b91c2c; animation: pulse-emergency 1.5s ease-in-out infinite; }

.badge-type { background: #f1f5f9; color: #475569; }

.emergency-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #dc3545;
    color: #fff;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    animation: pulse-emergency 1.5s ease-in-out infinite;
}

@keyframes pulse-emergency {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.75; }
}

/* ─── Job Cards ───────────────────────────────────────── */
.job-card {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 10px;
    transition: all 0.15s;
    position: relative;
}
.job-card:hover { box-shadow: var(--shadow-md); transform: translateX(2px); }
.job-card.is-emergency { border-left: 4px solid var(--accent-red); }
.job-card.priority-urgent { border-left: 4px solid var(--accent-orange); }

.job-card-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    text-decoration: none;
    display: block;
    margin-bottom: 6px;
}
.job-card-title:hover { color: var(--accent-blue); }

.job-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

/* ─── Table ───────────────────────────────────────────── */
.jobs-table {
    width: 100%;
    border-collapse: collapse;
}
.jobs-table th {
    background: #f8fafc;
    padding: 10px 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}
.jobs-table td {
    padding: 10px 10px;
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
    vertical-align: middle;
}
.jobs-table tr:hover td { background: var(--hover-bg); }
.jobs-table tr:last-child td { border-bottom: none; }
.jobs-table .emergency-row td { background: #fff5f5; }

/* ─── Forms ───────────────────────────────────────────── */
.form-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}
.form-control, .form-select {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 14px;
    padding: 9px 12px;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus, .form-select:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(26,111,196,0.12);
    outline: none;
}
.form-section {
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}
.form-section-title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ─── Buttons ─────────────────────────────────────────── */
.btn { border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; }
.btn-primary { background: var(--accent-blue); border-color: var(--accent-blue); }
.btn-primary:hover { background: #1558a0; border-color: #1558a0; }

/* ─── Calendar ────────────────────────────────────────── */
.calendar-container {
    background: #fff;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    padding: 20px;
}

.fc .fc-toolbar-title { font-size: 18px; font-weight: 700; color: var(--text-primary); }
.fc .fc-button-primary {
    background: var(--accent-blue) !important;
    border-color: var(--accent-blue) !important;
    border-radius: var(--radius-sm) !important;
    font-size: 13px !important;
    font-weight: 500 !important;
}
.fc .fc-button-primary:hover {
    background: #1558a0 !important;
    border-color: #1558a0 !important;
}
.fc .fc-button-primary:not(:disabled):active,
.fc .fc-button-primary:not(:disabled).fc-button-active {
    background: #1558a0 !important;
}

.fc-event {
    border-radius: 5px !important;
    border: none !important;
    padding: 2px 6px !important;
    font-size: 12px !important;
    font-weight: 500 !important;
    cursor: pointer !important;
}

.fc-daygrid-event-dot { display: none !important; }

.fc th { color: var(--text-muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.fc .fc-col-header-cell-cushion { padding: 10px 4px; color: var(--text-muted); }
.fc .fc-daygrid-day-number { color: var(--text-primary); font-weight: 500; }
.fc .fc-day-today { background: rgba(26,111,196,0.04) !important; }
.fc .fc-day-today .fc-daygrid-day-number {
    background: var(--accent-blue);
    color: #fff;
    border-radius: 50%;
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
}

/* Calendar filter bar */
.cal-filters {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.tech-filter-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.15s;
}
.tech-filter-btn.active { border-color: currentColor; }

/* ─── Tooltip-style popup on calendar ─────────────────── */
.fc-event-popup {
    position: fixed;
    background: #1a2433;
    color: #fff;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    max-width: 260px;
    z-index: 9999;
    box-shadow: var(--shadow-lg);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
}
.fc-event-popup.visible { opacity: 1; }
.fc-event-popup .popup-title { font-weight: 700; font-size: 14px; margin-bottom: 8px; }
.fc-event-popup .popup-row { display: flex; gap: 6px; margin-bottom: 4px; color: rgba(255,255,255,0.75); }
.fc-event-popup .popup-row i { width: 14px; color: rgba(255,255,255,0.5); }

/* ─── Tech Color Dots ─────────────────────────────────── */
.tech-dot {
    display: inline-block;
    width: 10px; height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ─── Customer / Tech Cards ───────────────────────────── */
.person-card {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    transition: all 0.15s;
}
.person-card:hover { box-shadow: var(--shadow-md); }

.person-avatar {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

/* ─── Search / Filter Bar ─────────────────────────────── */
.filter-bar {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 16px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: flex-end;
}
.filter-bar .form-control,
.filter-bar .form-select { min-width: 120px; }

/* ─── Attachment List ─────────────────────────────────── */
.attachment-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}
.attachment-icon {
    width: 36px; height: 36px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}
.attachment-icon.img-type { background: #dbeafe; color: var(--accent-blue); }
.attachment-icon.pdf-type { background: #fee2e2; color: var(--accent-red); }
.attachment-icon.doc-type { background: #ede9fe; color: var(--accent-purple); }
.attachment-icon.other-type { background: #f1f5f9; color: var(--text-muted); }

/* ─── Notes ───────────────────────────────────────────── */
.note-item {
    padding: 12px 16px;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}
.note-date { font-size: 11px; color: #92400e; margin-top: 6px; }

/* ─── Page Headers ────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}
.page-header h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}
.page-header .page-subtitle {
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ─── Job Detail ──────────────────────────────────────── */
.detail-section {
    margin-bottom: 20px;
}
.detail-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.detail-value {
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 500;
}

.status-selector .btn-check + .btn {
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    padding: 6px 14px;
}

/* ─── Responsive ──────────────────────────────────────── */
@media (max-width: 768px) {
    /* Sidebar: off-screen, overlay when open */
    .sidebar { transform: translateX(-100%); position: fixed; z-index: 1050; height: 100vh; }
    .sidebar.mobile-open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,.3); }
    .main-wrapper,
    .main-wrapper.sidebar-collapsed {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    /* Override pre-collapsed desktop state on mobile */
    html.sidebar-pre-collapsed .main-wrapper {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    html.sidebar-pre-collapsed .sidebar {
        width: var(--sidebar-width) !important;
        transform: translateX(-100%);
    }

    /* Mobile overlay backdrop */
    .sidebar-backdrop {
        position: fixed; inset: 0; background: rgba(0,0,0,.4);
        z-index: 1040; display: none;
    }
    .sidebar-backdrop.show { display: block; }

    /* Topbar: compact for mobile */
    .topbar { padding: 0 12px; gap: 8px; height: 50px; flex-wrap: nowrap; }
    .topbar-left { gap: 8px; min-width: 0; }
    .topbar-right { gap: 6px; flex-shrink: 0; }
    .topbar-date { display: none; }
    .live-indicator { display: none; }
    .breadcrumb-nav { font-size: 14px; }
    .topbar-right .btn { font-size: 14px; padding: 6px 10px; }
    .topbar-right .btn-label { display: none; }
    .user-pill { font-size: 12px; padding: 4px 8px; }
    .user-pill span { max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

    /* Page content */
    .page-content { padding: 12px; }
    .page-header { flex-direction: column; gap: 8px; }
    .page-header h1 { font-size: 20px; }

    /* Stat cards: 2 per row, compact */
    .stat-card { padding: 12px; }
    .stat-card-value { font-size: 22px; }
    .stat-card-label { font-size: 11px; }
    .stat-card-icon { font-size: 16px; width: 32px; height: 32px; }

    /* Cards */
    .card-header { flex-direction: column; align-items: flex-start !important; gap: 8px; padding: 12px; }
    .card-body { padding: 12px !important; }

    /* Tables: horizontal scroll */
    .table-responsive, .card-body { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .jobs-table, table { min-width: 500px; }
    .jobs-table th, .jobs-table td, table th, table td { padding: 8px 10px; font-size: 13px; white-space: nowrap; }

    /* Prevent any child from blowing out the viewport */
    .page-content, .card { max-width: 100%; overflow-x: hidden; }
    .card-body { overflow-x: auto; max-width: 100%; }

    /* Filter bars */
    .filter-bar { flex-direction: column; gap: 8px; padding: 12px !important; }
    .filter-bar .form-control,
    .filter-bar .form-select,
    .filter-bar .ts-wrapper,
    .filter-bar input,
    .filter-bar select { width: 100% !important; min-width: 0 !important; max-width: 100% !important; }
    .filter-bar .btn { width: 100%; }

    /* Override all inline min-width on form elements */
    .page-content input[style*="min-width"],
    .page-content select[style*="min-width"],
    .page-content .form-control[style*="min-width"],
    .page-content .form-select[style*="min-width"] { min-width: 0 !important; width: 100% !important; }

    /* Job cards */
    .job-card { padding: 10px; }
    .job-card-meta { flex-direction: column; gap: 2px; }

    /* Modals */
    .modal-dialog { margin: 8px; max-width: calc(100vw - 16px); }
    .modal-body { padding: 12px; }

    /* Force larger breakpoint columns to full-width, but respect col-6 for stat cards */
    .row.g-3 > [class*="col-xl"]:not([class*="col-6"]),
    .row.g-3 > [class*="col-lg"]:not([class*="col-6"]) { flex: 0 0 100%; max-width: 100%; }

    /* Onboarding */
    .onboarding-item { font-size: 13px; }

    /* Notification items */
    .notification-item { font-size: 13px; padding: 8px 10px; }

    /* Trial banner compact */
    .trial-banner { font-size: 13px; padding: 8px 12px; }
}

/* ─── Custom scrollbar ────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c8d3e0; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #aab5c4; }

/* ─── Misc Utilities ──────────────────────────────────── */
.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.cursor-pointer { cursor: pointer; }
.border-left-4 { border-left: 4px solid; }

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.empty-state i { font-size: 48px; margin-bottom: 16px; opacity: 0.3; }
.empty-state p { font-size: 15px; }

/* ─── Tom Select ──────────────────────────────────────── */
/* Hide native <select> until Tom Select wraps it — prevents layout-shift flinch on page load */
select:not(.ts-hidden-accessible) { visibility: hidden; }
/* Tom Select keeps the original <select> as a hidden accessible element with
   position:absolute. When it gets focused (on every selection) the browser fires
   scrollIntoView(), which in PyQt6 Chromium incorrectly scrolls the sidebar's
   overflow-y:auto container. position:fixed removes it from the document flow
   entirely so scrollIntoView() becomes a no-op. */
.ts-hidden-accessible {
    position: fixed !important;
    top: -9999px !important;
    left: -9999px !important;
}
/* Hide native date/time inputs until Flatpickr initialises them — prevents mm/dd/yyyy flash */
input[type="date"]:not(.flatpickr-input),
input[type="datetime-local"]:not(.flatpickr-input),
input[type="time"]:not(.flatpickr-input) { visibility: hidden; }
/* Kill all Tom Select animations/transitions — prevents the pop-in flinch on page load */
.ts-wrapper, .ts-control { animation: none !important; transition: none !important; }
/* Constrain dropdown width to wrapper — prevents sideways expansion */
.ts-wrapper { position: relative; }
.ts-dropdown .option { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Kill the open animation so the popup appears instantly in PyQt6 Chromium */
.ts-dropdown { animation: none !important; transition: none !important; width: 100% !important; min-width: 0 !important; }
/* Hide the inline search input when idle so the control doesn't grow */
.ts-wrapper .ts-control > input { width: 0 !important; min-width: 0 !important; opacity: 0; position: absolute; color: var(--text-primary); }
/* When focused/open: reveal the search input so typed text is visible */
.ts-wrapper.focus .ts-control > input {
    opacity: 1 !important; position: relative !important;
    width: auto !important; min-width: 4px !important;
}
/* Fade the selected item while actively typing so it doesn't visually clash */
.ts-wrapper.single.focus .ts-control .item { opacity: 0.35; }
/* Ensure selected text doesn't run under the caret arrow */
.ts-wrapper.single .ts-control { padding-right: 2.5rem !important; overflow: hidden; }
.ts-wrapper.single .ts-control .item { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
/* Match app font and sizing */
.ts-wrapper .ts-control,
.ts-dropdown { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; font-size: 13px; }
/* Option hover/active — use app hover colour instead of Bootstrap blue */
.ts-dropdown .option:hover,
.ts-dropdown .option.active { background: var(--hover-bg) !important; color: var(--text-primary) !important; }
/* Selected option highlight */
.ts-dropdown .option.selected { background: #e8f0fb !important; color: var(--text-primary) !important; }

/* ─── Dropdown fixes ──────────────────────────────────── */
/* Kill the slide/fade/scale animation entirely — prevents the white-square
   expansion artifact seen in PyQt6 Chromium. */
.dropdown-menu,
.dropdown-menu.show,
.dropdown-menu.fade,
.dropdown-menu.collapsing {
    animation: none !important;
    transition: none !important;
    transform: none !important;
    /* Ensure the menu is either fully opaque or hidden — no in-between states */
    opacity: 1 !important;
    /* Remove any Bootstrap clip-path trick */
    clip-path: none !important;
}
/* Bootstrap 5 uses .show on the menu to reveal it; we handle visibility
   purely through display so there is never a partially-rendered frame. */
.dropdown-item { transition: none; }
.dropdown-item:hover, .dropdown-item:focus {
    background-color: var(--hover-bg) !important;
    color: var(--text-primary) !important;
}
.dropdown-item:active {
    background-color: var(--accent-blue) !important;
    color: #fff !important;
}

/* Allow dropdown menus to escape table-responsive overflow clipping */
.table-responsive:has(.dropdown-menu.show) { overflow: visible; }

/* ─── Sortable column headers ─────────────────────────── */
th[data-sortable] {
    cursor: pointer;
    user-select: none;
    position: relative;
}
th[data-sortable]:hover { background: #edf2f7; color: var(--text-primary); }
th[data-sortable]::after { content: ' ⇅'; font-size: 10px; opacity: 0.35; }
th[data-sortable].sort-asc::after  { content: ' ▲'; opacity: 1; color: var(--accent-blue); }
th[data-sortable].sort-desc::after { content: ' ▼'; opacity: 1; color: var(--accent-blue); }

/* ─── Table row hover (smooth transition) ─────────────── */
.jobs-table tbody tr { transition: background-color 0.12s ease; }
.jobs-table tr:hover td { background: var(--hover-bg); cursor: default; }
.jobs-table .emergency-row td { background: #fff5f5; }
.jobs-table .emergency-row:hover td { background: #fee2e2; }

/* ─── Stat card links (no underline, keep colors) ─────── */
a.stat-card-link {
    text-decoration: none;
    display: block;
    color: inherit;
}
a.stat-card-link .stat-card { cursor: pointer; }

/* ─── Sidebar collapsed: center icons, add tooltips ──────*/
.sidebar.collapsed .menu-item {
    justify-content: center;
    padding: 10px;
    position: relative;
}
.sidebar.collapsed .menu-item i { width: auto; margin: 0; }

/* Tooltip label that floats to the right of the icon */
.sidebar.collapsed .menu-item::after {
    content: attr(data-label);
    position: fixed;
    left: 72px;
    background: #1a2433;
    color: #fff;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    z-index: 2000;
    box-shadow: var(--shadow-md);
    transition: opacity 0.12s;
}
.sidebar.collapsed .menu-item:hover::after { opacity: 1; }

/* Make the sidebar itself not clip the floating tooltips */
.sidebar.collapsed { overflow: visible; }

/* ─── Invoice status badges ───────────────────────────── */
.badge-inv-draft    { background: #f1f5f9; color: #475569; }
.badge-inv-sent     { background: #dbeafe; color: #1e40af; }
.badge-inv-paid     { background: #dcfce7; color: #166534; }
.badge-inv-overdue  { background: #fee2e2; color: #991b1b; }

/* ─── Invoice document layout ─────────────────────────── */
.invoice-doc {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 48px 52px;
    box-shadow: var(--shadow-sm);
    max-width: 820px;
    margin: 0 auto;
}
.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding-bottom: 24px;
    border-bottom: 2px solid var(--border-color);
}
.inv-company-name { font-size: 22px; font-weight: 800; color: var(--text-primary); margin-bottom: 4px; }
.inv-company-detail { font-size: 13px; color: var(--text-muted); }
.inv-doc-type { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.5px; color: var(--accent-blue); margin-bottom: 4px; }
.inv-number { font-size: 24px; font-weight: 800; color: var(--text-primary); }
.inv-meta { font-size: 13px; color: var(--text-muted); }
.inv-section-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); margin-bottom: 6px; }
.inv-table-wrap { margin-top: 28px; border: 1px solid var(--border-color); border-radius: var(--radius-sm); overflow: hidden; }
.inv-table { width: 100%; border-collapse: collapse; }
.inv-table th { background: #f8fafc; padding: 10px 14px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); border-bottom: 1px solid var(--border-color); }
.inv-table td { padding: 12px 14px; font-size: 13px; border-bottom: 1px solid #f1f5f9; }
.inv-table tr:last-child td { border-bottom: none; }
.inv-totals { display: flex; justify-content: flex-end; margin-top: 20px; }
.inv-totals table { font-size: 14px; min-width: 260px; }
.inv-totals td { padding: 5px 0 5px 32px; }
.inv-amount { text-align: right; font-weight: 600; }
.inv-total-row td { border-top: 2px solid var(--border-color); padding-top: 10px; font-size: 17px; font-weight: 800; color: var(--accent-blue); }
.inv-notes { margin-top: 28px; padding: 16px; background: #fffbeb; border-radius: var(--radius-sm); border: 1px solid #fde68a; }
.inv-footer { margin-top: 36px; padding-top: 16px; border-top: 1px solid var(--border-color); text-align: center; font-size: 13px; color: var(--text-muted); }

/* ─── Inventory stock indicators ──────────────────────── */
.stock-qty { display: inline-block; padding: 3px 8px; border-radius: 4px; font-size: 13px; font-weight: 600; }
.stock-ok  { background: #dcfce7; color: #166534; }
.stock-low { background: #fee2e2; color: #991b1b; }
.low-stock-row td { background: #fff5f5 !important; }

/* ─── Report tabs ─────────────────────────────────────── */
.report-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.report-tab {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 600;
    text-decoration: none;
    color: var(--text-muted);
    background: #fff;
    border: 1px solid var(--border-color);
    transition: all 0.15s;
}
.report-tab:hover { background: var(--hover-bg); color: var(--text-primary); }
.report-tab.active { background: var(--accent-blue); color: #fff; border-color: var(--accent-blue); }

/* ─── Notification items ──────────────────────────────── */
.notification-item {
    display: flex;
    align-items: flex-start;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
}
.notification-danger  { background: #fff5f5; color: #991b1b; border-left: 3px solid #ef4444; }
.notification-warning { background: #fffbeb; color: #92400e; border-left: 3px solid var(--accent-orange); }
.notification-info    { background: #f0f7ff; color: #1e40af; border-left: 3px solid var(--accent-blue); }

/* ─── Live autocomplete dropdown ─────────────────────── */
.ac-dropdown {
    display: none;
    position: absolute;
    left: 0; right: 0;
    top: calc(100% + 2px);
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    max-height: 220px;
    overflow-y: auto;
    z-index: 2000;
}
.ac-item {
    padding: 9px 14px;
    font-size: 13px;
    cursor: pointer;
    border-bottom: 1px solid #f1f5f9;
    color: var(--text-primary);
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover { background: var(--hover-bg); }
.ac-clear { color: var(--text-muted); font-style: italic; }
.ac-clear:hover { background: #f8fafc; }

/* ─── Avatar gradient ─────────────────────────────────── */
.avatar-gradient {
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-blue-light));
}

/* ─── Card section icons ──────────────────────────────── */
.card-icon {
    width: 36px; height: 36px;
    border-radius: 8px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}
.card-icon-blue   { background: #dbeafe; color: var(--accent-blue); }
.card-icon-green  { background: #dcfce7; color: var(--accent-green); }
.card-icon-orange { background: #ffedd5; color: var(--accent-orange); }
.card-icon-red    { background: #fee2e2; color: var(--accent-red); }
.card-icon-purple { background: #ede9fe; color: var(--accent-purple); }
.card-icon-gray   { background: #f1f5f9; color: var(--text-muted); }

/* ─── Contact rows ────────────────────────────────────── */
.contact-row {
    display: flex; align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-decoration: none;
}
.contact-row:hover { color: var(--text-primary); }
.contact-row i { width: 16px; text-align: center; flex-shrink: 0; }
.contact-row.contact-phone   i { color: var(--accent-green); }
.contact-row.contact-email   i { color: var(--accent-blue); }
.contact-row.contact-address i { color: var(--accent-red); }

/* ─── Upload zone ─────────────────────────────────────── */
.upload-zone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    padding: 24px 20px;
    text-align: center;
    background: #f8fafc;
    transition: border-color 0.15s, background 0.15s;
    cursor: pointer;
}
.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--accent-blue);
    background: #eff6ff;
}
.upload-zone i { font-size: 28px; color: var(--text-muted); margin-bottom: 8px; display: block; }

/* ─── Monospace text ──────────────────────────────────── */
.mono-text {
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 12px;
    color: var(--text-muted);
}

/* ─── Logo preview (settings) ─────────────────────────── */
.logo-preview {
    max-height: 56px; max-width: 150px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    object-fit: contain;
    background: #fff;
    padding: 4px;
}
.logo-placeholder {
    width: 56px; height: 56px;
    background: #f1f5f9;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted);
}

/* ─── Form help text ──────────────────────────────────── */
.form-help { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ─── Recommendation box (drain camera notes) ─────────── */
.recommendation-box {
    white-space: pre-wrap;
    background: #fffbeb;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent-orange);
    font-size: 13px;
    color: var(--text-primary);
}

/* ─── Table typography helpers ────────────────────────── */
.table-link {
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 14px;
}
.table-link:hover { color: var(--accent-blue); }
.table-sub { font-size: 11px; color: var(--text-muted); }

/* ─── Onboarding checklist (dashboard) ───────────────── */
.onboarding-item {
    display: flex; align-items: center; gap: 14px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s;
}
.onboarding-item.done    { background: #f0fdf4; color: #166534; }
.onboarding-item.done    .onboarding-icon { background: #dcfce7; color: var(--accent-green); }
.onboarding-item.pending { background: #f8fafc; color: var(--text-primary); }
.onboarding-item.pending .onboarding-icon { background: #f1f5f9; color: var(--text-muted); }
.onboarding-icon {
    width: 32px; height: 32px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; flex-shrink: 0;
}
.onboarding-item a { font-weight: 600; text-decoration: none; }
.onboarding-item.pending a { color: var(--accent-blue); }
.onboarding-item.done    a { color: #166534; }

/* ─── Payment modal ───────────────────────────────────── */
.pay-modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.45); z-index: 9999;
    align-items: center; justify-content: center;
}
.pay-modal-overlay.open { display: flex; }
.pay-modal-box {
    background: #fff;
    border-radius: 16px;
    width: 90%; max-width: 460px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}
.pay-modal-header {
    background: linear-gradient(135deg, var(--accent-green), #22c55e);
    color: #fff;
    padding: 20px 24px 16px;
}
.pay-modal-header h5 { font-size: 18px; font-weight: 700; margin: 0; }
.pay-modal-header p  { font-size: 13px; opacity: .85; margin: 4px 0 0; }
.pay-modal-body   { padding: 20px 24px; }
.pay-modal-footer { padding: 12px 24px 20px; display: flex; gap: 8px; justify-content: flex-end; }
.pay-amount-wrap { position: relative; margin-bottom: 16px; }
.pay-amount-prefix {
    position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    font-size: 18px; font-weight: 700; color: var(--text-muted);
    pointer-events: none;
}
.pay-amount-input {
    width: 100%; padding: 12px 12px 12px 28px;
    font-size: 24px; font-weight: 700; color: var(--text-primary);
    border: 2px solid var(--border-color); border-radius: var(--radius-sm);
    outline: none; transition: border-color .15s;
}
.pay-amount-input:focus { border-color: var(--accent-blue); }
.pay-method-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 16px; }
.pay-method-btn {
    padding: 10px 6px; border-radius: var(--radius-sm);
    border: 2px solid var(--border-color);
    background: #fff; cursor: pointer; text-align: center;
    font-size: 12px; font-weight: 600; color: var(--text-muted);
    transition: border-color .15s, color .15s, background .15s;
}
.pay-method-btn:hover   { border-color: var(--accent-blue); color: var(--accent-blue); background: #eff6ff; }
.pay-method-btn.selected{ border-color: var(--accent-blue); color: var(--accent-blue); background: #eff6ff; }
.pay-method-btn i { display: block; font-size: 20px; margin-bottom: 4px; }
.pay-link-box {
    background: #f8fafc; border: 1px solid var(--border-color);
    border-radius: var(--radius-sm); padding: 14px;
    font-size: 13px; margin-bottom: 14px;
}
.pay-link-box a { color: var(--accent-blue); font-weight: 600; text-decoration: none; }
.pay-link-box a:hover { text-decoration: underline; }

/* ─── Stat card top-accent borders ───────────────────── */
.stat-blue   { border-top: 3px solid var(--accent-blue); }
.stat-orange { border-top: 3px solid var(--accent-orange); }
.stat-green  { border-top: 3px solid var(--accent-green); }
.stat-red    { border-top: 3px solid var(--accent-red); }
.stat-purple { border-top: 3px solid var(--accent-purple); }
.stat-gray   { border-top: 3px solid var(--border-color); }

/* ─── Print styles (invoice) ──────────────────────────── */
@media print {
    @page { margin: 10mm 12mm; size: A4 portrait; }

    /* Hide all chrome */
    .no-print, .sidebar, .topbar, .topbar *,
    .flash-container, .trial-banner, nav, header,
    .sidebar-toggle, .dropdown { display: none !important; }

    /* Full-width body, no scroll */
    html, body {
        background: #fff !important;
        margin: 0 !important; padding: 0 !important;
        width: 100% !important; max-width: 100% !important;
        overflow: visible !important;
    }

    /* Kill sidebar offset completely */
    .main-wrapper, .page-content {
        margin: 0 !important; padding: 0 !important;
        width: 100% !important; max-width: 100% !important;
        left: 0 !important; transform: none !important;
        overflow: visible !important;
    }

    /* Invoice document: full width, no decorations */
    .invoice-doc {
        box-shadow: none !important; border: none !important;
        padding: 0 !important; margin: 0 !important;
        max-width: 100% !important; width: 100% !important;
        overflow: visible !important;
    }

    /* Tables: force wrap instead of overflow */
    table { width: 100% !important; table-layout: fixed !important; }
    td, th { word-wrap: break-word !important; overflow-wrap: break-word !important; }

    /* Preserve colours */
    * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
}
