/* ── JOB CARDS ── */
.job-section {
    margin-bottom: 28px;
}

.job-section-divider {
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 6px 0 14px;
}

.job-section-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, rgba(27,51,80,0.32), rgba(27,51,80,0.08));
}

.job-section-label {
    font-family: 'Bebas Neue', sans-serif;
    font-size: 18px;
    letter-spacing: 1.2px;
    color: var(--navy);
    white-space: nowrap;
}

.doc-groups {
    display: grid;
    gap: 14px;
}

.doc-group {
    display: grid;
    gap: 8px;
}

.doc-group-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--gray-3);
}

.doc-links {
    display: grid;
    gap: 8px;
}

.doc-link-row {
    display: flex;
    align-items: stretch;
    gap: 8px;
}

.doc-link {
    display: inline-flex;
    align-items: center;
    flex: 1;
    padding: 6px 10px;
    border-radius: 999px;
    background: #EFF6FF;
    color: var(--blue);
    text-decoration: none;
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid rgba(41,104,166,0.16);
}

.doc-link:hover {
    background: #DBEAFE;
}

.doc-link-ext {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    min-width: 34px;
    border-radius: 999px;
    background: #F7F9FC;
    color: var(--navy);
    border: 1px solid rgba(41,104,166,0.16);
    text-decoration: none;
    font-size: 14px;
    font-weight: 700;
}

.doc-link-ext:hover {
    background: #E9EFF7;
}

.doc-card-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(248,250,252,0.96));
    box-shadow: 0 6px 18px rgba(15, 27, 45, 0.06);
}
.doc-card-name {
    min-width: 0;
    color: var(--navy);
    font-size: 14px;
    font-weight: 700;
    line-height: 1.25;
    text-decoration: none;
    overflow-wrap: anywhere;
}
.doc-card-name:hover {
    color: var(--blue);
    text-decoration: underline;
}
.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}
.photo-card-row {
    position: relative;
    display: grid;
    gap: 8px;
    padding: 10px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(248,250,252,0.96));
    box-shadow: 0 6px 18px rgba(15, 27, 45, 0.06);
}
.photo-card-thumb {
    width: 100%;
    aspect-ratio: 4 / 3;
    border: 0;
    border-radius: 10px;
    background: var(--gray-1);
    background-size: cover;
    background-position: center;
    cursor: pointer;
    box-shadow: inset 0 0 0 1px rgba(15, 27, 45, 0.12);
    overflow: hidden;
    padding: 0;
    position: relative;
}
.photo-card-badge {
    position: absolute;
    left: 6px;
    bottom: 6px;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(15, 27, 45, 0.78);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    pointer-events: none;
}
.photo-card-badge-cover {
    background: #1F3A5F;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.18);
}
.photo-card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.photo-card-name {
    color: var(--text-lt);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    line-height: 1.3;
    text-align: center;
    min-height: 1.3em;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.photo-card-name:empty {
    display: none;
}
.photo-card-row .doc-link-ext {
    position: absolute;
    right: 16px;
    top: 16px;
    background: rgba(255,255,255,0.92);
}
[data-theme="dark"] .doc-card-row,
[data-theme="dark"] .photo-card-row {
    background: linear-gradient(180deg, rgba(26, 35, 50, 0.98), rgba(18, 28, 44, 0.96));
    border-color: #2D3A4D;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}
[data-theme="dark"] .doc-card-row:hover,
[data-theme="dark"] .photo-card-row:hover {
    border-color: #3B4B62;
}
[data-theme="dark"] .doc-card-name {
    color: #89BCF8;
}
[data-theme="dark"] .photo-card-name {
    color: #B6BEC9;
}
[data-theme="dark"] .photo-card-row .doc-link-ext {
    background: rgba(10, 18, 32, 0.88);
}

.section-edit-cta {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}

.section-edit-block {
    border: 1px solid rgba(41,104,166,0.16);
    background: #F8FBFF;
    border-radius: 10px;
    padding: 16px;
}

.close-card-block {
    display: flex;
    justify-content: center;
    padding-top: 4px;
}

/* Match the floating CLOSE pill exactly: same blue outline + text on a
   surface fill with a soft shadow, same height/font/spacing — body-bottom
   close and top-right floating close are visually the same control. */
.close-card-btn {
    min-width: 160px;
    height: 30px;
    padding: 0 18px;
    background: var(--surface, var(--white));
    border: 1px solid var(--blue);
    border-radius: 5px;
    color: var(--blue);
    font-family: 'DM Sans', sans-serif;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(15, 27, 45, 0.18);
    transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.12s, box-shadow 0.18s;
}
.close-card-btn:hover {
    background: var(--blue);
    color: var(--white);
    box-shadow: 0 6px 18px rgba(46, 117, 182, 0.32);
}
.close-card-btn:active { transform: scale(0.96); }
[data-theme="dark"] .close-card-btn {
    background: #1A2332;
    border-color: #6AAAF0;
    color: #6AAAF0;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
}
[data-theme="dark"] .close-card-btn:hover {
    background: #6AAAF0;
    color: var(--navy);
    box-shadow: 0 6px 18px rgba(106, 170, 240, 0.32);
}

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

.doc-import-btn-secondary {
    background: #EFF3F8;
    color: var(--navy);
    border: 1px solid rgba(27,51,80,0.16);
}

.doc-import-btn-secondary:hover {
    background: #E3EAF3;
}

.doc-import-btn-compact {
    height: 24px;
    padding: 0 8px;
    font-size: 11px;
}

.payment-row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

/* ── Document reference links & popover ── */
.doc-ref-link {
    color: var(--blue);
    cursor: pointer;
    font-weight: 600;
    font-size: 12px;
    border-bottom: 1px dashed var(--blue);
    padding-bottom: 1px;
}
.doc-ref-link:hover {
    color: var(--navy);
    border-bottom-color: var(--navy);
}
.doc-ref-generate {
    color: var(--gray-3);
    cursor: pointer;
    font-size: 11px;
    font-weight: 500;
}
.doc-ref-generate:hover {
    color: var(--blue);
}
.doc-ref-cell {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.doc-ref-popover {
    position: absolute;
    z-index: 1000;
    background: var(--white);
    border: 1px solid var(--gray-2);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    padding: 6px 0;
    min-width: 120px;
}
.doc-ref-popover .popover-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--gray-3);
    padding: 4px 14px 6px;
    border-bottom: 1px solid var(--gray-1);
    letter-spacing: 0.3px;
}
.popover-action {
    display: block;
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 500;
    color: var(--navy);
    text-decoration: none;
    cursor: pointer;
}
.popover-action:hover {
    background: #EDF1F7;
}
.popover-empty {
    display: block;
    padding: 7px 14px;
    font-size: 12px;
    color: var(--gray-3);
}

.schedule-select-col {
    width: 36px;
}

.schedule-select {
    width: 16px;
    height: 16px;
}

.invoice-review-check {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
}

.invoice-builder-block {
    align-items: flex-start;
}

.invoice-builder-controls {
    display: grid;
    gap: 8px;
    flex: 1;
}

.invoice-builder-list {
    flex: 1;
}

/* ── NEW JOB MODAL ── */
#new-job-modal .doc-modal-box {
    max-height: 85vh;
    overflow-y: auto;
    border-radius: 12px;
    box-shadow: 0 12px 48px rgba(0,0,0,0.18), 0 0 0 1px rgba(0,0,0,0.04);
    -webkit-overflow-scrolling: touch;
}
@media (max-width: 600px) {
    #new-job-modal .doc-modal-box {
        width: 95vw;
        max-height: 80vh;
        padding: 20px 16px 16px;
        top: 52%;
    }
}
#new-job-modal .doc-modal-label {
    min-width: 75px;
    font-size: 12px;
}
.required-mark {
    color: #E53935;
    font-weight: 700;
}
#new-job-modal .doc-modal-input,
#new-job-modal select.doc-modal-input {
    border: 1.5px solid var(--gray-1);
    background: var(--gray-bg);
    border-radius: 6px;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
