/* CD Business Tools — Brand Stylesheet */

/* Self-hosted fonts (variable woff2, latin + latin-ext). See static/fonts/. */
@font-face {
    font-family: 'Fraunces';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url(fonts/fraunces-latin.woff2) format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: 'Fraunces';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url(fonts/fraunces-latin-ext.woff2) format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url(fonts/inter-latin.woff2) format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url(fonts/inter-latin-ext.woff2) format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
    --bg: #f0ede6;
    --card-bg: #ffffff;
    --card-border: #e8e4d4;
    --accent-gold: #85754e;
    --accent-link: #6f613f;
    --text-primary: #161612;
    --text-secondary: #414135;
    --text-muted: #656553;
    --over-budget: #b91c1c;
    --on-budget: #166534;
    --font-stack: 'Inter', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.10), 0 2px 4px rgba(0,0,0,0.06);
}

/* Reset & base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font-stack);
    font-variant-numeric: tabular-nums;
    background: var(--bg);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--accent-link); text-decoration: none; }
a:hover { color: #51462e; text-decoration: underline; }

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

h1, h2, h3 {
    font-family: var(--font-display);
    letter-spacing: -0.01em;
    line-height: 1.15;
}

h1 { font-weight: 600; }

/* Header */
.header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--card-border);
    padding: 0.75rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-logo {
    width: 40px;
    height: 40px;
    background: var(--accent-gold);
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
}

.header-title {
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    color: var(--accent-gold);
    text-transform: uppercase;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.header-user a { color: var(--accent-link); }

/* Nav tabs */
.nav-tabs {
    background: var(--card-bg);
    border-bottom: 1px solid var(--card-border);
    padding: 0 2rem;
    display: flex;
    gap: 0;
}

.nav-tab {
    padding: 0.75rem 1.25rem;
    font-size: 0.9rem;
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 2.5px solid transparent;
    transition: color 0.2s ease, border-color 0.25s ease, background 0.2s ease;
}

.nav-tab:hover {
    color: var(--text-primary);
    text-decoration: none;
    background: rgba(133, 117, 78, 0.04);
}

.nav-tab.active {
    color: var(--accent-gold);
    border-bottom-color: var(--accent-gold);
    font-weight: 600;
}

/* Main content */
.main-content {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 2rem;
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.25s ease, transform 0.2s ease;
}

.card a:only-child:hover,
.card[onclick]:hover,
.card.card-interactive:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-1px);
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

/* Metrics */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.metric-card {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 1.25rem;
    text-align: center;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.25s ease;
}

.metric-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.metric-value {
    font-family: var(--font-display);
    font-size: 2.1rem;
    font-weight: 600;
    color: var(--accent-gold);
    letter-spacing: -0.01em;
}

.metric-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--card-border);
}

th {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

td { color: var(--text-secondary); }

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

/* Buttons */
.btn-primary, .btn-secondary {
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 36px;
    line-height: 1;
    box-sizing: border-box;
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent-gold);
    color: #fff;
    border: 1px solid var(--accent-gold);
    transition: background 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
}

