:root {
    --ink: #16211d;
    --forest: #1f5c4c;
    --moss: #6f8179;
    --stone: #667085;
    --canvas: #f4f6f5;
    --surface: #ffffff;
    --line: #d9e0dd;
    --soft: #eaf0ec;
    --soft-blue: #e6eff5;
    --warning-surface: #f9eee1;
    --warning-text: #8a5a00;
    --danger-surface: #fde8e7;
    --danger-text: #b42318;
    --shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
    --radius-xl: 24px;
    --radius-lg: 20px;
    --radius-md: 16px;
    --radius-sm: 14px;
    --sidebar-width: 300px;
    --font-sans: "Segoe UI Variable Text", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    --font-display: "Segoe UI Variable Display", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
}

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

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    background: radial-gradient(circle at top left, rgba(230, 239, 245, 0.75), transparent 36%),
    linear-gradient(180deg, #f7f8f7 0%, #f1f4f2 100%);
    color: var(--ink);
    font-family: var(--font-sans);
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

[hidden] {
    display: none !important;
}

.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

a {
    color: inherit;
}

h1,
h2,
h3 {
    margin: 0;
    color: var(--ink);
}

h1,
.display-title,
.page-header h1 {
    font-family: var(--font-display);
    font-weight: 700;
    letter-spacing: 0;
}

p {
    margin: 0;
    color: var(--stone);
    line-height: 1.6;
}

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

.app-shell {
    display: grid;
    grid-template-columns: minmax(250px, var(--sidebar-width)) minmax(0, 1fr);
    min-height: 100vh;
}

.app-sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    gap: 28px;
    height: 100vh;
    overflow-y: auto;
    padding: 28px 22px;
    background: rgba(255, 255, 255, 0.84);
    backdrop-filter: blur(18px);
    border-right: 1px solid rgba(217, 224, 221, 0.9);
}

.public-brand-logo {
    display: block;
    width: min(260px, 78vw);
    height: auto;
    margin-bottom: 18px;
    object-fit: contain;
}

.maintenance-screen {
    display: grid;
    min-height: calc(100vh - 80px);
    place-items: center;
    padding: clamp(18px, 4vw, 42px);
}

.maintenance-illustration {
    display: block;
    width: min(100%, 860px);
    height: auto;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
}

.brand-kicker,
.nav-section-label,
.eyebrow,
.eyebrow-label {
    color: var(--stone);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.38em;
    text-transform: uppercase;
}

.nav-stack {
    display: flex;
    flex-direction: column;
    gap: 28px;
    flex: 1;
}

.nav-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-link {
    display: block;
    padding: 12px 14px;
    border-radius: 14px;
    color: var(--ink);
    text-decoration: none;
    font-weight: 600;
    transition: background-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.nav-link:hover {
    background: rgba(31, 92, 76, 0.08);
    color: var(--forest);
    transform: translateX(2px);
}

.nav-link.is-active {
    background: var(--soft);
    color: var(--forest);
}

.nav-link-danger {
    color: var(--danger-text);
}

.sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.account-chip {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
}

.sidebar-identity {
    grid-template-columns: 40px minmax(0, 1fr);
    gap: 10px;
    min-height: 62px;
    padding: 10px 12px;
    border-radius: 12px;
}

.sidebar-identity .account-avatar {
    width: 40px;
    height: 40px;
}

.sidebar-identity-copy {
    min-width: 0;
}

.sidebar-identity-copy strong,
.sidebar-identity-copy p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.account-avatar {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--soft-blue);
    color: var(--forest);
    font-weight: 700;
    overflow: hidden;
}

.account-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.account-chip strong {
    display: block;
    margin-bottom: 2px;
}

.account-chip p {
    font-size: 13px;
    overflow-wrap: anywhere;
}

.app-main,
.public-shell {
    padding: 32px;
}

.app-main {
    min-width: 0;
}

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

.page-header h1 {
    font-size: clamp(2rem, 1.65rem + 1.2vw, 3rem);
    line-height: 1.02;
    margin-top: 10px;
}

