:root {
    --bg: #f4f3f1;
    --surface: #ffffff;
    --surface-sunken: #faf9f6;
    --border: #e5e3dd;
    --text: #1c1a17;
    --muted: #6b6660;
    --primary: #c2660a;
    --primary-dark: #9c5108;
    --primary-soft: #f7e6d3;
    --sidebar: #1c1917;
    --sidebar-text: #d6d3ce;
    --sidebar-muted: #8a847a;
    --sidebar-active: #29241f;
    --success: #16a34a;
    --success-soft: #dcfce7;
    --danger: #dc2626;
    --danger-dark: #b91c1c;
    --danger-soft: #fee2e2;
    --warning: #d97706;
    --warning-soft: #fef3c7;

    --radius: 12px;
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family:
        Inter,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.45;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select,
textarea {
    font: inherit;
}

svg {
    flex-shrink: 0;
}

/* Keyboard focus is always visible — never remove this without replacing it */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Numbers that should line up in a column: prices, quantities, counts */
.num {
    font-variant-numeric: tabular-nums;
}

/* Application shell */

.app {
    min-height: 100vh;
    display: flex;
}

/* Sidebar */

.sidebar {
    width: 240px;
    min-height: 100vh;
    background: var(--sidebar);
    color: var(--sidebar-text);
    padding: 24px 14px;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
}

.sidebar nav {
    flex: 1;
}

.sidebar-footer {
    padding: 12px;
    font-size: 11px;
    color: #6b665e;
    letter-spacing: 0.02em;
}

.brand {
    padding: 0 12px 28px;
}

.brand-name {
    color: #ffffff;
    font-size: 21px;
    font-weight: 700;
    letter-spacing: -0.5px;
    line-height: 1.2;
}

.brand-subtitle {
    margin-top: 4px;
    font-size: 12px;
    color: #a39d94;
}

.nav-section {
    margin-top: 20px;
}

.nav-label {
    padding: 0 12px 8px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--sidebar-muted);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    margin-bottom: 2px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--sidebar-text);
    border-left: 3px solid transparent;
    transition: background 0.15s ease, color 0.15s ease;
}

.nav-item .nav-icon {
    display: flex;
    color: var(--sidebar-muted);
    transition: color 0.15s ease;
}

.nav-item:hover {
    background: var(--sidebar-active);
    color: #ffffff;
}

.nav-item:hover .nav-icon {
    color: var(--sidebar-text);
}

.nav-item.active {
    background: var(--sidebar-active);
    color: #ffffff;
    border-left-color: var(--primary);
}

.nav-item.active .nav-icon {
    color: var(--primary);
}

/* Main area */

.main {
    margin-left: 240px;
    width: calc(100% - 240px);
    min-height: 100vh;
}

/* Top bar */

.topbar {
    height: 72px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
}

.topbar-title {
    font-size: 16px;
    font-weight: 600;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 14px;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #ece9e4;
    display: grid;
    place-items: center;
    font-size: 13px;
    font-weight: 600;
}

.logout-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--muted);
    padding: 6px 10px;
    border-radius: 7px;
    transition: background 0.15s ease, color 0.15s ease;
}

.logout-link:hover {
    color: var(--text);
    background: var(--surface-sunken);
}

/* Page */

.page {
    padding: 32px;
}

.page-header {
    margin-bottom: 28px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.page-title {
    margin: 0;
    font-size: 28px;
    letter-spacing: -0.7px;
}

.page-description {
    margin: 7px 0 0;
    color: var(--muted);
    font-size: 14px;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 42px;
    padding: 0 18px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: var(--primary);
    color: #ffffff;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.button svg {
    width: 16px;
    height: 16px;
}

.button:hover {
    background: var(--primary-dark);
}

.button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.button.secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}

.button.secondary:hover {
    background: var(--surface-sunken);
    border-color: #d6d3cb;
}

/* Destructive actions get their own unmistakable style, never the same
   look as a neutral "view" or "secondary" action. */
.button.danger {
    background: var(--surface);
    color: var(--danger-dark);
    border-color: #f3c7c7;
}

.button.danger:hover {
    background: var(--danger-soft);
    border-color: var(--danger);
}

/* Compact variant for inline row actions inside tables/lists */
.button.sm {
    height: 32px;
    padding: 0 12px;
    font-size: 12.5px;
    gap: 6px;
    border-radius: 7px;
}

.button.sm svg {
    width: 14px;
    height: 14px;
}

/* Cards */

.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 18px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.stat-card {
    padding: 20px;
}

.stat-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.stat-icon {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    flex-shrink: 0;
}

