:root {
    --bg: #f4efe6;
    --bg-accent: #e7dbc8;
    --panel: rgba(255, 252, 247, 0.92);
    --panel-strong: #fffaf2;
    --text: #2f261d;
    --muted: #6e6255;
    --line: #d4c4b0;
    --brand: #1c6b5f;
    --brand-soft: #ddf0eb;
    --warning-bg: #fff3d7;
    --warning-text: #775719;
    --warning-line: #f1d48f;
    --error: #9d3d2f;
    --error-soft: #f7dfda;
    --success: #2e6a43;
    --success-soft: #dff0e5;
    --shadow: 0 18px 48px rgba(87, 63, 37, 0.14);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    padding: 32px 18px 40px;
    font-family: "Aptos", "Segoe UI", sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(255, 255, 255, 0.9), transparent 28%),
        linear-gradient(145deg, var(--bg), var(--bg-accent));
}

body.summary-open {
    overflow: hidden;
}

.app-shell {
    width: min(1120px, 100%);
    margin: 0 auto;
    display: grid;
    gap: 20px;
}

.hero-card,
.panel {
    background: var(--panel);
    border: 1px solid rgba(126, 100, 72, 0.14);
    border-radius: 22px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(8px);
}

.hero-card {
    padding: 28px;
}

.session-bar {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
    padding: 14px 16px;
    border-radius: 16px;
    background: rgba(255, 250, 242, 0.82);
    border: 1px solid rgba(126, 100, 72, 0.12);
}

.session-label {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.session-meta {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.4;
}

.support-notice {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 18px;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid rgba(28, 107, 95, 0.16);
    background: rgba(221, 240, 235, 0.75);
    color: var(--brand);
    font-size: 0.92rem;
    line-height: 1.45;
}

.support-notice a {
    color: inherit;
    font-weight: 700;
}

.eyebrow {
    margin: 0 0 8px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--brand);
    font-size: 0.76rem;
    font-weight: 700;
}

h1,
h2,
h3 {
    margin: 0;
    font-family: "Iowan Old Style", "Georgia", serif;
    font-weight: 700;
}

h1 {
    font-size: clamp(2rem, 4vw, 3.2rem);
    line-height: 1.05;
}

.hero-copy,
.panel-header p,
.drop-zone span,
.empty-state,
dt,
#result {
    color: var(--muted);
}

.hero-copy {
    margin: 12px 0 0;
    max-width: 52rem;
    font-size: 1.02rem;
    line-height: 1.6;
}

.hero-actions {
    margin-top: 22px;
    display: grid;
    gap: 12px;
    justify-items: start;
}

.hero-primary-action {
    border: 1px solid rgba(18, 84, 76, 0.28);
    border-radius: 14px;
    padding: 13px 18px;
    background: linear-gradient(180deg, #1f7668, #185b52);
    color: #f7fffd;
    font-size: 0.98rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(28, 107, 95, 0.16);
}

.quickbooks-flow-panel {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.workflow-choice {
    border: 1px solid rgba(28, 107, 95, 0.18);
    border-radius: 14px;
    padding: 12px 16px;
    background: rgba(255, 250, 242, 0.9);
    color: var(--brand);
    font-size: 0.94rem;
    font-weight: 700;
    cursor: pointer;
}

#availabilityNotice {
    display: none;
    margin-top: 18px;
}

#availabilityNotice.visible {
    display: grid;
    gap: 8px;
}

.billing-notice {
    margin-top: 14px;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border-radius: 16px;
    border: 1px solid var(--warning-line);
    background: rgba(255, 243, 215, 0.92);
    color: var(--warning-text);
}

.billing-notice strong {
    display: block;
    margin-bottom: 4px;
}

.billing-notice p {
    margin: 0;
    color: inherit;
    line-height: 1.45;
}

.billing-setup-btn {
    flex-shrink: 0;
}

.notice {
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid transparent;
    font-size: 0.95rem;
}

.notice.warning {
    background: var(--warning-bg);
    color: var(--warning-text);
    border-color: var(--warning-line);
}

.workspace-grid {
    display: grid;
    grid-template-columns: minmax(0, 760px);
    gap: 20px;
    justify-content: center;
}

.panel {
    padding: 24px;
}

.upload-panel {
    width: min(100%, 760px);
    margin: 0 auto;
}

.saved-invoices-panel {
    width: min(100%, 760px);
    margin: 0 auto;
}

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

.panel-header p {
    margin: 6px 0 0;
    font-size: 0.95rem;
    line-height: 1.45;
}

.panel-chip {
    align-self: center;
    padding: 6px 10px;
    border-radius: 999px;
    background: var(--brand-soft);
    color: var(--brand);
    font-size: 0.8rem;
    font-weight: 700;
}