.btn-primary:hover { background: #76664a; text-decoration: none; color: #fff; box-shadow: 0 1px 4px rgba(133, 117, 78, 0.25); }
.btn-primary:active { background: #65573f; transform: translateY(1px); box-shadow: none; }
.btn-primary:disabled, .btn-primary.disabled {
    opacity: 0.5; cursor: not-allowed; pointer-events: none;
}

.btn-secondary {
    background: transparent;
    color: var(--accent-gold);
    border: 1px solid var(--accent-gold);
    transition: background 0.2s ease, transform 0.1s ease;
}

.btn-secondary:hover { background: rgba(133, 117, 78, 0.08); text-decoration: none; }
.btn-secondary:active { background: rgba(133, 117, 78, 0.15); transform: translateY(1px); }
.btn-secondary:disabled, .btn-secondary.disabled {
    opacity: 0.5; cursor: not-allowed; pointer-events: none;
}

.btn-sm { height: 36px; padding: 0.4rem 0.75rem; font-size: 0.8rem; }

.btn-destructive {
    color: #991b1b;
    border-color: #b91c1c;
}

.btn-destructive:hover { background: #fef2f2; color: #7f1d1d; }

/* Accordion */
.accordion-section { margin-bottom: 0.75rem; }

.accordion-toggle {
    width: 100%;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    transition: background 0.15s;
}

.accordion-toggle:hover { background: #faf8f3; }

.accordion-toggle .accordion-arrow {
    transition: transform 0.2s;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.accordion-content {
    display: none;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-top: none;
    border-radius: 0 0 8px 8px;
    padding: 1.25rem;
}

.accordion-section.open .accordion-toggle {
    border-radius: 8px 8px 0 0;
}

.accordion-section.open .accordion-content { display: block; }

.accordion-section.open .accordion-arrow { transform: rotate(180deg); }

.accordion-badge {
    background: var(--accent-gold);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    margin-left: 0.5rem;
}

.accordion-badge-alert {
    background: var(--on-budget);
}

/* Forms */
.form-group { margin-bottom: 1rem; }

.form-grid { display: grid; gap: 0.75rem; }
.form-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-actions { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.checkbox-row { display: flex; align-items: center; gap: 0.55rem; margin-bottom: 1rem; color: var(--text-secondary); }
.checkbox-row input { width: 18px; height: 18px; }

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--card-border);
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: var(--font-stack);
    background: var(--card-bg);
    color: var(--text-primary);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent-gold);
    box-shadow: 0 0 0 2px rgba(133, 117, 78, 0.15);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent-gold);
    box-shadow: 0 0 0 2px rgba(133, 117, 78, 0.15);
}

a:focus-visible,
button:focus-visible,
summary:focus-visible {
    outline: 2px solid rgba(133, 117, 78, 0.55);
    outline-offset: 2px;
}

/* Contacts directory */
.page-heading {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-end;
    margin-bottom: 1rem;
}

.page-heading p { color: var(--text-muted); margin-top: 0.35rem; }

.contact-toolbar {
    background: var(--card-bg);
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
    padding: 1rem;
    margin-bottom: 1rem;
}

.search-field { position: relative; }
.search-field svg {
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    pointer-events: none;
}

.search-field input {
    width: 100%;
    min-height: 44px;
    padding: 0.7rem 0.85rem 0.7rem 2.65rem;
    border: 1px solid var(--card-border);
    border-radius: 7px;
    font: inherit;
    color: var(--text-primary);
}

.filter-tabs { display: flex; gap: 0.5rem; margin-top: 0.75rem; flex-wrap: wrap; }
.filter-tab {
    min-height: 36px;
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--card-border);
    border-radius: 999px;
    background: var(--card-bg);
    color: var(--text-secondary);
    font: 600 0.85rem/1 var(--font-stack);
    cursor: pointer;
}
.filter-tab span { color: var(--text-muted); margin-left: 0.25rem; }
.filter-tab:hover { border-color: var(--accent-gold); background: #faf8f3; }
.filter-tab.active { background: var(--accent-gold); border-color: var(--accent-gold); color: #fff; }
.filter-tab.active span { color: #fff; }

.contact-panel {
    background: var(--card-bg);
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
    padding: 1.25rem;
}

.section-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}
.section-heading h2 { font-size: 1.2rem; }
.section-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.contact-add { position: relative; }
.contact-add > summary { list-style: none; cursor: pointer; }
.contact-add > summary::-webkit-details-marker { display: none; }
.contact-add-form {
    position: absolute;
    right: 0;
    top: calc(100% + 0.5rem);
    z-index: 20;
    width: min(680px, calc(100vw - 3rem));
    margin: 0;
    border: 1px solid var(--card-border);
    box-shadow: var(--shadow-lg);
}

.directory-list { display: grid; gap: 0.65rem; }
.directory-card {
    display: grid;
    grid-template-columns: minmax(180px, 1.2fr) minmax(220px, 1fr) auto;
    align-items: center;
    gap: 1rem;
    padding: 0.8rem 0;
    border-bottom: 1px solid var(--card-border);
}
.directory-card:last-child { border-bottom: 0; }
.directory-primary, .directory-details { display: flex; flex-direction: column; align-items: flex-start; gap: 0.15rem; min-width: 0; }
.directory-primary > span, .cell-secondary { color: var(--text-muted); font-size: 0.85rem; display: block; }
.directory-details a { overflow-wrap: anywhere; }
.role-badges { display: inline-flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.2rem; }
.role-badge {
    display: inline-flex;
    border-radius: 999px;
    padding: 0.12rem 0.45rem;
    background: #f1ede3;
    color: #5f5132;
    font-size: 0.72rem;
    font-weight: 650;
}
.row-actions { display: flex; justify-content: flex-end; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.row-actions form { margin: 0; }
.directory-table td:last-child { width: 1%; white-space: nowrap; }
.directory-table .role-badges { display: flex; }
.status-text { color: var(--text-muted); font-weight: 600; }
.status-text-success { color: var(--on-budget); }
.directory-empty { text-align: center; margin-top: 1rem; }
.directory-empty p { color: var(--text-muted); margin-bottom: 0.75rem; }

/* Alerts */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.alert-success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.alert-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-info {
    background: #f8f7f3;
    color: var(--text-secondary);
    border: 1px solid var(--card-border);
}

/* Login page */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
}

.login-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 3rem;
    text-align: center;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
}

.login-logo {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--accent-gold);
    margin-bottom: 0.5rem;
}

.login-subtitle {
    font-size: 1rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.login-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    text-decoration: none;
    transition: box-shadow 0.15s, border-color 0.15s;
}

.login-btn:hover {
    border-color: var(--accent-gold);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    text-decoration: none;
}

.login-btn svg { width: 20px; height: 20px; }

.login-footnote {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 1.5rem;
}

/* Budget-specific */
.over-budget { color: var(--over-budget); font-weight: 600; }
.on-budget { color: var(--on-budget); font-weight: 600; }

/* Project tabs */
.project-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--card-border);
    margin-bottom: 1.5rem;
}
.project-tab {
    padding: 0.75rem 1.25rem;
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 500;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s;
}
.project-tab:hover {
    color: var(--text-primary);
    text-decoration: none;
}
.project-tab.active {
    color: var(--accent-gold);
    border-bottom-color: var(--accent-gold);
}
.tab-badge {
    background: var(--accent-gold);
    color: #fff;
    font-size: 0.7rem;
    padding: 0.1rem 0.45rem;
    border-radius: 10px;
    margin-left: 0.35rem;
    vertical-align: middle;
}
.tab-content {
    min-height: 200px;
}