.page-lead {
    max-width: 56rem;
    margin-top: 12px;
    font-size: 15px;
}

.hero-panel,
.panel,
.metric-card,
.list-card,
.empty-state,
.state-card,
.surface-card,
.profile-panel {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--line);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
}

.hero-panel {
    padding: 28px;
    background: linear-gradient(135deg, rgba(230, 239, 245, 0.95), rgba(247, 251, 253, 0.98));
}

.hero-panel .page-lead {
    max-width: 40rem;
}

.metric-grid,
.panel-grid,
.two-column-grid,
.three-column-grid {
    display: grid;
    gap: 16px;
}

.metric-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.panel-grid,
.two-column-grid {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.three-column-grid {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.metric-card {
    padding: 18px;
}

.metric-card strong {
    display: block;
    margin-top: 8px;
    font-size: 24px;
    color: var(--ink);
}

.panel {
    padding: 24px;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
    margin-bottom: 20px;
}

.panel-title {
    font-size: 22px;
    font-weight: 700;
}

.panel-subtitle {
    margin-top: 6px;
    max-width: 44rem;
}

.stack,
.vertical-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.list-card {
    padding: 22px;
}

.list-card h3 {
    font-size: 20px;
    margin-bottom: 10px;
}

.list-card-header,
.row-split,
.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
}

.meta-list {
    display: grid;
    gap: 8px;
}

.meta-list strong,
.detail-label {
    color: var(--ink);
    font-weight: 700;
}

.detail-value,
.meta-list span {
    color: var(--stone);
}

.status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
    background: var(--soft);
    color: var(--forest);
}

.status-pill.pending,
.status-pill.pending_review,
.status-pill.checkout_created,
.status-pill.hold_requested,
.status-pill.disputed,
.status-pill.cash_due,
.status-pill.cash_agreed,
.status-pill.cash_paid_unconfirmed,
.status-pill.bank_transfer_due,
.status-pill.bank_transfer_marked_sent,
.status-pill.setup_needed,
.status-pill.needs-video-call,
.status-pill.needs_video_call {
    background: var(--warning-surface);
    color: var(--warning-text);
}

.status-pill.accepted,
.status-pill.active,
.status-pill.completed,
.status-pill.funds_held,
.status-pill.released_to_tradesman,
.status-pill.cash_paid_confirmed,
.status-pill.bank_transfer_received,
.status-pill.ready,
.status-pill.ready_test,
.status-pill.verified {
    background: var(--soft);
    color: var(--forest);
}

.status-pill.denied,
.status-pill.archived,
.status-pill.payment_failed,
.status-pill.cancelled,
.status-pill.rejected {
    background: var(--danger-surface);
    color: var(--danger-text);
}

.status-pill.refunded_to_client {
    background: #e8f1ff;
    color: #1e4fa3;
}

.status-pill.cash_handoff_pending {
    background: #e8f1ff;
    color: #1e4fa3;
}

.availability-row {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--stone);
}

.availability-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--moss);
    flex-shrink: 0;
}

.availability-dot.available {
    background: var(--forest);
}

.availability-dot.unavailable {
    background: var(--danger-text);
}

.availability-dot.warning {
    background: var(--warning-text);
}

.button,
.button-link,
button,
input[type="submit"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    padding: 12px 18px;
    border: 1px solid transparent;
    border-radius: 14px;
    background: var(--forest);
    color: #ffffff;
    text-decoration: none;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}

.button:hover,
.button-link:hover,
button:hover,
input[type="submit"]:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 22px rgba(31, 92, 76, 0.16);
}

.button.secondary,
.button-link.secondary,
button.secondary,
button[type="button"].secondary {
    background: #ffffff;
    color: var(--ink);
    border-color: var(--line);
    box-shadow: none;
}

.button.ghost,
.button-link.ghost {
    background: transparent;
    color: var(--forest);
    border-color: var(--line);
}

.button.danger,
.button-link.danger,
button.danger {
    background: var(--danger-text);
}