#new-job-modal .doc-modal-input:focus,
#new-job-modal select.doc-modal-input:focus {
    border-color: var(--blue);
    background: var(--white);
    box-shadow: 0 0 0 3px rgba(46,117,182,0.1);
}
#new-job-modal .doc-modal-actions {
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--gray-1);
}

.new-job-mode-switch {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    background: var(--gray-bg);
    border-radius: 10px;
    padding: 4px;
    border: 1px solid var(--gray-1);
}
.new-job-mode-switch button {
    flex: 1;
    border: none !important;
    border-radius: 7px !important;
    padding: 8px 16px !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    transition: all 0.2s !important;
    background: transparent !important;
    color: var(--gray-4) !important;
}
.new-job-mode-switch .new-job-mode-active {
    background: var(--white) !important;
    color: var(--navy) !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1) !important;
}

.work-order-actions {
    justify-content: flex-start;
    margin-top: 4px;
}

.work-order-textarea {
    min-height: 88px;
    resize: vertical;
}

.textarea-polish-wrap {
    flex: 1;
    position: relative;
}
.textarea-polish-wrap textarea {
    width: 100%;
    box-sizing: border-box;
    padding-bottom: 30px;
}
.textarea-polish-btn {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: var(--white);
    border: 1.5px solid var(--gray-1);
    border-radius: 6px;
    padding: 4px 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--gray-4);
    cursor: pointer;
    transition: all 0.15s;
    letter-spacing: 0.3px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.textarea-polish-btn:hover {
    background: var(--navy);
    color: var(--white);
    border-color: var(--navy);
    box-shadow: 0 2px 6px rgba(31,58,95,0.2);
}

.polish-suggestions {
    margin-top: 6px;
    font-size: 13px;
    line-height: 1.5;
}
.polish-suggestions:empty { display: none; }