.drop-zone {
    display: grid;
    justify-items: center;
    gap: 10px;
    border: 2px dashed var(--line);
    border-radius: 20px;
    padding: 34px 20px;
    text-align: center;
    background: linear-gradient(180deg, rgba(255,255,255,0.82), rgba(246, 239, 229, 0.88));
    cursor: pointer;
    transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.drop-zone:hover,
.drop-zone.dragover {
    transform: translateY(-1px);
    border-color: var(--brand);
    background: linear-gradient(180deg, #f8fffd, #e6f4f0);
}

.drop-zone-icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--brand-soft);
    color: var(--brand);
    font-size: 1.8rem;
    font-weight: 700;
}

#fileInput {
    display: none;
}

.file-meta {
    margin: 18px 0 0;
    padding: 14px 16px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    background: var(--panel-strong);
    border: 1px solid rgba(126, 100, 72, 0.12);
    border-radius: 16px;
}

.file-meta div {
    min-width: 0;
}

dt {
    margin: 0 0 6px;
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

dd {
    margin: 0;
    font-weight: 600;
    color: var(--text);
    overflow-wrap: anywhere;
}

.actionRow {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.actionRow button {
    flex: 1;
    border: 1px solid transparent;
    border-radius: 12px;
    padding: 12px 16px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 700;
    transition: transform 0.18s ease, filter 0.18s ease;
}

.actionRow button:hover {
    transform: translateY(-1px);
    filter: brightness(1.02);
}

#cancelBtn {
    background: #f9e4df;
    border-color: #efc1b8;
    color: #893d31;
}

#retryBtn {
    background: #dff1ec;
    border-color: #b7dbd1;
    color: var(--brand);
}

.summary-toggle,
.summary-close {
    border: 1px solid rgba(28, 107, 95, 0.18);
    border-radius: 12px;
    padding: 11px 14px;
    background: var(--panel-strong);
    color: var(--brand);
    font-size: 0.92rem;
    font-weight: 700;
    cursor: pointer;
}

.summary-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.saved-invoices-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.summary-action {
    border: 1px solid rgba(28, 107, 95, 0.18);
    border-radius: 12px;
    padding: 11px 14px;
    background: var(--panel-strong);
    color: var(--brand);
    font-size: 0.92rem;
    font-weight: 700;
    cursor: pointer;
}