/* Status chips */
.status-chip {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    border: 1px solid transparent;
}

.status-received {
    background: #fff7ed;
    color: #9a3412;
    border-color: #fed7aa;
}

.status-reviewed {
    background: #fef9c3;
    color: #854d0e;
    border-color: #fde68a;
}

.status-bundled,
.status-orphaned,
.status-complete {
    background: #f4f3ef;
    color: var(--text-muted);
    border-color: var(--card-border);
}

.status-sent,
.status-active,
.status-issued {
    background: #dcfce7;
    color: #166534;
    border-color: #bbf7d0;
}

/* A statement being edited is hidden from the client portal until it is
   reissued. Slate keeps it distinct from Received's orange — every status in
   this set owns exactly one colour. */
.status-editing {
    background: #eef2f6;
    color: #334155;
    border-color: #cbd5e1;
}

/* Budget: invoices entered but not yet counted in Paid to Date.
   Deliberately neutral — the gold border in this app means "action required"
   (see the ready-to-bundle card), and this note is informational. */
.budget-unbundled-notice {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: #f4f3ef;
    border: 1px solid var(--card-border);
    border-left: 3px solid var(--text-muted);
    border-radius: 8px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.budget-unbundled-notice > [data-lucide] { color: var(--text-muted); }

@media (max-width: 640px) {
    .budget-unbundled-notice { align-items: flex-start; flex-wrap: wrap; }
}

/* Native modal dialogs. Sized to the viewport so a form works on a phone. */
.app-dialog {
    width: min(560px, calc(100vw - 2rem));
    max-height: calc(100vh - 3rem);
    overflow-y: auto;
    padding: 1.25rem;
    border: 1px solid var(--card-border);
    border-radius: 10px;
    background: var(--card-bg);
    color: var(--text-primary);
    box-shadow: var(--shadow-lg);
}

.app-dialog::backdrop { background: rgba(22, 22, 18, 0.45); }

.app-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1rem;
}