.button:disabled,
button:disabled,
input[type="submit"]:disabled {
    opacity: 0.58;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.logout-form .logout-button {
    display: block;
    width: 100%;
    min-height: 0;
    padding: 12px 14px;
    border: 0;
    background: transparent;
    color: var(--danger-text);
    box-shadow: none;
    text-align: left;
    font: inherit;
}

.logout-form .logout-button:hover {
    background: rgba(31, 92, 76, 0.08);
    color: var(--forest);
    box-shadow: none;
    transform: translateX(2px);
}

.button-row,
.inline-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

form {
    margin: 0;
}

.form-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.field-span-full {
    grid-column: 1 / -1;
}

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

.field label,
.field-label {
    color: var(--ink);
    font-size: 14px;
    font-weight: 700;
}

.field-note,
.helper-text,
.muted-text {
    color: var(--stone);
    font-size: 13px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="number"],
input[type="tel"],
select,
textarea,
.input-field {
    width: 100%;
    min-height: 52px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.96);
    color: var(--ink);
    outline: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}

textarea {
    min-height: 140px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
.input-field:focus {
    border-color: var(--forest);
    box-shadow: 0 0 0 4px rgba(31, 92, 76, 0.12);
}

input[type="file"] {
    padding: 14px;
    border: 1px dashed var(--line);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.9);
}

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

.form-success {
    color: var(--forest);
    font-size: 13px;
    font-weight: 600;
}

.info-box {
    padding: 16px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: #f8fbfd;
}

.info-box.warning {
    background: #f6f3e8;
}

.empty-state,
.state-card {
    padding: 28px;
    text-align: center;
}

.empty-state h3,
.state-card h3 {
    margin-bottom: 10px;
}

.surface-table {
    width: 100%;
    border-collapse: collapse;
}

.surface-table td,
.surface-table th {
    padding: 14px 0;
    border-bottom: 1px solid var(--line);
    text-align: left;
}

.surface-table tr:last-child td,
.surface-table tr:last-child th {
    border-bottom: 0;
}

.badge-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.75);
    color: var(--forest);
    font-size: 13px;
    font-weight: 700;
}

.flash-stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.flash {
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
}

.flash-success {
    background: #ebf5ef;
    color: var(--forest);
    border-color: #bdd7c6;
}

.flash-warning {
    background: #fff4e4;
    color: var(--warning-text);
    border-color: #f1d9ab;
}

.flash-danger,
.flash-error {
    background: #fdeceb;
    color: var(--danger-text);
    border-color: #f1c1bc;
}

.toast-root {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

.toast {
    min-width: 260px;
    max-width: min(380px, calc(100vw - 40px));
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
    color: var(--ink);
    box-shadow: var(--shadow);
    animation: toast-in 0.2s ease;
}

.toast-success {
    background: #ebf5ef;
    color: var(--forest);
}

.toast-error {
    background: #fdeceb;
    color: var(--danger-text);
}

.toast-exit {
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.loader {
    width: 44px;
    height: 44px;
    border: 3px solid rgba(31, 92, 76, 0.18);
    border-top-color: var(--forest);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

.loading-inline {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 980px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .app-sidebar {
        position: static;
        height: auto;
        overflow-y: visible;
        border-right: 0;
        border-bottom: 1px solid rgba(217, 224, 221, 0.9);
    }

    .nav-stack {
        gap: 18px;
    }

    .nav-section {
        gap: 6px;
    }

    .app-main,
    .public-shell {
        padding: 22px 18px 28px;
    }
}

@media (max-width: 640px) {
    .page-header,
    .panel-header,
    .list-card-header,
    .row-split,
    .detail-row {
        flex-direction: column;
    }

    .button,
    .button-link,
    button,
    input[type="submit"] {
        width: 100%;
    }

    .button-row,
    .inline-actions {
        flex-direction: column;
    }

    .toast-root {
        right: 12px;
        left: 12px;
        bottom: 12px;
    }

    .toast {
        min-width: 0;
        max-width: none;
    }
}
