html, body {
    font-family: var(--font-ui, "Segoe UI", -apple-system, BlinkMacSystemFont, system-ui, sans-serif);
}

.page-header {
    background: var(--surface);
    border-bottom: 1px solid var(--ledger-rule, var(--line));
    padding: 14px 24px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--ledger-rule, var(--line));
    border-radius: var(--r-md) !important;
    padding: 20px;
    width: 100%;
    height: 100%;
    min-height: 112px;
    transition: box-shadow 180ms var(--ease-out), background 180ms var(--ease-out), border-color 180ms var(--ease-out);
}

.stat-card:hover {
    background: var(--surface-raised);
    box-shadow: var(--shadow-2) !important;
    border-color: color-mix(in oklch, var(--brand), var(--line) 54%);
}

.stat-icon-wrap {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon-wrap--lg {
    width: 52px;
    height: 52px;
    border-radius: var(--r-sm);
}

.stat-icon-wrap[style*="#FDE6D3"],
.stat-icon-wrap[style*="#FEF3C7"] {
    background: var(--accent-soft) !important;
}

.stat-icon-wrap[style*="#ECF6EE"] {
    background: var(--ok-soft) !important;
}

.stat-icon-wrap[style*="#FEE2E2"] {
    background: var(--bad-soft) !important;
}

.stat-icon-wrap .mud-icon-root[style*="#C2410C"],
.stat-icon-wrap .mud-icon-root[style*="#B45309"] {
    color: var(--accent-strong) !important;
}

.stat-icon-wrap .mud-icon-root[style*="#15803D"] {
    color: var(--ok) !important;
}

.stat-icon-wrap .mud-icon-root[style*="#B91C1C"] {
    color: var(--bad) !important;
}

.table-card {
    border: 1px solid var(--ledger-rule, var(--line)) !important;
    border-radius: var(--r-md) !important;
    overflow: hidden;
    width: 100%;
}

.mud-grid > .mud-grid-item:has(> .stat-card),
.mud-grid > .mud-grid-item:has(> .report-metric),
.mud-grid > .mud-grid-item:has(> .table-card),
.mud-grid > .mud-grid-item:has(> .mud-card) {
    display: flex;
    flex-direction: column;
}

.mud-grid > .mud-grid-item:has(> .stat-card) > .stat-card,
.mud-grid > .mud-grid-item:has(> .report-metric) > .report-metric,
.mud-grid > .mud-grid-item:has(> .table-card) > .table-card,
.mud-grid > .mud-grid-item:has(> .mud-card) > .mud-card {
    flex: 1 1 auto;
    width: 100%;
}

.page-header .mud-container > .d-flex.align-center {
    gap: 10px;
}

.page-header .mud-stack-row,
.table-card > .d-flex.align-center,
.table-card > .d-flex.align-center.justify-space-between,
.mud-dialog-actions,
.mud-message-box .mud-dialog-actions {
    gap: 10px;
}

.table-card > .d-flex.align-center {
    flex-wrap: wrap;
    padding: 16px !important;
}

.table-card > .d-flex.align-center .mud-button-root.ml-2,
.table-card > .d-flex.align-center .mud-button-root.mr-2 {
    margin-left: 0 !important;
    margin-right: 0 !important;
}

.mud-dialog-actions {
    padding: 16px 24px 20px !important;
    flex-wrap: wrap;
}

.mud-dialog-actions .mud-button-root {
    margin: 0 !important;
}

.cursor-pointer {
    cursor: pointer;
}

.stat-label {
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--ink-muted);
}

.stat-value {
    font-weight: 700;
    color: var(--ink);
    line-height: 1.2;
}

.stat-hint {
    color: var(--ink-soft);
}

.section-divider {
    border-bottom: 1px solid var(--line-soft);
}

.reports-filter {
    align-items: center;
    gap: 12px;
    flex: 1 1 auto;
    flex-wrap: wrap;
    justify-content: flex-end;
    min-width: 0;
    max-width: 100%;
}

.reports-filter .mud-picker,
.reports-filter .mud-input-control {
    flex: 1 1 160px;
    min-width: 150px;
    max-width: 190px;
}