@media (max-width: 640px) {
    .app-dialog { padding: 1rem; }
    /* Stack the two-column form so nothing is cut off on a narrow screen. */
    .app-dialog form > div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
    .app-dialog-actions { flex-direction: column-reverse; }
    .app-dialog-actions .btn-primary,
    .app-dialog-actions .btn-secondary { width: 100%; }
}

/* Budget table */
.budget-section {
    margin-bottom: 1.5rem;
}
.budget-table {
    width: 100%;
    font-size: 0.85rem;
    /* Fixed layout + uniform column widths so the separate section tables and the
       PROJECT TOTAL totals-bar table line their money columns up exactly. */
    table-layout: fixed;
}
.budget-table th:nth-child(1), .budget-table td:nth-child(1) { width: 72px; }    /* Code */
.budget-table th:nth-child(3), .budget-table td:nth-child(3) { width: 150px; }   /* Allowance */
.budget-table th:nth-child(4), .budget-table td:nth-child(4) { width: 130px; }   /* Paid */
.budget-table th:nth-child(5), .budget-table td:nth-child(5) { width: 130px; }   /* Balance */
.budget-table th:nth-child(6), .budget-table td:nth-child(6) { width: 44px; }    /* actions */
.budget-table th {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
}
.budget-table td[data-editable] {
    cursor: pointer;
    border: 1px solid #ebe8df;
    border-radius: 4px;
    background: #fdfcfa;
    transition: background-color 0.3s ease, border-color 0.15s;
}

.budget-table td[data-editable]:hover {
    border-color: var(--accent-gold);
    box-shadow: 0 0 0 2px rgba(133, 117, 78, 0.12);
    background: rgba(133, 117, 78, 0.08);
}

.budget-table td[data-editable].edit-success {
    background: #dcfce7;
}

.budget-table td[data-editable].edit-error {
    background: #fef2f2;
}
.inline-edit {
    width: 100%;
    padding: 0.2rem 0.3rem;
    border: 1px solid var(--accent-gold);
    border-radius: 3px;
    font-size: 0.85rem;
    background: var(--card-bg);
    color: var(--text-primary);
}
.pm-fee-row td, .grand-total-row td {
    padding: 0.5rem 0.75rem;
}
.grand-total-row {
    font-size: 1.05rem;
    border-top: 2px solid var(--accent-gold);
}
.budget-totals-bar {
    margin-top: 1rem;
    border-top: 2px solid var(--card-border);
}

/* Over-budget row */
.over-budget-row {
    background: #fef2f2;
}
.over-budget-row td {
    border-bottom-color: #fecaca;
}
.over-budget-icon {
    color: var(--over-budget);
    vertical-align: middle;
    margin-right: 0.25rem;
}

/* Confidence chips */
.confidence-chip {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}
.confidence-chip[data-level="firm"] {
    background: #dcfce7; color: #166534;
}
.confidence-chip[data-level="reasonable"] {
    background: #e0f2fe; color: #075985;
}
.confidence-chip[data-level="placeholder"] {
    background: #f3e8ff; color: #6b21a8;
}
.confidence-chip[data-level="uncertain"] {
    background: #fff7ed; color: #9a3412;
}

/* Budget section header improvements */
.budget-section-header {
    font-size: 0.95rem;
    color: var(--text-primary);
    padding: 0.7rem 1rem;
    background: var(--card-bg);
    border-left: 3px solid var(--accent-gold);
    border-radius: 6px 6px 0 0;
    box-shadow: var(--shadow-sm);
    border-bottom: none;
    margin-bottom: 0;
}