.polish-result-panel {
    padding: 14px 16px;
    border: 1px solid #C8E6C9;
    border-radius: 8px;
    background: #F1F8E9;
    color: var(--text);
    line-height: 1.6;
}
.polish-result-text {
    font-size: 14px;
    margin-bottom: 12px;
}
.polish-result-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}
.polish-use-btn {
    background: var(--navy);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 7px 18px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.polish-use-btn:hover { background: var(--blue); }

.work-order-polish-preview {
    display: grid;
    gap: 8px;
    margin-top: 8px;
}

.work-order-polish-preview:empty {
    display: none;
}

.work-order-polish-head {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    color: var(--gray-4);
}

.work-order-polish-copy {
    padding: 10px 12px;
    border: 1px solid #D7E2EF;
    border-radius: 10px;
    background: #F8FBFE;
    color: var(--text);
    line-height: 1.5;
}

.work-order-polish-actions {
    display: flex;
    justify-content: flex-end;
}

#work-order-payment-fields {
    display: grid;
    gap: 0;
}

.work-order-customer-matches {
    display: grid;
    gap: 8px;
    margin: -2px 0 6px 128px;
}

.work-order-customer-matches:empty {
    display: none;
}

.currency-input-wrap {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}
.currency-prefix {
    position: absolute;
    left: 10px;
    color: var(--gray-4);
    font-size: 13px;
    font-weight: 600;
    pointer-events: none;
}
.currency-input {
    padding-left: 22px !important;
}
.currency-input::-webkit-inner-spin-button,
.currency-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.new-job-duplicate-warning {
    position: relative;
    background: #FFF8E1;
    border: 1px solid #FFD54F;
    border-radius: 6px;
    padding: 8px 32px 8px 12px;
    font-size: 12px;
    color: #5D4037;
    margin-bottom: 10px;
    line-height: 1.5;
}
.duplicate-close-btn {
    position: absolute;
    top: 4px;
    right: 6px;
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    color: #8D6E63;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    border-radius: 4px;
}
.duplicate-close-btn:hover { background: rgba(0,0,0,0.06); color: #5D4037; }
.duplicate-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    flex-wrap: wrap;
}
.duplicate-goto-btn {
    background: var(--navy);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
}
.duplicate-goto-btn:hover { background: var(--blue); }

.send-receipt-text-btn {
    background: #2E7D32 !important;
}
.send-receipt-text-btn:hover {
    background: #1B5E20 !important;
}

.work-order-match {
    display: grid;
    gap: 3px;
    text-align: left;
    border: 1px solid #D7E2EF;
    border-radius: 10px;
    background: #F8FBFE;
    padding: 10px 12px;
    cursor: pointer;
    color: var(--text);
}

.work-order-match:hover {
    background: #EEF5FC;
    border-color: #B9CEE5;
}

.work-order-match-name {
    font-weight: 700;
    color: var(--navy);
}

.work-order-match-job,
.work-order-match-meta {
    font-size: 12px;
    color: var(--text-lt);
}

.invoice-schedule-list {
    flex: 1;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--gray-1);
    border-radius: 8px;
    overflow: hidden;
}

.invoice-schedule-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--gray-1);
}
.invoice-schedule-list .invoice-schedule-row:last-child { border-bottom: none; }
.invoice-schedule-row:hover { background: var(--gray-1); }

.invoice-schedule-row.invoice-schedule-paid {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    row-gap: 2px;
    cursor: default;
    color: var(--gray-3);
}
.invoice-schedule-row.invoice-schedule-paid:hover { background: transparent; }
.invoice-schedule-row.invoice-schedule-paid .invoice-schedule-name {
    grid-column: 2;
    grid-row: 1;
    color: var(--gray-3);
    font-weight: 500;
}
.invoice-schedule-row.invoice-schedule-paid .invoice-schedule-amt {
    grid-column: 3;
    grid-row: 1;
    color: var(--gray-3);
    font-weight: 500;
}
.invoice-schedule-row.invoice-schedule-paid .invoice-schedule-paid-badge {
    grid-column: 2 / -1;
    grid-row: 2;
}

.invoice-schedule-paid input[type="checkbox"] {
    visibility: hidden;
    width: 16px;
}

.invoice-schedule-paid-badge {
    font-size: 11px;
    font-weight: 500;
    color: var(--gray-3);
    background: transparent;
    padding: 0;
    white-space: nowrap;
}
.invoice-schedule-paid-badge::before {
    content: "✓ ";
    color: var(--green);
    font-weight: 700;
}

.invoice-schedule-name {
    min-width: 0;
    color: var(--text);
    font-weight: 600;
}

.invoice-schedule-amt {
    color: var(--navy);
    font-weight: 700;
    white-space: nowrap;
}

.invoice-extra-line-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 10px;
    align-items: start;
    padding: 8px 10px;
    border: 1px solid var(--gray-1);
    border-radius: 8px;
    background: #f8fafc;
    margin-bottom: 8px;
}

.invoice-extra-line-change-order {
    border-color: rgba(39, 174, 96, 0.32);
    background: rgba(39, 174, 96, 0.07);
}

.invoice-extra-line-copy {
    min-width: 0;
}