.reports-filter .mud-button-root {
    flex: 0 0 auto;
}

.report-metric {
    background: var(--surface);
    border: 1px solid var(--ledger-rule, var(--line));
    border-radius: var(--r-md);
    padding: 14px;
    width: 100%;
    height: 100%;
}

.report-metric--compact {
    padding: 12px;
}

.report-rate {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.report-bar {
    width: 100%;
    height: 10px;
    background: var(--surface-mark);
    border-radius: var(--r-pill);
    overflow: hidden;
}

.report-bar > div {
    height: 100%;
    background: var(--ok);
}

.report-bar--small {
    height: 6px;
    min-width: 110px;
}

.report-rate-cell {
    display: grid;
    gap: 6px;
    min-width: 140px;
}

.job-items-table {
    display: grid;
}

.job-item-row {
    display: grid;
    grid-template-columns: minmax(120px, .8fr) minmax(180px, 1.4fr) minmax(90px, .55fr) minmax(110px, .6fr) minmax(110px, .6fr) auto auto;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line-soft);
}

.job-item-row--template {
    grid-template-columns: minmax(120px, .8fr) minmax(180px, 1.5fr) minmax(90px, .55fr) minmax(110px, .6fr) minmax(110px, .6fr) auto;
}

.job-item-row:last-child {
    border-bottom: 0;
}

.job-item-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    justify-content: flex-end;
}

.field-work-section-head {
    align-items: center;
    display: flex;
    gap: 16px;
    justify-content: space-between;
    margin-bottom: 16px;
}

.field-work-record {
    background: var(--surface-raised);
    border: 1px solid var(--line-soft);
    border-radius: var(--r-md);
    margin-bottom: 12px;
    padding: 12px;
}

.field-work-record-state {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.field-work-record-state .mud-typography {
    flex: 1 1 220px;
}

/* Combined date + time control (Components/Jobs/DateTimePicker.razor). The two
   MudPickers must share a row and shrink to fit; without min-width: 0 the
   pickers' min-content width forces an overlap or an unwanted wrap. They only
   stack once the container drops below ~230px. */
.datetime-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: flex-start;
}

.datetime-picker > .datetime-picker-date {
    flex: 1 1 130px;
    min-width: 0;
}

.datetime-picker > .datetime-picker-time {
    flex: 1 1 100px;
    min-width: 0;
}

.field-work-billing-card {
    overflow: hidden;
}

.field-work-billing-table-wrap {
    overflow-x: auto;
}

.field-work-billing-table {
    min-width: 1120px;
}

.field-work-billing-table th {
    white-space: nowrap;
}

.field-work-billing-table td {
    vertical-align: middle;
}

.field-work-billing-table td:nth-child(3) {
    min-width: 260px;
}

.field-work-billing-table td:nth-child(5),
.field-work-billing-table td:nth-child(6),
.field-work-billing-table td:nth-child(7) {
    min-width: 145px;
}

.field-work-line-unselected {
    background: var(--surface-tint);
    color: var(--ink-muted);
}

.field-work-number {
    font-variant-numeric: tabular-nums;
    text-align: right !important;
    white-space: nowrap;
}

.job-cost-lines {
    display: grid;
    gap: 10px;
}

.job-cost-lines > div {
    align-items: center;
    border-bottom: 1px solid var(--line-soft);
    display: flex;
    font-variant-numeric: tabular-nums;
    gap: 20px;
    justify-content: space-between;
    padding-bottom: 10px;
}

.job-cost-lines > div:last-child {
    border-bottom: 0;
}

.job-cost-lines-total {
    color: var(--ink);
    font-size: 1rem;
    padding-top: 4px;
}

.pdf-template-toolbar .mud-input-control {
    min-width: 180px;
    margin-top: 0;
}

.pdf-logo-preview {
    max-width: 220px;
    max-height: 120px;
    object-fit: contain;
    border: 1px solid var(--line-soft);
    border-radius: var(--r-md);
    padding: 12px;
    background: var(--surface-tint);
}