.budget-section-header .section-total-display {
    font-size: 0.8rem;
    color: var(--accent-gold);
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* Budget table number formatting */
.budget-table td:nth-child(3),
.budget-table td:nth-child(4),
.budget-table td:nth-child(5) {
    font-variant-numeric: tabular-nums;
}

.budget-table td:nth-child(2) {
    font-weight: 500;
}

.budget-table td:nth-child(1) {
    color: var(--text-muted);
}

.budget-table thead tr {
    background: #faf9f6;
}

.budget-table thead th {
    border-bottom: 2px solid var(--card-border);
}

.budget-table tbody td {
    border-bottom: 1px solid #f0ede6;
    padding: 0.5rem 0.6rem;
}

.section-total-row {
    background: #faf9f6;
    font-weight: 600;
    border-top: 2px solid var(--card-border);
}
.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0.1rem;
    opacity: 0.5;
}
.btn-icon:hover {
    opacity: 1;
}
/* Collapsible budget sections — toggled via JS */

/* Toast notifications */
#toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 380px;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    padding: 0.85rem 1rem;
    box-shadow: var(--shadow-lg);
    transition: opacity 0.3s, transform 0.3s;
    animation: toast-in 0.3s ease-out;
}

.toast-success { border-left: 4px solid var(--on-budget); }
.toast-error { border-left: 4px solid var(--over-budget); }
.toast-info { border-left: 4px solid var(--accent-gold); }

.toast-icon { font-size: 1.1rem; line-height: 1; margin-top: 2px; }
.toast-body { flex: 1; }
.toast-title { font-weight: 600; font-size: 0.85rem; color: var(--text-primary); }
.toast-subtitle { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }
.toast-close {
    background: none;
    border: none;
    font-size: 1.1rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.5rem;
    line-height: 1;
}

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

/* Confirmation modal */
.confirm-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.confirm-modal {
    background: var(--card-bg);
    border-radius: 10px;
    padding: 1.5rem;
    max-width: 400px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.confirm-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #fef2f2;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 0.75rem;
}

.confirm-icon i { color: var(--over-budget); }

.confirm-title {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.35rem;
}

.confirm-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1.25rem;
}

.confirm-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.btn-danger {
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid #ef4444;
    background: #ef4444;
    color: #fff;
    transition: background 0.15s;
}

.btn-danger:hover { background: #dc2626; }

/* Mobile navigation */
.nav-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--accent-gold);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
}

.header-logo-img { height: 56px; width: auto; }
.header-logo-text { display: none; }
.nav-user-mobile { display: none; }

@media (max-width: 768px) {
    .nav-toggle { display: block; }
    .header-user { display: none; }
    .header-logo-img { height: 36px; }
    .header-logo-text {
        display: inline;
        font-size: 0.9rem;
        font-weight: 600;
        color: var(--accent-gold);
        letter-spacing: 0.05em;
    }
    .header { padding: 0.5rem 1rem; }

    .nav-tabs {
        display: none;
        flex-direction: column;
        padding: 0;
    }
    .nav-tabs.nav-menu-open { display: flex; }
    .nav-tab {
        padding: 0.85rem 1.25rem;
        border-bottom: none;
        border-left: 3px solid transparent;
    }
    .nav-tab:hover { background: rgba(133, 117, 78, 0.05); }
    .nav-tab.active {
        border-bottom: none;
        border-left-color: var(--accent-gold);
        background: rgba(133, 117, 78, 0.05);
    }

    .nav-user-mobile {
        display: flex;
        gap: 1rem;
        padding: 0.85rem 1.25rem;
        border-top: 1px solid var(--card-border);
        font-size: 0.85rem;
        color: var(--text-muted);
        margin-top: 0.25rem;
    }
    .nav-user-mobile a { color: var(--accent-link); }

    /* Toast: full width on mobile */
    #toast-container {
        right: 0;
        left: 0;
        max-width: 100%;
        padding: 0 0.75rem;
    }
}