.invoice-co-pill {
    display: inline-flex;
    align-items: center;
    margin-left: 6px;
    padding: 2px 6px;
    border-radius: 999px;
    background: rgba(39, 174, 96, 0.14);
    color: var(--green);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.5px;
    vertical-align: middle;
}

.invoice-co-note {
    margin-top: 3px;
    color: var(--green);
    font-size: 11px;
    font-weight: 700;
}

.invoice-extra-line-amt {
    font-weight: 700;
    color: var(--navy);
    white-space: nowrap;
}

.invoice-review-totals {
    margin-top: 18px;
    padding: 14px 16px;
    background: var(--gray-1);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.invoice-totals-line {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    font-size: 13px;
    color: var(--text-lt);
}
.invoice-totals-line .invoice-totals-v {
    font-family: 'DM Mono', monospace;
}
.invoice-totals-line.invoice-totals-primary {
    border-top: 1px solid var(--gray-2);
    border-bottom: 1px solid var(--gray-2);
    margin: 6px 0;
    padding: 10px 0;
    font-size: 14px;
    color: var(--text);
}
.invoice-totals-line.invoice-totals-primary .invoice-totals-k {
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 11px;
    color: var(--text-lt);
}
.invoice-totals-line.invoice-totals-primary .invoice-totals-v {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
}
.invoice-totals-line.invoice-totals-meta {
    font-size: 12px;
    color: var(--gray-3);
}

/* ── INVOICE REVIEW MODAL (mockup-aligned) ── */
.doc-modal-box.app-modal-box {
    width: min(760px, 96vw);
    padding: 0;
    border-radius: 22px;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.45);
}
.app-modal-box .app-modal-header {
    padding: 28px 32px 20px;
    border-bottom: 1px solid var(--gray-1);
    flex-shrink: 0;
    background: var(--white);
    box-shadow: 0 6px 14px -10px rgba(0, 0, 0, 0.55);
    position: relative;
    z-index: 2;
}
.app-modal-box .app-modal-eyebrow {
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--blue);
    font-weight: 700;
    margin-bottom: 6px;
}
.app-modal-box .app-modal-title {
    margin: 0;
    font-family: 'Bebas Neue', sans-serif;
    font-size: 28px;
    line-height: 1.1;
    letter-spacing: 0.5px;
    color: var(--text);
}
.app-modal-box .app-modal-subtitle {
    margin-top: 6px;
    color: var(--gray-3);
    font-size: 14px;
}
.app-modal-box .app-modal-body {
    padding: 24px 32px 28px;
    overflow-y: auto;
    flex: 1;
}
.app-modal-box .app-modal-section {
    margin-bottom: 24px;
}
.app-modal-box .app-modal-section:last-child {
    margin-bottom: 0;
}
.app-modal-box .app-modal-section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--gray-3);
    font-weight: 700;
    margin-bottom: 10px;
}
.app-modal-box .app-modal-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.app-modal-box .app-modal-check {
    display: flex;
    gap: 10px;
    align-items: center;
    cursor: pointer;
    font-size: 13px;
    color: var(--text);
    padding: 8px 4px;
}
.app-modal-box .app-modal-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--blue);
    margin: 0;
}

