/* =============================================================================
   Home page — dashboard layout
   =============================================================================

   The home is a real dashboard: a greeting + a stack of discrete cards on the
   page background. We strip the default .main-card chrome (single white blob)
   for .home-page and let each section be its own card. Spacing rhythm uses an
   8px grid. Typography is hierarchical — H1 dominant, section titles secondary,
   meta text muted.
*/

/* Widen the container for the dashboard table layout. */
body:has(.home-page) .portal-container { max-width: 1080px; }

/* Strip the outer .main-card chrome — cards inside take care of themselves. */
.main-card.home-page {
    background: transparent;
    box-shadow: none;
    margin: 0;
    padding: 24px 16px 40px;
    border-radius: 0;
    overflow: visible;
}
.home-page > * + * { margin-top: 24px; }

/* ============================================================================
   Greeting
   ============================================================================ */
.home-greeting {
    padding: 8px 8px 0;
}
.home-greeting h1 {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
    margin: 0;
    line-height: 1.2;
}
.home-subtitle {
    color: var(--text-muted);
    font-size: 15px;
    margin: 6px 0 0;
    line-height: 1.5;
}

/* ============================================================================
   Card primitive — base for tasks / contact / claims sections
   ============================================================================ */
.home-card {
    background: var(--surface, #fff);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(17, 24, 39, 0.04);
}
.home-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 22px;
    gap: 12px;
    border-bottom: 1px solid var(--border);
}
.home-card-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    margin: 0;
    letter-spacing: -0.01em;
}
.home-card-body { padding: 18px 22px; }

/* ============================================================================
   Action required (tasks) card — amber-tinted prominence
   ============================================================================ */
.home-card-tasks {
    border-color: #f0c674;
    background: #fffaf0;
    box-shadow: 0 1px 2px rgba(146, 64, 14, 0.06);
}
.home-tasks-eyebrow {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 700;
    color: #92400e;
    margin: 0;
    padding: 14px 22px 0;
    display: flex;
    align-items: center;
    gap: 6px;
}
.home-tasks-eyebrow::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: #d97706;
    box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.18);
}
.home-card-tasks .home-card-body { padding: 12px 22px 18px; }