.pdf-color-field {
    display: grid;
    gap: 6px;
}

.pdf-color-field label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--ink-muted);
}

.pdf-color-field > div {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
}

.pdf-color-field input[type="color"] {
    width: 42px;
    height: 42px;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    padding: 3px;
    background: var(--surface);
}

.pdf-region {
    margin-bottom: 18px;
}

.pdf-region-header,
.pdf-column-editor-header,
.pdf-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.pdf-block-panel {
    border: 1px solid var(--line-soft);
    border-radius: var(--r-md) !important;
    margin-bottom: 10px;
    overflow: hidden;
}

.pdf-block-actions,
.pdf-switch-wrap {
    flex-wrap: wrap;
}

.pdf-column-editor {
    display: grid;
    gap: 10px;
}

.pdf-column-row,
.pdf-total-row {
    display: grid;
    align-items: center;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--line-soft);
    border-radius: var(--r-md);
    background: var(--surface-tint);
}

.pdf-column-row {
    grid-template-columns: auto auto auto minmax(130px, 1fr) minmax(150px, 1.1fr) minmax(100px, .7fr) minmax(110px, .8fr) auto;
}

.pdf-total-row {
    grid-template-columns: minmax(150px, 1fr) minmax(160px, 1fr) auto minmax(150px, 1fr) auto;
}

.pdf-preview-shell {
    position: sticky;
    top: 88px;
    display: grid;
    grid-template-rows: auto minmax(620px, calc(100vh - 190px));
    border: 1px solid var(--ledger-rule, var(--line));
    border-radius: var(--r-md);
    background: var(--surface);
    overflow: hidden;
}

.pdf-preview-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--line-soft);
    margin-bottom: 0;
}

.pdf-preview-frame {
    width: 100%;
    height: 100%;
    border: 0;
    background: var(--surface-tint);
}

.pdf-preview-empty {
    display: grid;
    place-items: center;
    align-content: center;
    gap: 10px;
    min-height: 420px;
    background: var(--surface-tint);
}

.page-title {
    font-weight: 700;
    color: var(--ink);
}

.selected {
    background-color: var(--brand-soft) !important;
}

.selected > td {
    color: var(--ink) !important;
}

.selected > td .mud-input {
    color: var(--ink) !important;
}

.mud-nav-link.active {
    background-color: var(--sidebar-active-bg) !important;
    color: var(--sidebar-active-fg) !important;
}

.mud-nav-link.active .mud-icon-root {
    color: currentColor !important;
}

.app-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ─── Mobile responsiveness ─────────────────────────────────────────── */