/* User Management cards */
.app-modal-box .user-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.app-modal-box .user-card {
    background: var(--gray-1);
    border: 1px solid var(--gray-2);
    border-radius: 14px;
    overflow: hidden;
    transition: border-color 0.15s;
}
.app-modal-box .user-card-disabled { opacity: 0.55; }
.app-modal-box .user-card-main {
    display: grid;
    grid-template-columns: 44px 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 12px 14px;
}
.app-modal-box .user-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 0.5px;
    flex-shrink: 0;
    background: var(--gray-3);
}
.app-modal-box .user-avatar.role-owner  { background: #1B3350; }
.app-modal-box .user-avatar.role-office { background: #2968A6; }
.app-modal-box .user-avatar.role-crew   { background: #D4A017; }
.app-modal-box .user-avatar.role-field  { background: #27AE60; }
.app-modal-box .user-card-info { min-width: 0; }
.app-modal-box .user-card-name {
    color: var(--text);
    font-weight: 700;
    font-size: 15px;
    text-decoration: none;
    display: block;
    word-break: break-word;
}
.app-modal-box .user-card-name:hover { text-decoration: underline; }
.app-modal-box .user-card-meta {
    margin-top: 4px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    font-size: 12px;
    color: var(--gray-3);
}
.app-modal-box .user-role-pill {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 2px 8px;
    border-radius: 999px;
    color: #fff;
    background: var(--gray-3);
}
.app-modal-box .user-role-pill.role-owner  { background: #1B3350; }
.app-modal-box .user-role-pill.role-office { background: #2968A6; }
.app-modal-box .user-role-pill.role-crew   { background: #D4A017; }
.app-modal-box .user-role-pill.role-field  { background: #27AE60; }
.app-modal-box .user-rate {
    font-family: 'DM Mono', ui-monospace, monospace;
    color: var(--text-lt);
}
.app-modal-box .user-status.on  { color: var(--green); font-weight: 600; }
.app-modal-box .user-status.off { color: var(--red);   font-weight: 600; }
.app-modal-box .user-edit-btn {
    padding: 8px 14px;
    font-size: 12px;
}
.app-modal-box .user-profile {
    padding: 14px 14px 16px;
    border-top: 1px solid var(--gray-2);
    background: rgba(0, 0, 0, 0.04);
}
[data-theme="dark"] .app-modal-box .user-profile {
    background: rgba(255, 255, 255, 0.03);
}
.app-modal-box .user-profile-section { margin-bottom: 14px; }
.app-modal-box .user-profile-section:last-of-type { margin-bottom: 0; }
.app-modal-box .user-profile-section-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--gray-3);
    margin-bottom: 8px;
}
.app-modal-box .user-profile-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--gray-2);
}

/* Assign worker job list */
.app-modal-box .assign-jobs-list {
    margin-top: 10px;
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid var(--gray-2);
    border-radius: 12px;
    padding: 4px;
}
.app-modal-box .assign-job-row {
    display: grid;
    grid-template-columns: auto auto 1fr;
    gap: 10px;
    align-items: center;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text);
}
.app-modal-box .assign-job-row:hover { background: var(--gray-2); }
.app-modal-box .assign-job-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--blue);
    margin: 0;
}
.app-modal-box .assign-job-num {
    font-weight: 700;
    font-family: 'DM Mono', ui-monospace, monospace;
    font-size: 13px;
    color: var(--blue);
}
.app-modal-box .assign-job-info {
    color: var(--text-lt);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Bill list */
.app-modal-box .bill-list {
    background: transparent;
    border: 1px solid var(--gray-1);
    border-radius: 14px;
    overflow: hidden;
}
.app-modal-box .bill-row {
    display: grid;
    grid-template-columns: 32px 1fr auto;
    gap: 14px;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--gray-1);
    cursor: pointer;
    margin: 0;
}
.app-modal-box .bill-row:last-child { border-bottom: none; }
.app-modal-box .bill-row.selected {
    background: rgba(74, 144, 217, 0.08);
}
.app-modal-box .bill-row-paid,
.app-modal-box .bill-row-billed {
    cursor: not-allowed;
    opacity: 0.55;
}
.app-modal-box .bill-row-paid .bill-name,
.app-modal-box .bill-row-paid .bill-amount,
.app-modal-box .bill-row-billed .bill-name,
.app-modal-box .bill-row-billed .bill-amount {
    text-decoration: line-through;
    text-decoration-color: var(--gray-3);
    text-decoration-thickness: 1px;
}
.app-modal-box .bill-row-paid .bill-check-paid {
    background: var(--gray-2);
    color: var(--gray-3);
}
.app-modal-box .bill-check-billed {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: var(--gray-2);
    color: var(--gray-3);
    font-size: 13px;
    font-weight: 800;
    display: grid;
    place-items: center;
    flex-shrink: 0;
}
.app-modal-box .bill-meta-billed {
    color: var(--gray-3);
    font-weight: 700;
}
.app-modal-box .bill-check {
    appearance: none;
    -webkit-appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    border: 2px solid var(--gray-3);
    background: transparent;
    margin: 0;
    display: grid;
    place-items: center;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
}
.app-modal-box .bill-check:checked {
    background: var(--green);
    border-color: var(--green);
}
.app-modal-box .bill-check:checked::after {
    content: "✓";
    color: #0f1a28;
    font-size: 13px;
    font-weight: 800;
    line-height: 1;
}
.app-modal-box .bill-check-paid {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: var(--green);
    color: #0f1a28;
    font-size: 13px;
    font-weight: 800;
    display: grid;
    place-items: center;
    flex-shrink: 0;
}
.app-modal-box .bill-main { min-width: 0; }
.app-modal-box .bill-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    word-break: break-word;
}
.app-modal-box .bill-meta {
    margin-top: 2px;
    color: var(--gray-3);
    font-size: 12px;
}
.app-modal-box .bill-meta-paid {
    color: var(--green);
    font-weight: 700;
}
.app-modal-box .bill-amount {
    font-family: 'DM Mono', ui-monospace, monospace;
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
}

/* Custom charge inputs */
.app-modal-box .custom-grid {
    display: grid;
    grid-template-columns: 1fr 160px auto;
    gap: 10px;
}
.app-modal-box .custom-desc-row { margin-top: 10px; }
.app-modal-box .invoice-change-order-toggle {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-top: 10px;
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
}
.app-modal-box .invoice-change-order-toggle input {
    width: 17px;
    height: 17px;
    accent-color: var(--green);
}
.app-modal-box .invoice-change-order-toggle em {
    color: var(--gray-3);
    font-style: normal;
    font-weight: 600;
}
.app-modal-box .app-modal-input {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    background: var(--gray-1);
    border: 1px solid var(--gray-2);
    border-radius: 10px;
    color: var(--text);
    padding: 12px 14px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.app-modal-box input[type="date"].app-modal-input,
.app-modal-box input[type="number"].app-modal-input {
    -webkit-appearance: none;
    appearance: none;
    min-height: 44px;
}
.app-modal-box .app-modal-input::placeholder { color: var(--gray-3); }
.app-modal-box .app-modal-input:focus {
    border-color: var(--blue-lt);
    box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.18);
}