.summary-save {
    background: linear-gradient(180deg, #f6fbfa, #edf7f4);
}

.summary-send {
    background: linear-gradient(180deg, #1f7668, #185b52);
    border-color: rgba(18, 84, 76, 0.35);
    color: #f7fffd;
}

.summary-action:disabled,
.summary-close:disabled {
    cursor: not-allowed;
    opacity: 0.55;
    filter: none;
}

.summary-toggle {
    width: 100%;
    margin-top: 14px;
    background: linear-gradient(180deg, #f6fbfa, #edf7f4);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.status-toggle {
    margin-top: 10px;
    background: linear-gradient(180deg, #fff7ea, #f8ead1);
    color: #8a5a12;
    border-color: rgba(138, 90, 18, 0.16);
}

.summary-toggle:disabled {
    cursor: not-allowed;
    opacity: 0.65;
}

.summary-toggle.is-disabled {
    pointer-events: auto;
    cursor: not-allowed;
    opacity: 0.65;
}

.status-page-shell {
    width: min(1120px, 100%);
    margin: 0 auto;
    display: grid;
    gap: 20px;
}

.status-page-actions {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.status-page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 11px 14px;
    border-radius: 12px;
    border: 1px solid rgba(28, 107, 95, 0.18);
    background: var(--panel-strong);
    color: var(--brand);
    font-size: 0.92rem;
    font-weight: 700;
    text-decoration: none;
}

.status-hero-copy {
    margin: 12px 0 0;
    max-width: 44rem;
    font-size: 1rem;
    line-height: 1.55;
    color: var(--muted);
}

.status-grid {
    display: grid;
    gap: 20px;
}

.status-summary-card {
    padding: 14px 16px;
    border-radius: 16px;
    background: var(--panel-strong);
    border: 1px solid rgba(126, 100, 72, 0.12);
}

.status-detail-card {
    padding: 24px;
}

.status-table-wrap {
    overflow: auto;
    border: 1px solid rgba(126, 100, 72, 0.14);
    border-radius: 18px;
    background: var(--panel-strong);
}

.saved-invoices-table-wrap {
    overflow: auto;
    border: 1px solid rgba(126, 100, 72, 0.14);
    border-radius: 18px;
    background: var(--panel-strong);
}

.saved-invoices-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.94rem;
}

.saved-invoices-table th {
    background: #efe4d2;
    padding: 12px 14px;
    font-weight: 700;
    text-align: left;
}

.saved-invoices-table td {
    padding: 12px 14px;
    border-bottom: 1px solid rgba(126, 100, 72, 0.1);
    vertical-align: top;
}

.saved-invoices-table tr:last-child td {
    border-bottom: 0;
}

.saved-invoices-table input[type="checkbox"] {
    width: 18px;
    height: 18px;
}

.saved-invoice-status {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 10px;
    background: var(--brand-soft);
    color: var(--brand);
    font-size: 0.8rem;
    font-weight: 700;
}

.saved-invoice-status.is-warning {
    background: var(--warning-bg);
    color: var(--warning-text);
}

.saved-invoice-status.is-success {
    background: var(--success-soft);
    color: var(--success);
}

.saved-invoice-status.is-error {
    background: var(--error-soft);
    color: var(--error);
}

.saved-invoice-note {
    color: var(--muted);
    font-size: 0.84rem;
}

.saved-invoice-link {
    display: inline-flex;
    align-items: center;
    margin-top: 6px;
    color: var(--brand);
    font-size: 0.86rem;
    font-weight: 700;
    text-decoration: none;
}

.saved-invoice-link:hover {
    text-decoration: underline;
}

.saved-invoice-links {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.saved-invoice-primary-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 140px;
    padding: 9px 12px;
    border: 1px solid rgba(28, 107, 95, 0.18);
    border-radius: 10px;
    background: linear-gradient(180deg, #f6fbfa, #edf7f4);
    color: var(--brand);
    font-size: 0.88rem;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}

.saved-invoice-primary-action:hover {
    text-decoration: none;
    filter: brightness(1.01);
}

.status-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.94rem;
}

.status-table th {
    background: #efe4d2;
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 12px 14px;
    font-weight: 700;
    text-align: left;
}

.status-table td {
    padding: 12px 14px;
    border-bottom: 1px solid rgba(126, 100, 72, 0.1);
    vertical-align: top;
}

.status-table tr:last-child td {
    border-bottom: 0;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 10px;
    background: var(--brand-soft);
    color: var(--brand);
    font-size: 0.8rem;
    font-weight: 700;
}

.status-message {
    color: var(--text);
    line-height: 1.45;
}

.status-error {
    margin-top: 8px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--error-soft);
    color: var(--error);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.status-empty {
    padding: 22px 18px;
    border-radius: 16px;
    border: 1px dashed var(--line);
    text-align: center;
    background: rgba(255, 250, 242, 0.65);
    color: var(--muted);
}

.summary-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(35, 28, 18, 0.38);
    backdrop-filter: blur(4px);
    z-index: 20;
}

.status-card {
    margin-top: 18px;
    padding: 16px 18px;
    border-radius: 16px;
    background: var(--panel-strong);
    border: 1px solid rgba(126, 100, 72, 0.12);
}

.status-toast {
    position: fixed;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    width: min(92vw, 420px);
    padding: 12px 16px;
    border-radius: 14px;
    border: 1px solid rgba(126, 100, 72, 0.16);
    background: rgba(47, 38, 29, 0.94);
    color: #fffaf2;
    box-shadow: 0 18px 40px rgba(35, 28, 18, 0.28);
    z-index: 60;
    font-size: 0.94rem;
    font-weight: 600;
    line-height: 1.4;
}

.status-toast[data-state="working"] {
    background: rgba(199, 135, 25, 0.96);
    color: #fffaf2;
}

.status-toast[data-state="success"] {
    background: rgba(46, 106, 67, 0.96);
    color: #f7fff9;
}

.status-toast[data-state="warning"] {
    background: rgba(182, 122, 29, 0.96);
    color: #fff8ec;
}

.status-toast[data-state="error"] {
    background: rgba(157, 61, 47, 0.96);
    color: #fff5f2;
}

.auth-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(35, 28, 18, 0.45);
    backdrop-filter: blur(6px);
    z-index: 80;
}

.auth-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(92vw, 520px);
    z-index: 81;
    padding: 24px;
}

.auth-modal-header {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 16px;
}

.auth-modal-copy {
    margin: 14px 0 0;
    color: var(--muted);
    line-height: 1.5;
}