/* Responsive layout */
@media (max-width: 768px) {
    .main-content {
        padding: 0 1rem;
        margin: 1rem auto;
    }

    /* Stack all 2-column form grids to single column */
    [style*="grid-template-columns: 1fr 1fr"],
    [style*="grid-template-columns:1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Dashboard metrics grid: single column */
    .metrics-grid {
        grid-template-columns: 1fr;
    }

    /* Tables: horizontal scroll wrapper */
    .card > table,
    .tab-content table,
    .budget-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Buttons: ensure minimum tap target */
    .btn-primary, .btn-secondary {
        min-height: 44px;
        padding: 0.6rem 1rem;
    }
    .btn-sm {
        min-height: 36px;
        padding: 0.4rem 0.75rem;
    }

    /* Forms: larger touch targets */
    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 0.75rem;
        font-size: 1rem;
        min-height: 44px;
    }

    /* Card padding tighter */
    .card { padding: 1rem; }

    /* Project tabs: scrollable on mobile */
    .project-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Action item rows: stack on small screens */
    h1 { font-size: 1.4rem; }
    h2 { font-size: 1.1rem; }

    .form-grid-2 { grid-template-columns: 1fr; }
    .contact-panel { padding: 1rem; }
    .directory-card { grid-template-columns: 1fr; gap: 0.55rem; }
    .directory-card .row-actions { justify-content: flex-start; }
    .contact-add-form {
        position: fixed;
        left: 0.75rem;
        right: 0.75rem;
        top: 4.5rem;
        width: auto;
        max-height: calc(100vh - 5.5rem);
        overflow-y: auto;
    }
    .filter-tabs { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 0.15rem; }
    .filter-tab { flex: 0 0 auto; min-height: 44px; }
}

@media (max-width: 480px) {
    .main-content {
        padding: 0 0.75rem;
        margin: 0.75rem auto;
    }

    .form-group input,
    .form-group select {
        font-size: 16px; /* Prevents iOS zoom on focus */
    }

    .card { padding: 0.75rem; }

    .metric-value { font-size: 1.5rem; }
}

/* Table scroll hint — right fade */
.table-scroll-wrapper {
    position: relative;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-scroll-wrapper::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 24px;
    background: linear-gradient(to right, transparent, var(--bg));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
}

@media (max-width: 768px) {
    .table-scroll-wrapper::after { opacity: 1; }
}

/* PDF viewer — mobile vs desktop */
.pdf-mobile { display: none; text-align: center; padding: 1.5rem; }
.pdf-embed { display: block; }

@media (max-width: 768px) {
    .pdf-mobile { display: block; }
    .pdf-embed { display: none; }
}

/* Button loading state */
.btn-loading {
    pointer-events: none;
    opacity: 0.7;
    gap: 0.5rem;
}