/* Adjustments */
.app-modal-box .invoice-adj-card {
    background: var(--gray-1);
    border-radius: 12px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.app-modal-box .invoice-adj-row {
    display: flex;
    gap: 12px;
    align-items: center;
}
.app-modal-box .invoice-adj-label {
    font-size: 13px;
    color: var(--text-lt);
    font-weight: 600;
    flex-shrink: 0;
}
.app-modal-box .invoice-adj-input {
    flex: 1;
    background: var(--white);
    border: 1px solid var(--gray-2);
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--text);
    font-size: 13px;
    outline: none;
}
.app-modal-box .invoice-adj-check {
    display: flex;
    gap: 8px;
    align-items: center;
    cursor: pointer;
    font-size: 13px;
    color: var(--text);
}

/* Extra lines list */
.app-modal-box .invoice-builder-list .invoice-extra-line-item {
    border-radius: 12px;
    margin-bottom: 8px;
}
.app-modal-box .empty-state {
    color: var(--gray-3);
    font-size: 13px;
    padding: 8px 0;
}

/* Summary card */
.app-modal-box .summary-card {
    background: var(--gray-1);
    border: 1px solid var(--gray-2);
    border-radius: 16px;
    padding: 18px 20px;
}
.app-modal-box .summary-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 18px;
    color: var(--gray-3);
    font-size: 14px;
    padding: 4px 0;
}
.app-modal-box .summary-row strong {
    color: var(--text);
    font-size: 15px;
    font-family: 'DM Mono', ui-monospace, monospace;
    font-weight: 700;
}
.app-modal-box .summary-divider {
    height: 1px;
    background: var(--gray-2);
    margin: 12px 0;
}
.app-modal-box .total-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 18px;
    padding: 4px 0;
}
.app-modal-box .total-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--text-lt);
    font-weight: 700;
}
.app-modal-box .total-amount {
    font-family: 'DM Mono', ui-monospace, monospace;
    font-size: clamp(28px, 5vw, 38px);
    font-weight: 800;
    letter-spacing: -0.04em;
    color: var(--text);
}
.app-modal-box .after-negative { color: var(--red); }

/* Modal actions */
.app-modal-box .app-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 8px;
}
.app-modal-box .app-modal-btn {
    border: 0;
    border-radius: 12px;
    padding: 12px 18px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: filter 0.15s, background 0.15s;
}
.app-modal-box .app-modal-btn-secondary {
    background: transparent;
    color: var(--text-lt);
    border: 1px solid var(--gray-2);
}
.app-modal-box .app-modal-btn-secondary:hover { background: var(--gray-1); }
.app-modal-box .app-modal-btn-primary {
    background: var(--navy);
    color: var(--white);
}
.app-modal-box .app-modal-btn-primary:hover { filter: brightness(1.1); }
.app-modal-box .app-modal-btn-primary:disabled,
.app-modal-box .app-modal-btn-primary[disabled] {
    background: var(--gray-2);
    color: var(--text-lt);
    cursor: not-allowed;
    filter: none;
}
.app-modal-box .app-modal-hint {
    margin-top: 4px;
    margin-bottom: 4px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--gray-1);
    color: var(--text-lt);
    font-size: 13px;
    line-height: 1.4;
    text-align: center;
}
[data-theme="dark"] .app-modal-box .app-modal-btn-primary:disabled,
[data-theme="dark"] .app-modal-box .app-modal-btn-primary[disabled] {
    background: var(--gray-2);
    color: var(--text-lt);
}
[data-theme="dark"] .app-modal-box .app-modal-hint {
    background: #0F1520;
    color: var(--text-lt);
}
.app-modal-box .app-modal-btn-blue {
    background: rgba(74, 144, 217, 0.14);
    color: var(--blue);
    border: 1px solid rgba(74, 144, 217, 0.32);
}
.app-modal-box .app-modal-btn-blue:hover { background: rgba(74, 144, 217, 0.22); }