.auth-tab-row {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.auth-tab {
    flex: 1;
    border: 1px solid rgba(28, 107, 95, 0.18);
    border-radius: 12px;
    padding: 10px 12px;
    background: var(--panel-strong);
    color: var(--brand);
    font-size: 0.92rem;
    font-weight: 700;
    cursor: pointer;
}

.auth-tab.is-active {
    background: linear-gradient(180deg, #1f7668, #185b52);
    border-color: rgba(18, 84, 76, 0.35);
    color: #f7fffd;
}

.auth-feedback {
    margin-top: 16px;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid transparent;
    line-height: 1.45;
}

.auth-feedback[data-state="error"] {
    background: var(--error-soft);
    color: var(--error);
    border-color: rgba(157, 61, 47, 0.18);
}

.auth-feedback[data-state="success"] {
    background: var(--success-soft);
    color: var(--success);
    border-color: rgba(46, 106, 67, 0.18);
}

.auth-form {
    display: grid;
    gap: 10px;
    margin-top: 18px;
}

.auth-label {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text);
}

.auth-password-hint {
    margin: 0;
    color: var(--muted);
    font-size: 0.86rem;
    line-height: 1.45;
}

.auth-submit {
    width: 100%;
    margin-top: 6px;
}

.status-heading {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #a59a8b;
    box-shadow: 0 0 0 6px rgba(165, 154, 139, 0.18);
}

.status-dot[data-state="working"] {
    background: #c78719;
    box-shadow: 0 0 0 6px rgba(199, 135, 25, 0.18);
}

.status-dot[data-state="success"] {
    background: var(--success);
    box-shadow: 0 0 0 6px rgba(46, 106, 67, 0.16);
}

.status-dot[data-state="error"] {
    background: var(--error);
    box-shadow: 0 0 0 6px rgba(157, 61, 47, 0.16);
}

.status-dot[data-state="warning"] {
    background: #b67a1d;
    box-shadow: 0 0 0 6px rgba(182, 122, 29, 0.16);
}

#result {
    margin: 0;
    white-space: pre-wrap;
    font-family: "IBM Plex Mono", "Consolas", monospace;
    font-size: 0.92rem;
    line-height: 1.55;
}

.summary-strip {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.extraction-panel {
    position: fixed;
    top: 24px;
    right: 24px;
    bottom: 24px;
    width: min(560px, calc(100vw - 24px));
    z-index: 30;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: translateX(calc(100% + 36px));
    transition: transform 0.24s ease;
}

.extraction-panel.open {
    transform: translateX(0);
}

.summary-card {
    padding: 14px 16px;
    border-radius: 16px;
    background: var(--panel-strong);
    border: 1px solid rgba(126, 100, 72, 0.12);
}

.summary-label {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.empty-state {
    padding: 22px 18px;
    border-radius: 16px;
    border: 1px dashed var(--line);
    text-align: center;
    background: rgba(255, 250, 242, 0.65);
}

.extraction-container {
    flex: 1;
    min-height: 0;
    overflow: auto;
    border: 1px solid rgba(126, 100, 72, 0.14);
    border-radius: 18px;
    background: var(--panel-strong);
}

.extraction-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.94rem;
}

.extraction-table th {
    background: #efe4d2;
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 12px 14px;
    font-weight: 700;
    text-align: left;
}

.extraction-table td {
    padding: 10px 14px;
    border-bottom: 1px solid rgba(126, 100, 72, 0.1);
    vertical-align: top;
}

.extraction-table tr:last-child td {
    border-bottom: 0;
}

.extraction-table pre,
.extraction-table input {
    font: inherit;
}

.editor-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid rgba(126, 100, 72, 0.18);
    border-radius: 10px;
    background: #fffdf9;
    color: var(--text);
}

@media (max-width: 860px) {
    .workspace-grid {
        grid-template-columns: 1fr;
    }

    .summary-strip,
    .file-meta {
        grid-template-columns: 1fr;
    }

    .extraction-panel {
        top: auto;
        right: 12px;
        left: 12px;
        bottom: 12px;
        width: auto;
        max-height: 78vh;
        transform: translateY(calc(100% + 24px));
    }

    .extraction-panel.open {
        transform: translateY(0);
    }
}

@media (max-width: 600px) {
    body {
        padding: 18px 12px 28px;
    }

    .hero-card,
    .panel {
        padding: 18px;
        border-radius: 18px;
    }

    .panel-header {
        flex-direction: column;
        align-items: start;
    }

    .summary-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .saved-invoices-actions,
    .quickbooks-flow-panel {
        width: 100%;
        justify-content: stretch;
    }

    .hero-primary-action,
    .workflow-choice {
        width: 100%;
    }

    .billing-notice {
        flex-direction: column;
        align-items: stretch;
    }

    .status-page-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .session-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .support-notice {
        flex-direction: column;
        align-items: start;
    }


    .actionRow {
        flex-direction: column;
    }

    .drop-zone {
        padding: 28px 16px;
    }

    .status-toast {
        bottom: 12px;
        width: calc(100vw - 24px);
    }

    .auth-modal {
        padding: 18px;
    }

    .auth-tab-row {
        flex-direction: column;
    }
}