/* Tighter page header on phones */
@media (max-width: 599px) {
    .page-header {
        padding: 10px 12px;
    }

    .page-header .mud-container {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .page-header .mud-container > .d-flex.align-center {
        gap: 6px;
        min-width: 0;
        width: 100%;
    }

    .page-header .mud-typography-h6 {
        display: block;
        max-width: calc(100vw - 190px);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Reduce container padding on phones */
    .mud-container {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }

    /* Tighter stat cards: compact icon plus stacked text at half-width */
    .stat-card {
        padding: 12px;
    }

    .stat-card .d-flex.align-center {
        gap: 10px !important;
    }

    .stat-icon-wrap--lg {
        width: 40px !important;
        height: 40px !important;
    }

    .stat-value {
        font-size: 1.25rem !important;
    }

    /* Disable hover lift on touch */
    .stat-card:hover {
        transform: none;
        box-shadow: none !important;
    }

    /* Allow page-header title to truncate gracefully */
    .page-header-title {
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        max-width: 140px;
    }

    .app-title {
        max-width: calc(100vw - 160px);
    }
}

/* List-page title bar: wraps action buttons below title on phones */
.list-header {
    display: flex;
    align-items: center;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: nowrap;
}

.list-header-actions {
    display: flex;
    gap: 10px;
    margin-left: auto;
    flex-shrink: 0;
    flex-wrap: nowrap;
}

@media (max-width: 599px) {
    .list-header {
        flex-wrap: wrap;
        margin-bottom: 16px;
    }

    /* Title takes full width, buttons drop to own row */
    .list-header > div:first-child {
        flex: 1 1 100%;
    }

    .list-header-actions {
        margin-left: 0;
        width: 100%;
        justify-content: flex-end;
        flex-wrap: wrap;
    }

    .list-header-actions .mud-button-root {
        flex: 1 1 auto;
        min-width: 0;
    }
}

/* DataGrid horizontal scroll on small screens */
.table-card .mud-table-toolbar {
    align-items: center;
    gap: 12px;
    min-height: auto;
    padding: 16px;
}

.table-card .mud-table-toolbar .mud-input-control {
    margin-top: 0;
    min-width: min(260px, 100%);
}

.mobile-grid-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-width: 0;
    flex-wrap: wrap;
}

.mobile-grid-toolbar .mud-input-control {
    margin-top: 0;
    min-width: 160px;
}

.mobile-grid-toolbar .mud-spacer {
    min-width: 0;
}

.mobile-filter-scroll {
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

.mobile-filter-scroll .mud-toggle-group {
    width: max-content;
    max-width: none;
}

.mobile-filter-scroll .mud-toggle-group .mud-button-root {
    flex: 0 0 auto;
    white-space: nowrap;
}

@media (max-width: 599px) {
    .table-card .mud-table-container,
    .table-card .mud-data-grid {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table-card .mud-table-toolbar {
        flex-wrap: wrap;
        height: auto !important;
        min-height: 0 !important;
        align-items: stretch !important;
    }

    .table-card .mud-table-toolbar .mud-spacer {
        display: none;
    }

    .table-card .mud-table-toolbar .mud-input-control,
    .table-card .mud-table-toolbar .mud-toggle-group {
        width: 100%;
    }

    .mobile-grid-toolbar {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        align-items: stretch;
        gap: 10px;
        padding: 0;
    }

    .mobile-grid-toolbar .mud-input-control {
        width: 100%;
        min-width: 0;
    }

    .mobile-filter-scroll {
        width: 100%;
        padding-bottom: 2px;
    }

    .mobile-filter-scroll .mud-toggle-group {
        width: max-content !important;
    }

    /* Tighter spacing inside forms on mobile */
    .mud-grid {
        row-gap: 4px;
    }

    /* Reduce page content padding on mobile */
    .mud-container.pa-6 {
        padding: 16px !important;
    }

    .mud-dialog .mud-dialog-content {
        padding-left: 12px;
        padding-right: 12px;
    }

    /* MudBlazor's tab scroll buttons leave too little usable space on
       phones. Use native horizontal swiping and compact tab widths instead. */
    .mud-tabs {
        min-width: 0;
    }

    .mud-tabs .mud-tabs-scroll-button {
        display: none !important;
    }

    .mud-tabs .mud-tabs-tabbar,
    .mud-tabs .mud-tabs-tabbar-inner,
    .mud-tabs .mud-tabs-tabbar-content {
        min-width: 0 !important;
        width: 100% !important;
    }

    .mud-tabs .mud-tabs-tabbar-content {
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    .mud-tabs .mud-tabs-tabbar-wrapper {
        min-width: max-content !important;
        width: max-content !important;
    }

    .mud-tabs .mud-tab {
        flex: 0 0 auto !important;
        min-width: max-content !important;
        width: auto !important;
        padding-left: 14px !important;
        padding-right: 14px !important;
    }
}

@media (max-width: 599px) {
    .page-header .mud-stack-row,
    .table-card > .d-flex.align-center,
    .mud-dialog-actions {
        gap: 8px;
    }

    .table-card > .d-flex.align-center {
        padding: 12px !important;
    }

    .table-card > .d-flex.align-center .mud-button-root,
    .mud-dialog-actions .mud-button-root {
        flex: 1 1 auto;
        min-width: 0;
    }

    .reports-filter {
        align-items: stretch;
    }

    .reports-filter .mud-picker,
    .reports-filter .mud-input-control {
        max-width: none;
        width: 100%;
    }

    .pdf-color-field > div,
    .pdf-column-row,
    .pdf-total-row,
    .job-item-row,
    .job-item-row--template {
        grid-template-columns: 1fr;
    }

    .field-work-section-head {
        align-items: stretch;
        flex-direction: column;
    }

    .pdf-color-field input[type="color"] {
        width: 100%;
    }

    .pdf-preview-shell {
        position: static;
        grid-template-rows: auto 520px;
    }
}

/* ─── End mobile ─────────────────────────────────────────────────────── */

/* FocusOnNavigate focuses the page <h1> on load for accessibility; suppress
   the browser's default focus ring since headings aren't interactive. */
h1:focus,
h1:focus-visible {
    outline: none;
}

#components-reconnect-modal {
    animation: none !important;
    background: transparent !important;
    bottom: 18px !important;
    box-shadow: none !important;
    color: var(--ink) !important;
    display: none !important;
    left: auto !important;
    margin: 0 !important;
    max-width: calc(100vw - 32px) !important;
    opacity: 0 !important;
    padding: 0 !important;
    pointer-events: none;
    position: fixed !important;
    right: 18px !important;
    top: auto !important;
    transform: none !important;
    visibility: hidden !important;
    width: min(360px, calc(100vw - 32px)) !important;
    z-index: 10000 !important;
}

#components-reconnect-modal.components-reconnect-show {
    animation: reconnect-toast-delay 20s forwards !important;
    display: block !important;
}

#components-reconnect-modal.components-reconnect-failed,
#components-reconnect-modal.components-reconnect-rejected {
    animation: none !important;
    display: block !important;
    opacity: 1 !important;
    pointer-events: auto;
    visibility: visible !important;
}

#components-reconnect-modal.components-reconnect-hide {
    display: none !important;
}