/* Dark theme tweaks */
[data-theme="dark"] .app-modal-box .app-modal-header { border-bottom-color: var(--gray-2); }
[data-theme="dark"] .app-modal-box .bill-list { border-color: var(--gray-2); }
[data-theme="dark"] .app-modal-box .bill-row { border-bottom-color: var(--gray-2); }
[data-theme="dark"] .app-modal-box .bill-row.selected { background: rgba(106, 170, 240, 0.12); }
[data-theme="dark"] .app-modal-box .app-modal-input { background: #0F1520; border-color: var(--gray-2); }
[data-theme="dark"] .app-modal-box .invoice-adj-card { background: #0F1520; }
[data-theme="dark"] .app-modal-box .invoice-adj-input { background: var(--gray-1); border-color: var(--gray-2); }
[data-theme="dark"] .app-modal-box .summary-card { background: #0F1520; border-color: var(--gray-2); }
[data-theme="dark"] .app-modal-box .summary-divider { background: var(--gray-2); }
[data-theme="dark"] .app-modal-box .app-modal-btn-primary { background: var(--blue); color: #0F1520; }

/* Dark-mode contrast bumps — the modal/page hierarchy was too subtle.
   These rules apply to every consumer of .app-modal-box (Generate
   Invoice, Issue Receipt picker, Add Expense, Log Hours, User Admin). */

/* 1. Modal box pops off the page: visible border + stronger shadow. */
[data-theme="dark"] .doc-modal-box.app-modal-box {
    border: 1px solid var(--border-strong, #2B3A52);
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.65), 0 2px 0 rgba(255, 255, 255, 0.04) inset;
}
[data-theme="dark"] .app-modal-box .app-modal-header {
    background: var(--white);
    box-shadow: 0 6px 14px -10px rgba(0, 0, 0, 0.85);
}

/* 2. Section labels readable instead of barely-there. */
[data-theme="dark"] .app-modal-box .app-modal-eyebrow {
    color: var(--blue-lt, #6AAAF0);
}
[data-theme="dark"] .app-modal-box .app-modal-section-title {
    color: var(--text-lt, #A0AABB);
}

/* 3. Cards/lists nested inside the modal need visible edges. The
   default border alone disappears against the modal bg. */
[data-theme="dark"] .app-modal-box .invoice-adj-card,
[data-theme="dark"] .app-modal-box .summary-card {
    border: 1px solid var(--border, #1E2A3C);
}
[data-theme="dark"] .app-modal-box .invoice-builder-list {
    border: 1px solid var(--border, #1E2A3C);
    border-radius: 10px;
}
[data-theme="dark"] .app-modal-box .invoice-builder-list:empty::before {
    color: var(--gray-3);
}

/* 4. The "Add" button (.app-modal-btn-blue) was too washed out — give
   the outlined-blue style real presence in dark. */
[data-theme="dark"] .app-modal-box .app-modal-btn-blue {
    background: rgba(74, 144, 217, 0.18);
    color: var(--blue-lt, #6AAAF0);
    border-color: rgba(106, 170, 240, 0.45);
}
[data-theme="dark"] .app-modal-box .app-modal-btn-blue:hover {
    background: rgba(106, 170, 240, 0.26);
}

/* 5. Empty-state line ("No extra invoice lines yet.") needs to not
   melt into the bg. */
[data-theme="dark"] .app-modal-box .empty-state {
    color: var(--gray-3, #8896A6);
}

/* 6. Checkbox visibility — the default UA dark checkbox is barely
   visible. Border + accent so the box itself is findable. */
[data-theme="dark"] .app-modal-box input[type="checkbox"] {
    accent-color: var(--blue, #4A90D9);
}

/* Mobile collapse */
@media (max-width: 620px) {
    .doc-modal-box.app-modal-box {
        width: calc(100vw - 16px);
        max-height: calc(100vh - var(--btab-h) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 92px);
        border-radius: 16px;
        top: calc(env(safe-area-inset-top, 0px) + 64px + 12px);
        left: 50%;
        transform: translateX(-50%);
    }
    .app-modal-box .app-modal-header { padding: 20px 18px 16px; }
    .app-modal-box .app-modal-body { padding: 18px 18px 22px; }
    .app-modal-box .app-modal-title { font-size: 24px; }
    .app-modal-box .bill-row {
        grid-template-columns: 28px 1fr;
        row-gap: 4px;
    }
    .app-modal-box .bill-amount {
        grid-column: 2;
        justify-self: end;
    }
    .app-modal-box .custom-grid { grid-template-columns: 1fr; }
    .app-modal-box .app-modal-grid-2 { grid-template-columns: 1fr; }
    .app-modal-box .app-modal-actions {
        flex-direction: column-reverse;
    }
    .app-modal-box .app-modal-btn { width: 100%; }
}

.invoice-history-details {
    margin-top: 12px;
    border-top: 1px solid var(--gray-1);
    padding-top: 10px;
}

.invoice-history-details summary {
    cursor: pointer;
    font-weight: 700;
    color: var(--navy);
    list-style: none;
}

.invoice-history-details summary::-webkit-details-marker {
    display: none;
}

.invoice-history-list {
    display: grid;
    gap: 10px;
    margin-top: 10px;
}

.invoice-history-item {
    border: 1px solid var(--gray-1);
    border-radius: 8px;
    background: #f8fafc;
    padding: 10px 12px;
}

.invoice-history-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 8px;
}

.invoice-history-main {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: baseline;
}

.invoice-history-num {
    font-weight: 700;
    color: var(--navy);
}

.invoice-history-date {
    color: var(--gray-3);
    font-size: 13px;
}

.invoice-history-totals {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    justify-content: flex-end;
    font-size: 13px;
    color: var(--text);
}

.invoice-history-lines {
    margin-top: 8px;
}
.invoice-history-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--gray-1);
}
.invoice-history-actions .doc-import-btn {
    height: 32px;
    padding: 0 14px;
    font-size: 13px;
}
.invoice-history-actions .invoice-history-void-btn {
    color: var(--warning);
    border-color: var(--warning);
}
.invoice-history-actions .invoice-history-void-btn:hover {
    background: var(--warning);
    color: var(--white);
}
[data-theme="dark"] .invoice-history-actions {
    border-top-color: var(--gray-2);
}
.invoice-history-supersedes {
    font-size: 12px;
    color: var(--gray-3);
    margin-top: 2px;
    margin-bottom: 6px;
}
.invoice-history-badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}
.invoice-history-badge-voided {
    background: var(--gray-2);
    color: var(--gray-3);
    cursor: help;
}
.invoice-history-replaced {
    font-size: 12px;
    color: var(--gray-3);
    font-style: italic;
}
.invoice-history-voided {
    opacity: 0.62;
}
.invoice-history-voided .invoice-history-num,
.invoice-history-voided .invoice-history-totals strong {
    text-decoration: line-through;
    text-decoration-color: var(--gray-3);
}
[data-theme="dark"] .invoice-history-badge-voided {
    background: var(--gray-1);
    color: var(--gray-3);
}

.scope-subsection {
    margin-top: 8px;
}

.scope-subsection-divider {
    border-top: 1px solid var(--gray-2);
    margin-top: 14px;
    padding-top: 14px;
}

.scope-subtitle {
    margin: 0 0 10px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
}

.contact-input {
    width: 100%;
    border: 1px solid var(--gray-2);
    border-radius: 8px;
    padding: 7px 9px;
    font: inherit;
    color: var(--text);
    background: var(--white);
    outline: none;
}

.contact-input:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 2px rgba(41,104,166,0.15);
}

.contact-input-textarea {
    min-height: 76px;
    resize: vertical;
}

.contact-address-cell .contact-input {
    margin-bottom: 4px;
}

.contact-address-sub {
    display: grid;
    grid-template-columns: 1fr 56px 80px;
    gap: 4px;
}

.contact-address-sub .contact-input {
    margin-bottom: 0;
    padding: 6px 8px;
}

.contact-input-state {
    text-align: center;
}

.contact-remove-btn {
    background: none;
    border: none;
    color: var(--red);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

.contact-remove-btn:hover {
    text-decoration: underline;
}
.contact-remove-disabled {
    font-size: 11px;
    color: var(--gray-3);
    cursor: default;
}

.permit-fee-input {
    min-width: 88px;
}

.permit-status-select {
    min-width: 110px;
}

.permit-actions-cell {
    white-space: nowrap;
    display: flex;
    gap: 6px;
    align-items: center;
}

.inline-edit-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px 16px;
}

@media (max-width: 768px) {
    .inline-edit-grid { grid-template-columns: 1fr; }
}

.inline-edit-field {
    display: grid;
    gap: 6px;
}

.inline-edit-field span {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.9px;
    text-transform: uppercase;
    color: var(--gray-3);
}

.inline-edit-field input,
.inline-edit-field select,
.inline-edit-field textarea {
    width: 100%;
    border: 1px solid var(--gray-2);
    border-radius: 8px;
    padding: 9px 11px;
    font: inherit;
    color: var(--text);
    background: var(--white);
    outline: none;
}

.inline-edit-field input:focus,
.inline-edit-field select:focus,
.inline-edit-field textarea:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 2px rgba(41,104,166,0.15);
}

.inline-edit-field textarea {
    resize: vertical;
    min-height: 96px;
}

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

.job-card {
    background: var(--white);
    border-radius: 10px;
    box-shadow: var(--shadow);
    margin-bottom: 18px;
    overflow: hidden;
    border: 1px solid var(--gray-1);
    border-left: 4px solid transparent;
    transition: box-shadow 0.2s;
}
.job-card:hover { box-shadow: var(--shadow-lg); }

.card-pending  { background: var(--white); border-left-color: transparent; }
.card-ready    { background: var(--white); border-left-color: #1A8040; }
.card-permit   { background: var(--white); border-left-color: #D4A017; }
.card-material { background: var(--white); border-left-color: #E67E22; }
.card-progress { background: var(--white); border-left-color: #2968A6; }
.card-blocked  { background: var(--white); border-left-color: #C0392B; }
.card-closed   { background: #F8FAFC; border-left-color: #9CA3AF; }

.job-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    cursor: pointer;
    user-select: none;
    gap: 16px;
}
.job-header:hover { background: #F8FAFC; }

.action-job-link {
    color: var(--blue);
    text-decoration: none;
    font-weight: 600;
}
.action-job-link:hover { text-decoration: underline; }

.job-addr {
    font-size: 13px;
    color: var(--text-lt);
    margin-bottom: 1px;
}
.job-type {
    font-size: 12px;
    color: var(--blue);
    font-weight: 500;
    margin-top: 3px;
}

.chevron {
    font-size: 12px;
    color: var(--gray-3);
    transition: transform 0.2s;
}
.chevron.open { transform: rotate(180deg); }