.btn-spinner {
    display: none;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.btn-loading .btn-spinner { display: inline-block; }
.btn-loading .btn-text { display: none; }
.btn-loading .btn-loading-text { display: inline; }

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

/* Photo grid responsive */
@media (max-width: 768px) {
    .photo-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* Budget v2 Excel-faithful layout */
.budget-row-reserved td { color: var(--text-muted); background: rgba(0,0,0,0.02); font-style: italic; }
.budget-row-reserved .reserved-placeholder { color: var(--text-muted); }
.budget-notes-row td { background: #faf9f6; color: var(--text-secondary); font-size: 0.85rem; }
.budget-notes-row [data-editable="notes"] { cursor: pointer; }
.budget-accordion-controls { display: flex; justify-content: flex-end; gap: 0.5rem; margin: -0.35rem 0 0.75rem; }
.budget-section-accordion { border: 1px solid var(--card-border); border-radius: 8px; margin-bottom: 0.65rem; overflow: hidden; background: var(--card-bg); }
.budget-section-accordion > summary { display: flex; align-items: center; gap: 1rem; padding: 0.8rem 1rem; cursor: pointer; list-style: none; background: rgba(0,0,0,0.025); }
.budget-section-accordion > summary::-webkit-details-marker { display: none; }
.budget-section-accordion > summary::before { content: "›"; font-size: 1.3rem; color: var(--text-muted); transition: transform 0.15s ease; }
.budget-section-accordion[open] > summary::before { transform: rotate(90deg); }
.budget-section-accordion[open] > summary { border-bottom: 1px solid var(--card-border); }
.budget-section-title { flex: 1; font-weight: 650; }
.budget-section-summary-money { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.25rem; text-align: right; flex: 0 1 520px; width: min(520px, 55%); }
.budget-section-summary-money span { display: flex; flex-direction: column; }
.budget-section-summary-money small { color: var(--text-muted); font-size: 0.68rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.03em; }
.budget-section-summary-money strong { font-size: 0.85rem; }
.budget-section-content { padding: 0.25rem 0.75rem 0.75rem; }
.budget-project-total { display: flex; align-items: center; gap: 1rem; padding: 0.9rem 1.75rem 0.65rem; border-top: 3px solid var(--accent-gold); }
.budget-project-total-title { flex: 1; font-size: 1.05rem; }
.budget-project-total-money { font-size: 1.05rem; }
@media (max-width: 700px) {
    .budget-section-accordion > summary { align-items: flex-start; gap: 0.5rem; padding: 0.7rem; }
    .budget-section-summary-money { grid-template-columns: 1fr; gap: 0.15rem; width: 52%; flex-basis: 52%; }
    .budget-section-summary-money span { flex-direction: row; justify-content: space-between; gap: 0.5rem; }
    .budget-section-content { padding: 0 0.25rem 0.5rem; overflow-x: auto; }
    .budget-project-total { align-items: flex-start; padding: 0.75rem; }
}
.budget-subsection-header td { background: rgba(0,0,0,0.03); font-weight: 600; padding-top: 0.5rem; padding-bottom: 0.5rem; }
div.pm-fee-row { display: flex; align-items: center; gap: 0.75rem; padding: 0.6rem 0.75rem; border-top: 1px solid var(--card-border); border-bottom: 1px solid var(--card-border); margin: 0.5rem 0; }
.pm-fee-row .pm-fee-code { font-family: ui-monospace, monospace; color: var(--text-muted); width: 70px; }
.pm-fee-row .pm-fee-label { flex: 1; }
.pm-fee-row .pm-fee-suggestion { color: var(--text-muted); font-size: 0.85rem; }
.pm-fee-row .pm-fee-allowance { font-weight: 600; min-width: 130px; text-align: right; cursor: pointer; }
.combined-total-row { display: flex; justify-content: space-between; padding: 0.5rem 0.75rem; font-weight: 600; border-top: 2px solid var(--card-border); margin: 0.75rem 0; }

/* Help tips (toggle in Settings; hidden when html.help-tips-off) */
.help-tip {
    display: inline-flex; align-items: center; justify-content: center;
    width: 16px; height: 16px; border-radius: 50%;
    background: rgba(133, 117, 78, 0.16); color: var(--accent-gold);
    font-size: 11px; font-weight: 700; font-family: var(--font-stack);
    line-height: 1; cursor: help; position: relative;
    vertical-align: 2px; margin-left: 0.45rem; user-select: none; flex-shrink: 0;
}
.help-tip:focus-visible { outline: 2px solid var(--accent-gold); outline-offset: 2px; }
.help-tip::after {
    content: attr(data-tip);
    /* Left-anchored (grows rightward) so bubbles on headings near the page edge never clip offscreen. */
    position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-18px);
    background: var(--text-primary); color: #fdfcf9;
    padding: 0.5rem 0.7rem; border-radius: 6px;
    font-size: 0.78rem; font-weight: 400; line-height: 1.45; letter-spacing: 0;
    width: max-content; max-width: 260px; text-align: left; white-space: normal;
    text-transform: none; box-shadow: var(--shadow-lg);
    opacity: 0; pointer-events: none; transition: opacity 0.15s ease;
    z-index: 200;
}
.help-tip::before {
    content: ''; position: absolute; bottom: calc(100% + 3px); left: 50%; transform: translateX(-50%);
    border: 5px solid transparent; border-top-color: var(--text-primary);
    opacity: 0; pointer-events: none; transition: opacity 0.15s ease; z-index: 200;
}
.help-tip:hover::after, .help-tip:focus-visible::after,
.help-tip:hover::before, .help-tip:focus-visible::before { opacity: 1; }
html.help-tips-off .help-tip { display: none; }
@media (max-width: 640px) {
    .help-tip::after { max-width: 200px; }
}

/* Invoice reading panel on the Upload Invoice form */
#invoice-read-panel, #timecard-panel { margin: 0 0 0.75rem; padding: 0.6rem 0.75rem; border: 1px solid var(--border, #d9d9d9); border-radius: 6px; font-size: 0.9rem; }
#invoice-read-panel .read-status, #timecard-panel .read-status { color: var(--text-muted, #666); }
#invoice-read-panel ul, #timecard-panel ul { margin: 0.4rem 0 0; padding-left: 1.1rem; }
#invoice-read-panel li, #timecard-panel li { margin: 0.2rem 0; }
#invoice-read-panel li.flag-problem, #timecard-panel li.flag-problem { color: #b3261e; font-weight: 600; }
#invoice-read-panel li.flag-warning, #timecard-panel li.flag-warning { color: #8a5a00; }
#invoice-read-panel li.flag-info, #timecard-panel li.flag-info { color: var(--text-muted, #666); }
#invoice-read-panel details, #timecard-panel details { margin-top: 0.4rem; }
.ai-filled { background: #fff8d6 !important; }

/* An invoice waiting for the contractor to send a corrected one */
.status-hold { background: #fdecc8; color: #7a4f00; }

/* Role picker for each worker on a timecard (upload page) */
.worker-role-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.2rem 0; }
.worker-role-row select { font-size: 0.85rem; padding: 0.15rem 0.3rem; min-width: 9rem; }

/* "Is this the corrected invoice?" on the upload page */
.replace-choice { margin-top: 0.5rem; padding: 0.5rem 0.75rem; border-left: 3px solid #b8860b; background: rgba(184, 134, 11, 0.06); border-radius: 4px; }
.replace-choice select { margin-top: 0.35rem; max-width: 100%; }

/* Contracts and progress draws */
.contracts-table th.num, .contracts-table td.num { text-align: right; white-space: nowrap; }
.contracts-table td { vertical-align: top; }
.contracts-table tfoot td { border-top: 2px solid var(--border-color, #e8e4d4); }
.contract-sub { font-size: 0.78rem; color: var(--text-muted); font-weight: normal; margin-top: 0.15rem; }
.contract-bar { height: 8px; border-radius: 999px; background: #eee9dc; overflow: hidden; }
.contract-bar span { display: block; height: 100%; background: var(--accent-gold, #85754e); border-radius: 999px; }
.contract-over .contract-bar span { background: #b3261e; }
.contract-bar-big { height: 12px; margin: 0.25rem 0 0.5rem; }
.contract-over-text { color: #b3261e; font-weight: 600; }
.contract-alert { border-left: 4px solid #b3261e; background: #fdf3f2; }
.contract-change-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: flex-end; margin-top: 0.75rem; }
.contract-change-form .form-group { margin-bottom: 1rem; }
.contract-metrics { margin-bottom: 0.5rem; }
.contract-metrics .metric-value { font-size: 1.5rem; }
.invoice-contract { border-left: 4px solid var(--accent-gold, #85754e); }
.invoice-contract.over { border-left-color: #b3261e; }
.contract-line-phone { display: none; }
@media (max-width: 640px) {
    .contracts-table .contract-line { display: none; }
    .contracts-table .contract-line-phone { display: block; }
    .contracts-table th, .contracts-table td { padding-left: 0.5rem; padding-right: 0.5rem; }
    .contracts-table th:last-child, .contracts-table td:last-child { display: none; }   /* progress bar; % shows on the contract page */
}