.reconnect-toast__panel {
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--ledger-rule, var(--line));
    border-radius: var(--r-md);
    box-shadow: var(--shadow-2);
    display: flex;
    gap: 12px;
    padding: 14px 16px;
}

.reconnect-toast__spinner {
    animation: reconnect-toast-spin 0.9s linear infinite;
    border: 2px solid var(--surface-tint);
    border-top-color: var(--accent-strong);
    border-radius: 50%;
    flex: 0 0 auto;
    height: 18px;
    width: 18px;
}

.reconnect-toast__title,
.reconnect-toast__message {
    display: block;
    line-height: 1.3;
}

.reconnect-toast__title {
    font-size: 0.92rem;
    font-weight: 700;
}

.reconnect-toast__message {
    color: var(--ink-muted);
    font-size: 0.8rem;
    margin-top: 2px;
}

#components-reconnect-modal.components-reconnect-show .reconnect-toast__title::before {
    content: "Connection paused";
}

#components-reconnect-modal.components-reconnect-show .reconnect-toast__message::before {
    content: "Still trying to reconnect.";
}

#components-reconnect-modal.components-reconnect-failed .reconnect-toast__spinner,
#components-reconnect-modal.components-reconnect-rejected .reconnect-toast__spinner {
    animation: none;
    border-color: var(--bad);
}

#components-reconnect-modal.components-reconnect-failed .reconnect-toast__title::before,
#components-reconnect-modal.components-reconnect-rejected .reconnect-toast__title::before {
    content: "Connection lost";
}

#components-reconnect-modal.components-reconnect-failed .reconnect-toast__message::before,
#components-reconnect-modal.components-reconnect-rejected .reconnect-toast__message::before {
    content: "Refresh the page when you're back online.";
}

@keyframes reconnect-toast-delay {
    99% {
        opacity: 0;
        visibility: hidden;
    }

    100% {
        opacity: 1;
        visibility: visible;
    }
}

@keyframes reconnect-toast-spin {
    to {
        transform: rotate(360deg);
    }
}

.blazor-error-boundary {
    background: var(--bad-soft);
    border: 1px solid color-mix(in oklch, var(--bad), var(--bad-soft) 45%);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-1);
    color: var(--bad);
    padding: 1rem 1rem 1rem 3.7rem;
}

.blazor-error-boundary::after {
    content: "An error has occurred."
}