.home-tasks-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.home-tasks-list a {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background: var(--surface, #fff);
    border: 1px solid #f3d69b;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text);
    transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}
.home-tasks-list a:hover {
    border-color: var(--brand);
    background: var(--brand-subtle, #f4f7fb);
}
.home-tasks-list a:active { transform: scale(0.998); }
.home-tasks-label { font-weight: 600; font-size: 14px; flex: 0 0 auto; color: var(--text); }
.home-tasks-meta { color: var(--text-muted); font-size: 13px; flex: 1 1 auto; text-align: right; }
.home-tasks-arrow { width: 16px; height: 16px; color: var(--brand); flex: 0 0 auto; }

/* All-clear card */
.home-card-clear {
    border-color: #c5e9c8;
    background: #f4faf5;
}
.home-card-clear .home-card-body {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 22px;
}
.home-card-clear-icon {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border-radius: 999px;
    background: #16a34a;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.12);
}
.home-card-clear-icon svg { width: 16px; height: 16px; }
.home-card-clear-text { font-weight: 500; font-size: 15px; color: #0e6b2a; line-height: 1.4; }

/* ============================================================================
   Claims card
   ============================================================================ */
.home-card-claims-count {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}
.home-card-claims { padding: 0; }
.home-card-claims .home-card-header { padding: 18px 22px; }

.home-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.home-table thead th {
    text-align: left;
    padding: 11px 22px;
    background: #f7f8fb;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    border-bottom: 1px solid var(--border);
}
.home-table thead th:first-child { padding-left: 22px; }
.home-table tbody tr {
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 100ms ease;
    box-shadow: inset 3px 0 0 transparent;
}
.home-table tbody tr:last-child { border-bottom: 0; }
.home-table tbody tr:not(.home-row-divider):hover {
    background: var(--brand-subtle, #f4f7fb);
}
.home-table tbody td {
    padding: 14px 22px;
    vertical-align: middle;
}
/* Status stripe at the left edge — instant scan signal */
.home-row-open[data-state="action"] { box-shadow: inset 3px 0 0 #d97706; }
.home-row-open[data-state="progress"] { box-shadow: inset 3px 0 0 #16a34a; }

.home-cell-id {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    color: var(--text-secondary);
    font-size: 13px;
    width: 100px;
    white-space: nowrap;
    font-weight: 500;
}
.home-cell-lender {
    color: var(--text);
    max-width: 320px;
}
.home-lender-name {
    display: block;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.home-lender-status {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 400;
}
.home-row-closed .home-lender-status { opacity: 0.8; }
.home-cell-agreement {
    color: var(--text-secondary);
    font-size: 13px;
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.home-cell-date {
    color: var(--text-secondary);
    font-size: 13px;
    white-space: nowrap;
}
/* Desktop: empty date cells render an em-dash placeholder */
.home-cell-date:empty::after { content: '—'; color: var(--text-muted); }
.home-cell-status { white-space: nowrap; }
.home-cell-chevron {
    width: 36px;
    text-align: right;
    color: var(--text-muted);
}
.home-cell-chevron svg { width: 14px; height: 14px; }

/* Closed claims — tinted background + desaturated text + grey left stripe
   that matches the amber/green stripe used on open rows. Selector includes
   the table tag so it beats the general `.home-table tbody tr` rule's
   transparent stripe. */
.home-table tbody tr.home-row-closed { background: #f7f8fa; box-shadow: inset 3px 0 0 #c5cad3; }
.home-row-closed .home-cell-lender { color: var(--text-secondary); font-weight: 500; }
.home-row-closed .home-cell-id,
.home-row-closed .home-cell-agreement,
.home-row-closed .home-cell-date { opacity: 0.7; }
.home-table tbody tr.home-row-closed:hover { background: #eef0f4; }

/* Divider row between active and closed claims */
.home-row-divider { cursor: default; }
.home-row-divider td {
    padding: 14px 22px 8px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--text-muted);
    background: #f7f8fb;
    border-bottom: 1px solid var(--border);
}

/* Status badges. Colour system:
     amber  = your attention needed
     green  = we're handling it, no action from you
     grey   = no longer active
*/
.home-badge {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
    display: inline-block;
    letter-spacing: 0.2px;
}
.home-badge-action {
    background: #fff4d6;
    color: #92400e;
    box-shadow: inset 0 0 0 1px rgba(146, 64, 14, 0.12);
}
.home-badge-progress {
    background: #ecfdf3;
    color: #047857;
    box-shadow: inset 0 0 0 1px rgba(4, 120, 87, 0.14);
}
.home-badge-closed {
    background: #f1f3f6;
    color: var(--text-secondary);
}

/* ============================================================================
   Contact card — grid of 3 fields + Edit button
   ============================================================================ */
.home-contact-fields {
    margin: 0;
    padding: 18px 22px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px 24px;
}
.home-contact-field { display: flex; flex-direction: column; min-width: 0; margin: 0; }
.home-contact-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    font-weight: 600;
    margin: 0 0 4px;
}
.home-contact-value {
    font-size: 14px;
    color: var(--text);
    word-break: break-word;
    line-height: 1.4;
    margin: 0;
}
.home-muted { color: var(--text-muted); font-style: italic; font-weight: 400; }

.home-contact-edit {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    color: var(--brand);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    text-decoration: none;
    white-space: nowrap;
    transition: background 120ms ease, border-color 120ms ease;
}
.home-contact-edit:hover {
    background: var(--brand-light);
    border-color: var(--brand);
}
.home-contact-edit svg { width: 12px; height: 12px; }

/* ============================================================================
   Mobile
   ============================================================================ */
@media (max-width: 719px) {
    .main-card.home-page { padding: 16px 12px 32px; }
    .home-page > * + * { margin-top: 16px; }
    .home-greeting h1 { font-size: 22px; }
    .home-subtitle { font-size: 14px; }
    .home-card-header { padding: 14px 16px; }
    .home-card-body { padding: 14px 16px; }

    .home-card-tasks .home-card-body { padding: 8px 16px 14px; }
    .home-tasks-eyebrow { padding: 12px 16px 0; font-size: 10px; }
    .home-tasks-list a { flex-wrap: wrap; padding: 12px 14px; gap: 8px; }
    .home-tasks-meta { flex: 1 1 100%; text-align: left; order: 3; }

    /* Contact fields stack tight */
    .home-contact-fields {
        grid-template-columns: 1fr;
        padding: 12px 16px 14px;
        gap: 10px;
    }
    .home-contact-value { font-size: 13.5px; }

    /* Claims table -> compact two-line rows via flex.
       Row 1 (visual): lender + status. Row 2: #id · agreement · date.
       DOM order doesn't matter — `order` controls layout. */
    .home-table thead { display: none; }
    .home-table, .home-table tbody { display: block; }
    .home-table tbody tr {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0 6px;
        padding: 10px 14px;
        border-bottom: 1px solid var(--border);
        box-shadow: inset 3px 0 0 transparent;
    }
    .home-row-open[data-state="action"] { box-shadow: inset 3px 0 0 #d97706; }
    .home-row-open[data-state="progress"] { box-shadow: inset 3px 0 0 #16a34a; }
    .home-row-closed { box-shadow: inset 3px 0 0 #c5cad3; }

    /* Pseudo line-break between row 1 (lender + status) and row 2 (meta) */
    .home-table tbody tr::before {
        content: '';
        flex-basis: 100%;
        height: 0;
        order: 3;
    }

    .home-table tbody td {
        display: inline-block;
        padding: 0;
        max-width: none;
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
    }
    /* Default mobile rule — hide auto-generated labels. Specific overrides
       below re-enable for the date columns where we want inline labels. */
    .home-table tbody td[data-label]::before { display: none; content: ''; }

    .home-table tbody td.home-cell-lender {
        order: 1;
        /* flex-basis: 0 so the cell doesn't grow to fit the verbatim status
           text — that text ellipsis-truncates inside instead, keeping the
           status badge on the same line. */
        flex: 1 1 0;
        font-size: 14px;
        font-weight: 600;
        color: var(--text);
        line-height: 1.3;
        min-width: 0;
        margin-bottom: 4px;
    }
    .home-row-closed .home-cell-lender { color: var(--text-secondary); font-weight: 500; }

    .home-table tbody td.home-cell-status {
        order: 2;
        flex: 0 0 auto;
        margin-bottom: 4px;
        margin-left: 8px;
    }

    /* Meta line — id + labeled dates inline. Loan start hidden on mobile
       (it's still on the claim detail page); only Opened + Closed labelled
       inline. Empty cells (—) are hidden so closed/open claims read cleanly. */
    .home-table tbody td.home-cell-id          { order: 4; }
    .home-table tbody td[data-label="Loan start"]   { display: none !important; }
    .home-table tbody td[data-label="Claim opened"] { order: 5; }
    .home-table tbody td[data-label="Claim closed"] { order: 6; }
    .home-table tbody td.home-cell-id,
    .home-table tbody td[data-label="Claim opened"],
    .home-table tbody td[data-label="Claim closed"] {
        flex: 0 0 auto;
        font-size: 11.5px;
        color: var(--text-muted);
        line-height: 1.4;
    }
    /* Inline-label dates on mobile so they read naturally.
       Use ::before for the closed separator (only appears when the cell
       has content) so we never end up with a dangling "·" after Opened. */
    .home-cell-id::after { content: ' · '; margin: 0 4px; opacity: 0.7; display: inline; }
    .home-table tbody td[data-label="Claim opened"]::before { content: 'Opened '; display: inline; }
    .home-table tbody td[data-label="Claim closed"]::before { content: ' · Closed '; display: inline; opacity: 0.85; }

    /* Hide empty dates ('—') so we don't show "Closed —" on open claims */
    .home-table tbody td[data-label="Claim opened"]:empty,
    .home-table tbody td[data-label="Claim closed"]:empty { display: none !important; }

    .home-table tbody td.home-cell-chevron { display: none !important; }

    /* Divider — still display: block, full width */
    .home-row-divider { display: block !important; padding: 0 !important; box-shadow: none !important; border-bottom: 1px solid var(--border); }
    .home-row-divider::before { content: none !important; }
    .home-row-divider td { display: block; padding: 10px 14px 4px; font-size: 10px; letter-spacing: 0.7px; }

    .home-row-divider { display: block; }
    .home-row-divider td {
        display: block;
        padding: 10px 14px 4px;
        font-size: 10px;
        letter-spacing: 0.7px;
    }
}

/* ============================================================================
   No-params welcome
   ============================================================================ */
.welcome-help {
    background: var(--brand-subtle, #f4f7fb);
    padding: 16px;
    border-radius: 8px;
    margin-top: 20px;
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.5;
}
.welcome-help a { color: var(--brand); }