.stat-icon.success { background: var(--success-soft); color: #166534; }
.stat-icon.warning { background: var(--warning-soft); color: #92400e; }

.stat-label {
    color: var(--muted);
    font-size: 13px;
}

.stat-value {
    margin-top: 8px;
    font-size: 25px;
    font-weight: 700;
    letter-spacing: -0.5px;
    font-variant-numeric: tabular-nums;
}

.stat-meta {
    margin-top: 8px;
    font-size: 12px;
    color: var(--muted);
}

.stat-meta.warning {
    color: var(--warning);
    font-weight: 600;
}

/* Content grid */

.content-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    margin-top: 20px;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-size: 14.5px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card-header-title {
    display: flex;
    align-items: center;
    gap: 9px;
}

.card-header-title .icon-badge {
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 7px;
    background: var(--surface-sunken);
    color: var(--muted);
    flex-shrink: 0;
}

.card-header-link {
    font-size: 12.5px;
    font-weight: 500;
    color: var(--muted);
    white-space: nowrap;
}

.card-header-link:hover {
    color: var(--primary-dark);
}

.link-action {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    font-weight: 600;
    color: var(--primary-dark);
}

.link-action:hover {
    color: var(--primary);
}

.link-action svg {
    width: 14px;
    height: 14px;
}

.card-body {
    padding: 20px;
}

.empty-state {
    min-height: 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--muted);
    font-size: 14px;
    text-align: center;
    padding: 24px 20px;
    line-height: 1.6;
}

.empty-state svg {
    color: #c9c5bb;
}

/* Tables */

.table-wrap {
    overflow-x: auto;
}

table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table th {
    text-align: left;
    padding: 12px 20px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr.clickable {
    cursor: pointer;
}

.data-table tr.clickable:hover {
    background: #faf9f6;
}

.data-table select,
.data-table input[type="number"] {
    width: 100%;
    height: 38px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 7px;
    outline: none;
}

.data-table select:focus,
.data-table input[type="number"]:focus {
    border-color: var(--primary);
}

/* Pagination */

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

.pagination-summary {
    font-size: 12.5px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.pagination-page {
    font-size: 12.5px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.pagination-controls span.button[aria-disabled="true"] {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

/* Status badges */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 99px;
    font-size: 11.5px;
    font-weight: 600;
    text-transform: capitalize;
    white-space: nowrap;
}

.badge svg {
    width: 12px;
    height: 12px;
}

.badge-received { background: #e0e7ff; color: #3730a3; }
.badge-in_progress { background: #fef3c7; color: #92400e; }
.badge-quality_check { background: #ede9fe; color: #5b21b6; }
.badge-ready { background: #dcfce7; color: #166534; }
.badge-delivered { background: #e5e3dd; color: #57534e; }
.badge-on_hold { background: #fee2e2; color: #991b1b; }
.badge-cancelled { background: #e5e3dd; color: #a8a29e; }

.badge-unpaid { background: #fee2e2; color: #991b1b; }
.badge-partial { background: #fef3c7; color: #92400e; }
.badge-paid { background: #dcfce7; color: #166534; }

/* Forms */

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-grid.single {
    grid-template-columns: 1fr;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-field label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.form-field input,
.form-field select,
.form-field textarea {
    height: 42px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
    outline: none;
}

.form-field textarea {
    height: auto;
    padding: 10px 14px;
    min-height: 90px;
    resize: vertical;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
    border-color: var(--primary);
}

.form-actions {
    margin-top: 24px;
    display: flex;
    gap: 12px;
}

.form-error {
    background: #fee2e2;
    color: #991b1b;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 13.5px;
    margin-bottom: 20px;
}

/* Search / results (job card intake, parts lookup) */

.search-row {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.search-row input {
    flex: 1;
    height: 46px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    outline: none;
}

.search-row input:focus {
    border-color: var(--primary);
}

.search-result {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: border-color 0.15s ease;
}

.search-result:hover {
    border-color: var(--primary);
}

.result-meta {
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
}

/* Kanban (job cards board) */

.kanban {
    display: grid;
    grid-template-columns: repeat(5, minmax(220px, 1fr));
    gap: 16px;
    margin-top: 24px;
}

.kanban-column {
    background: #ece9e2;
    border-radius: var(--radius);
    border-top: 3px solid transparent;
    padding: 14px;
    min-height: 200px;
    transition: box-shadow 0.15s ease, opacity 0.15s ease;
}

.kanban-column-cards {
    min-height: 60px;
}

/* One accent colour per stage — carried by both the column's top edge
   and (more strongly) by every card inside it, so status reads at a
   glance without needing to read the column header. */
.kanban-column.col-received { border-top-color: #4338ca; }
.kanban-column.col-in_progress { border-top-color: #b45309; }
.kanban-column.col-quality_check { border-top-color: #6d28d9; }
.kanban-column.col-ready { border-top-color: #15803d; }
.kanban-column.col-delivered { border-top-color: #78716c; }

.kanban-column.drag-over {
    box-shadow: inset 0 0 0 2px var(--primary);
}

.kanban-column.drop-disabled {
    opacity: 0.4;
}

.kanban-column-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.kanban-column-label {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.kanban-column-label svg {
    color: #a39d8f;
}

.kanban-card-link {
    display: block;
}

.kanban-card-link[draggable="true"] {
    cursor: grab;
}

.kanban-card-link[draggable="true"]:active {
    cursor: grabbing;
}

.kanban-card-link.dragging .kanban-card {
    opacity: 0.4;
}

.kanban-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--border);
    border-radius: 9px;
    padding: 12px 14px;
    margin-bottom: 10px;
    box-shadow: var(--shadow);
    transition: opacity 0.15s ease;
}

/* Card colour matches the actual status, not just the column it sits
   in — an on_hold card visually lives in the In Progress column but
   is tinted distinctly so a paused job never looks like active work. */
.kanban-card.card-received { border-left-color: #4338ca; background: #eef0fd; }
.kanban-card.card-in_progress { border-left-color: #b45309; background: #fef8ec; }
.kanban-card.card-on_hold { border-left-color: #b91c1c; background: #fdeeee; }
.kanban-card.card-quality_check { border-left-color: #6d28d9; background: #f5f2fc; }
.kanban-card.card-ready { border-left-color: #15803d; background: #eefbf1; }
.kanban-card.card-delivered { border-left-color: #78716c; background: #f2f1ef; }

.kanban-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.kanban-card-job-no {
    font-size: 11.5px;
    color: var(--muted);
    font-weight: 600;
}

.kanban-card-vehicle {
    margin-top: 4px;
    font-weight: 600;
    font-size: 14px;
}

.kanban-card-customer {
    margin-top: 2px;
    font-size: 12.5px;
    color: var(--muted);
}

.kanban-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: var(--text);
    color: #fff;
    padding: 12px 18px;
    border-radius: 9px;
    font-size: 13.5px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 200;
}

.kanban-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Status tracker — same stage colours as the kanban board, so the job
   card detail page reads as the same object, not a different UI. */
.status-tracker {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
}

.status-tracker-segment {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    text-align: center;
}

.status-tracker-dot {
    width: 100%;
    height: 6px;
    border-radius: 4px;
    background: var(--border);
}

.status-tracker-segment.filled .status-tracker-dot {
    background: var(--stage-color, var(--primary));
}

.status-tracker-label {
    font-size: 10.5px;
    color: var(--muted);
    line-height: 1.3;
}

.status-tracker-segment.filled .status-tracker-label {
    color: var(--stage-color, var(--text));
    font-weight: 600;
}

/* Login */

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: var(--sidebar);
}

.auth-card {
    width: 380px;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 40px 36px;
    box-shadow: var(--shadow);
}

.auth-brand {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.auth-subtitle {
    margin: 6px 0 28px;
    color: var(--muted);
    font-size: 14px;
}

.auth-field {
    margin-bottom: 16px;
}

.auth-field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
}

.auth-field input {
    width: 100%;
    height: 44px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    outline: none;
}

.auth-field input:focus {
    border-color: var(--primary);
}

.auth-submit {
    width: 100%;
    height: 46px;
    margin-top: 8px;
    border: 0;
    border-radius: 8px;
    background: var(--primary);
    color: #ffffff;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
}

.auth-submit:hover {
    background: var(--primary-dark);
}

/* Layout utilities — replace one-off inline styles so spacing stays
   consistent everywhere instead of drifting page by page. */

.stack {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.stack-sm {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.inline-form {
    display: inline-flex;
}

.panel-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

.selected-summary {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface-sunken);
    border-radius: 9px;
    padding: 12px 14px;
    margin-bottom: 16px;
}

.selected-summary .icon-badge {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--muted);
    flex-shrink: 0;
}

/* A find-or-add helper row: search stays primary, "add new" is always
   visible right beside it — never hidden behind a failed search. */
.intake-add-new-row {
    margin: 12px 0 16px;
}

/* Modal ("quick create" dialogs launched from + New buttons) */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(20, 18, 15, 0.55);
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: 5vh 20px;
    overflow-y: auto;
    z-index: 100;
}

.modal-backdrop.open {
    display: flex;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius);
    width: 100%;
    max-width: 640px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
    margin: auto 0;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
}

.modal-header-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 700;
}

.modal-header-title .icon-badge {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.modal-close {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    color: var(--muted);
    background: transparent;
    border: 0;
    cursor: pointer;
}

.modal-close:hover {
    background: var(--surface-sunken);
    color: var(--text);
}

.modal-body {
    padding: 22px;
    max-height: 78vh;
    overflow-y: auto;
}

/* Responsive */

@media (max-width: 1100px) {
    .kanban {
        grid-template-columns: repeat(3, minmax(220px, 1fr));
        overflow-x: auto;
    }
}

@media (max-width: 1000px) {
    .stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .content-grid {
        grid-template-columns: 1fr;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 700px) {
    .sidebar {
        width: 72px;
        padding: 20px 8px;
    }

    .brand-name,
    .brand-subtitle,
    .nav-label,
    .nav-item span:last-child,
    .sidebar-footer {
        display: none;
    }

    .brand {
        padding-left: 10px;
    }

    .main {
        margin-left: 72px;
        width: calc(100% - 72px);
    }

    .topbar {
        padding: 0 20px;
    }

    .page {
        padding: 20px;
    }

    .stats {
        grid-template-columns: 1fr;
    }

    .kanban {
        grid-template-columns: 1fr;
    }
}
