* {
    box-sizing: border-box;
}

:root {
    --bg: #f4f6f8;
    --panel: #ffffff;
    --text: #1f2933;
    --muted: #6b7280;
    --border: #dfe3e8;
    --brand: #c87126;
    --brand-dark: #a85b1e;
    --success-bg: #eef8f1;
    --success-border: #b7dec2;
    --success-text: #205b31;
    --error-bg: #fff1f1;
    --error-border: #efb4b4;
    --error-text: #8a2424;
    --shadow: 0 12px 30px rgba(17, 24, 39, 0.08);
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

a {
    color: inherit;
}

button,
input,
textarea {
    font: inherit;
}

.topbar {
    min-height: 72px;
    padding: 14px 28px;
    background: #15191d;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.topbar-title {
    font-size: 1.15rem;
    font-weight: 700;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-pill {
    padding: 8px 12px;
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 999px;
    font-size: .9rem;
}

.page {
    width: min(1180px, calc(100% - 36px));
    margin: 30px auto 60px;
}

.hero {
    background: linear-gradient(135deg, #ffffff, #fff9f3);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 32px;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
}

.hero h1,
.panel h2,
.login-card h1 {
    margin: 0;
}

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

.hero-copy {
    margin: 12px 0 0;
    color: var(--muted);
    max-width: 680px;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--brand);
    font-size: .73rem;
    font-weight: 800;
    letter-spacing: .14em;
}

.stats-grid {
    margin: 22px 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.stat-card,
.panel,
.login-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
}

.stat-card {
    padding: 20px;
}

.stat-label,
.stat-help {
    display: block;
}

.stat-label {
    color: var(--muted);
    font-size: .86rem;
    font-weight: 700;
}

.stat-value {
    display: block;
    margin: 6px 0 2px;
    font-size: 2rem;
}

.stat-help {
    color: var(--muted);
    font-size: .82rem;
}

.panel {
    overflow: hidden;
}

.panel-heading {
    padding: 22px 24px;
    border-bottom: 1px solid var(--border);
}

.empty-state {
    margin: 0;
    padding: 30px 24px;
    color: var(--muted);
}

.table-wrap {
    overflow-x: auto;
}

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

th,
td {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}

th {
    font-size: .78rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .05em;
}

.status {
    display: inline-flex;
    align-items: center;
    padding: 5px 9px;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 800;
}

.status-open {
    background: #fff3df;
    color: #80500d;
}

.status-completed {
    background: #eef8f1;
    color: #205b31;
}

.status-archived {
    background: #eceff3;
    color: #5c6570;
}

.button {
    appearance: none;
    border: 0;
    border-radius: 10px;
    padding: 10px 15px;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    font-weight: 750;
}

.button-primary {
    background: var(--brand);
    color: white;
}

.button-primary:hover:not(:disabled) {
    background: var(--brand-dark);
}

.button-secondary {
    background: rgba(255,255,255,.10);
    color: #fff;
    border: 1px solid rgba(255,255,255,.18);
}

.button:disabled {
    cursor: not-allowed;
    opacity: .55;
}

.button-full {
    width: 100%;
    margin-top: 18px;
}

.alert {
    margin: 20px 0;
    padding: 13px 15px;
    border-radius: 10px;
    border: 1px solid;
}

.alert-success {
    background: var(--success-bg);
    border-color: var(--success-border);
    color: var(--success-text);
}

.alert-error {
    background: var(--error-bg);
    border-color: var(--error-border);
    color: var(--error-text);
}

.login-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 24px;
    background:
        radial-gradient(circle at top right, rgba(200,113,38,.14), transparent 32rem),
        var(--bg);
}

.login-card {
    width: min(430px, 100%);
    padding: 32px;
}

.login-card-wide {
    width: min(680px, 100%);
}

.brand-mark {
    width: 56px;
    height: 56px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: var(--brand);
    color: white;
    font-size: 1.25rem;
    font-weight: 900;
    margin-bottom: 18px;
}

.muted {
    color: var(--muted);
    margin-top: 8px;
}

label {
    display: block;
    margin: 18px 0 6px;
    font-size: .86rem;
    font-weight: 750;
}

input,
textarea {
    width: 100%;
    border: 1px solid #cfd5dc;
    border-radius: 10px;
    padding: 11px 12px;
    background: #fff;
    color: var(--text);
}

input:focus,
textarea:focus {
    outline: 2px solid rgba(200,113,38,.18);
    border-color: var(--brand);
}

.hash-output {
    min-height: 120px;
    margin-top: 12px;
    resize: vertical;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

code {
    background: #f1f3f5;
    padding: 2px 5px;
    border-radius: 5px;
}

@media (max-width: 850px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

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

@media (max-width: 520px) {
    .page {
        width: min(100% - 20px, 1180px);
        margin-top: 18px;
    }

    .topbar {
        padding-inline: 16px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .hero {
        padding: 24px;
    }
}


/* Stage 2 additions */
.page-narrow {
    width: min(760px, calc(100% - 36px));
}

.panel-body {
    padding: 24px;
}

.form-panel h1 {
    margin: 0;
    font-size: 2rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.form-actions {
    margin-top: 22px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.button-outline {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border);
}

.button-outline:hover {
    background: #f6f7f8;
}

.button-small {
    padding: 7px 11px;
    font-size: .82rem;
}

.actions-cell {
    text-align: right;
}

.stat-value-small {
    font-size: 1.45rem;
    margin-top: 10px;
}

.workflow-grid {
    display: grid;
    gap: 16px;
    margin: 22px 0;
}

.workflow-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 22px;
    display: flex;
    align-items: flex-start;
    gap: 18px;
}

.workflow-card h2 {
    margin: 0 0 6px;
    font-size: 1.15rem;
}

.workflow-card p {
    margin: 0 0 12px;
    color: var(--muted);
}

.workflow-number {
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: #fff3e8;
    color: var(--brand-dark);
    font-weight: 900;
    font-size: 1.1rem;
}

.coming-soon {
    display: inline-block;
    font-size: .7rem;
    font-weight: 900;
    letter-spacing: .08em;
    color: var(--brand-dark);
}

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

    .form-actions {
        flex-direction: column-reverse;
    }

    .form-actions .button {
        width: 100%;
    }
}


/* Stage 3 additions */
.upload-box {
    padding: 18px;
    border: 1px dashed #cfd5dc;
    border-radius: 14px;
    background: #fafbfc;
    margin-bottom: 18px;
}

.upload-box label {
    margin-top: 0;
    font-size: 1rem;
}

.upload-box input[type="file"] {
    margin-top: 10px;
    padding: 10px;
    background: #fff;
}

.info-box {
    margin-top: 20px;
    padding: 16px 18px;
    border-radius: 12px;
    background: #fff8ef;
    border: 1px solid #f2d5b8;
}

.info-box p {
    margin: 6px 0 0;
    color: var(--muted);
}


/* Stage 4 - Xero position */
.hero-action-stack {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
}

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

.xero-stats-grid .stat-money {
    font-size: 1.55rem;
}

.xero-position-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    color: var(--muted);
    font-size: .8rem;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    display: inline-block;
}

.dot-green {
    background: #4f9f63;
}

.dot-red {
    background: #c94a4a;
}

.number-cell {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.xero-position-table th,
.xero-position-table td {
    vertical-align: top;
}

.xero-position-table tbody tr.row-difference {
    background: #fffafa;
}

.xero-position-table tbody tr.row-match:hover,
.xero-position-table tbody tr.row-difference:hover {
    background: #fff7ee;
}

.xero-position-table tfoot th {
    border-top: 2px solid #cfd5dc;
    background: #f7f8fa;
}

.row-note {
    margin-top: 3px;
    color: var(--muted);
    font-size: .72rem;
    font-weight: 500;
}

.row-note-warn {
    color: #9d3d2f;
}

.held-money {
    display: inline-block;
    padding: 3px 7px;
    border-radius: 999px;
    background: #fff2df;
    color: #8a520e;
    font-weight: 800;
}

.money-match {
    color: #25653a;
}

.money-difference {
    color: #aa2f2f;
}

.status-problem {
    background: #fff0f0;
    color: #9b2828;
}

@media (max-width: 850px) {
    .xero-position-heading {
        align-items: flex-start;
        flex-direction: column;
    }
}


/* Stage 4.1 - compact Xero position so the full table fits on screen */
body:has(.xero-position-table) .page {
    width: calc(100% - 24px);
    max-width: none;
    margin: 18px auto 40px;
}

.xero-position-table {
    width: 100%;
    table-layout: fixed;
    font-size: 12px;
}

.xero-position-table th,
.xero-position-table td {
    padding: 9px 8px;
    white-space: normal;
    line-height: 1.25;
}

.xero-position-table th {
    font-size: 10px;
    line-height: 1.15;
}

.xero-position-table th:nth-child(1),
.xero-position-table td:nth-child(1) {
    width: 22%;
    text-align: left;
    overflow-wrap: anywhere;
}

.xero-position-table th:nth-child(2),
.xero-position-table td:nth-child(2) {
    width: 5%;
}

.xero-position-table th:nth-child(3),
.xero-position-table td:nth-child(3) {
    width: 10%;
}

.xero-position-table th:nth-child(4),
.xero-position-table td:nth-child(4) {
    width: 10%;
}

.xero-position-table th:nth-child(5),
.xero-position-table td:nth-child(5) {
    width: 11%;
}

.xero-position-table th:nth-child(6),
.xero-position-table td:nth-child(6) {
    width: 11%;
}

.xero-position-table th:nth-child(7),
.xero-position-table td:nth-child(7) {
    width: 10%;
}

.xero-position-table th:nth-child(8),
.xero-position-table td:nth-child(8) {
    width: 13%;
}

.xero-position-table th:nth-child(9),
.xero-position-table td:nth-child(9) {
    width: 8%;
}

.xero-position-table .number-cell {
    white-space: nowrap;
}

.xero-position-table .row-note {
    white-space: normal;
    line-height: 1.2;
}

.xero-position-table .held-money,
.xero-position-table .status {
    white-space: nowrap;
}

body:has(.xero-position-table) .table-wrap {
    overflow-x: visible;
}

body:has(.xero-position-table) .panel-heading {
    padding: 18px 20px;
}

body:has(.xero-position-table) .hero {
    padding: 24px 26px;
}

body:has(.xero-position-table) .hero h1 {
    font-size: clamp(1.8rem, 3vw, 2.7rem);
}

body:has(.xero-position-table) .stats-grid {
    gap: 10px;
}

body:has(.xero-position-table) .stat-card {
    padding: 15px;
}

@media (max-width: 1100px) {
    .xero-position-table {
        font-size: 11px;
    }

    .xero-position-table th,
    .xero-position-table td {
        padding: 8px 5px;
    }

    .xero-position-table th {
        font-size: 9px;
    }

    .xero-position-table .held-money {
        padding: 2px 5px;
    }
}
