:root {
    --paper: #f3f6fa;
    --surface: #ffffff;
    --ink: #102642;
    --ink-soft: #27415f;
    --muted: #66768b;
    --line: #d7e0ea;
    --line-strong: #b7c5d4;
    --blue: #2856d8;
    --blue-soft: #e9efff;
    --teal: #0c806f;
    --teal-soft: #e5f4f0;
    --amber: #b86f00;
    --amber-soft: #fff1d6;
    --red: #b13c4b;
    --red-soft: #fbe9ec;
    --font-display: "Microsoft YaHei UI", "PingFang SC", "Noto Sans SC", sans-serif;
    --font-body: "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
    --font-data: Bahnschrift, "DIN Alternate", "Roboto Mono", Consolas, monospace;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    background: var(--paper);
}

body {
    margin: 0;
    color: var(--ink);
    background: var(--paper);
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

button,
input,
select {
    font: inherit;
}

button,
a,
input,
select {
    -webkit-tap-highlight-color: transparent;
}

a {
    color: inherit;
}

:focus-visible {
    outline: 3px solid rgba(40, 86, 216, 0.3);
    outline-offset: 2px;
}

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

.eyebrow,
.form-kicker {
    margin: 0 0 8px;
    color: var(--blue);
    font-family: var(--font-data);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.brand-glyph {
    display: inline-grid;
    grid-template-columns: repeat(3, 4px);
    align-items: end;
    gap: 3px;
    width: 18px;
    height: 25px;
}

.brand-glyph i {
    display: block;
    width: 4px;
    background: currentColor;
}

.brand-glyph i:nth-child(1) {
    height: 12px;
}

.brand-glyph i:nth-child(2) {
    height: 25px;
}

.brand-glyph i:nth-child(3) {
    height: 18px;
}

.button {
    display: inline-flex;
    min-height: 42px;
    align-items: center;
    justify-content: center;
    gap: 9px;
    border: 1px solid transparent;
    border-radius: 5px;
    padding: 9px 17px;
    cursor: pointer;
    font-weight: 700;
    text-decoration: none;
    transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.button:hover:not(:disabled) {
    transform: translateY(-1px);
}

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

.button-primary {
    color: #fff;
    background: var(--blue);
    border-color: var(--blue);
}

.button-primary:hover:not(:disabled) {
    background: #1e46bc;
    border-color: #1e46bc;
}

.button-secondary {
    color: var(--ink);
    background: var(--surface);
    border-color: var(--line-strong);
}

.button-secondary:hover {
    border-color: var(--blue);
    color: var(--blue);
}

.button-quiet {
    color: var(--muted);
    background: transparent;
    border-color: transparent;
}

.button-quiet:hover {
    color: var(--ink);
    background: #edf1f6;
}

.button-wide {
    width: 100%;
}

.button-dot {
    width: 8px;
    height: 8px;
    border: 2px solid currentColor;
    border-radius: 50%;
}

.button.is-loading .button-dot {
    border-right-color: transparent;
    animation: turn 760ms linear infinite;
}

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

.notice {
    max-width: 1440px;
    margin: 0 auto 18px;
    border-left: 4px solid var(--blue);
    padding: 13px 16px;
    background: var(--blue-soft);
    color: var(--ink-soft);
    font-weight: 600;
}

.notice-success {
    border-color: var(--teal);
    background: var(--teal-soft);
}

.notice-warning {
    border-color: var(--amber);
    background: var(--amber-soft);
}

.notice-error {
    border-color: var(--red);
    background: var(--red-soft);
}

.notice-info {
    border-color: var(--blue);
}

/* Password-only entrance */
.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 28px;
    background: #e9eef5;
}

.login-shell {
    width: min(1080px, 100%);
    min-height: 680px;
    display: grid;
    grid-template-columns: 1.12fr 0.88fr;
    overflow: hidden;
    border: 1px solid #c9d3df;
    background: var(--surface);
}

.login-ledger {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
    padding: 52px 58px;
    color: #fff;
    background: var(--ink);
}

.login-ledger::after {
    content: "";
    position: absolute;
    top: 0;
    right: 52px;
    width: 5px;
    height: 100%;
    background: #47c4af;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 13px;
    color: #bfcce0;
    font-family: var(--font-data);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.16em;
}

.login-copy {
    position: relative;
    z-index: 1;
    width: min(420px, 86%);
    padding: 44px 0;
}

.login-copy .eyebrow {
    color: #77d8c7;
}

.login-copy h1 {
    margin: 0;
    font-family: var(--font-display);
    font-size: clamp(72px, 8vw, 108px);
    font-weight: 750;
    line-height: 0.95;
    letter-spacing: -0.08em;
}

.login-copy > p:last-child {
    width: 310px;
    max-width: 100%;
    margin: 34px 0 0;
    color: #c4d0df;
    font-size: 15px;
}

.ledger-rules {
    width: calc(100% - 46px);
}

.ledger-rules i {
    display: block;
    height: 1px;
    margin-top: 13px;
    background: rgba(255, 255, 255, 0.16);
}

.ledger-rules i:nth-child(2) { width: 82%; }
.ledger-rules i:nth-child(3) { width: 64%; }
.ledger-rules i:nth-child(4) { width: 88%; }

.login-panel {
    display: grid;
    place-items: center;
    padding: 54px;
    background: var(--surface);
}

.login-form {
    width: min(330px, 100%);
}

.login-form h2 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 27px;
    letter-spacing: -0.035em;
}

.form-help {
    margin: 9px 0 30px;
    color: var(--muted);
}

.login-form .notice {
    margin: 0 0 22px;
    font-size: 13px;
}

.field {
    display: grid;
    gap: 8px;
    margin-bottom: 18px;
    color: var(--ink-soft);
    font-size: 13px;
    font-weight: 700;
}

.field input,
.assignment-form input,
.date-filter input,
.date-filter select {
    min-height: 42px;
    width: 100%;
    border: 1px solid var(--line-strong);
    border-radius: 4px;
    padding: 8px 11px;
    color: var(--ink);
    background: #fff;
}

.field input:hover,
.assignment-form input:hover,
.date-filter input:hover,
.date-filter select:hover {
    border-color: #8da0b5;
}

.field input:focus,
.assignment-form input:focus,
.date-filter input:focus,
.date-filter select:focus {
    border-color: var(--blue);
    outline: 3px solid rgba(40, 86, 216, 0.12);
}

/* Application frame */
.app-header {
    min-height: 72px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 22px;
    border-bottom: 1px solid var(--line);
    padding: 12px clamp(20px, 4vw, 62px);
    background: rgba(255, 255, 255, 0.96);
}

.wordmark {
    display: inline-flex;
    align-items: center;
    gap: 13px;
    color: var(--blue);
    text-decoration: none;
}

.wordmark > span:last-child {
    display: grid;
}

.wordmark strong {
    color: var(--ink);
    font-family: var(--font-display);
    font-size: 17px;
    line-height: 1.15;
}

.wordmark small {
    margin-top: 3px;
    color: var(--muted);
    font-family: var(--font-data);
    font-size: 8px;
    font-weight: 700;
    letter-spacing: 0.15em;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-actions form {
    margin: 0;
}

.sync-note {
    margin-right: 8px;
    color: var(--muted);
    font-size: 12px;
}

.page-shell {
    width: min(1440px, calc(100% - 40px));
    margin: 0 auto;
    padding: 42px 0 68px;
}

.ledger-masthead {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 36px;
    border-bottom: 2px solid var(--ink);
    padding: 0 0 26px;
}

.ledger-masthead h1 {
    margin: 0;
    font-family: var(--font-display);
    font-size: clamp(30px, 4vw, 54px);
    font-weight: 720;
    line-height: 1;
    letter-spacing: -0.055em;
}

.ledger-summary {
    display: flex;
    align-items: end;
    gap: clamp(24px, 4vw, 56px);
    margin: 0;
}

.ledger-summary div {
    display: grid;
    gap: 3px;
}

.ledger-summary dt {
    color: var(--muted);
    font-size: 11px;
}

.ledger-summary dd {
    margin: 0;
    font-family: var(--font-data);
    font-size: 24px;
    font-weight: 700;
    line-height: 1;
}

.ledger-summary .summary-money {
    min-width: 190px;
    border-left: 1px solid var(--line-strong);
    padding-left: clamp(24px, 4vw, 56px);
}

.summary-money dd {
    color: var(--blue);
    font-size: clamp(27px, 3vw, 38px);
}

.summary-money dd span {
    margin-right: 3px;
    font-size: 0.56em;
}

.control-strip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    border-bottom: 1px solid var(--line);
    padding: 17px 0;
}

.view-tabs {
    display: flex;
    align-items: center;
    gap: 5px;
}

.view-tabs a {
    position: relative;
    padding: 9px 12px;
    color: var(--muted);
    font-weight: 700;
    text-decoration: none;
}

.view-tabs a::after {
    content: "";
    position: absolute;
    right: 12px;
    bottom: 2px;
    left: 12px;
    height: 2px;
    background: transparent;
}

.view-tabs a:hover,
.view-tabs a.active {
    color: var(--ink);
}

.view-tabs a.active::after {
    background: var(--blue);
}

.date-filter {
    display: flex;
    align-items: end;
    justify-content: flex-end;
    gap: 8px;
}

.date-filter label {
    display: grid;
    gap: 4px;
}

.date-filter label > span {
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
}

.date-filter input,
.date-filter select {
    min-height: 40px;
    width: auto;
    min-width: 150px;
}

.quick-dates {
    display: flex;
    align-items: center;
    align-self: center;
    gap: 10px;
    margin-left: 5px;
}

.quick-dates a {
    color: var(--blue);
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
}

.quick-dates a:hover {
    text-decoration: underline;
}

/* The ledger spine is the visual signature: source to channel in one line. */
.ledger-stack {
    display: grid;
    gap: 18px;
    margin-top: 26px;
}

.ledger-group {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--line);
    border-left: 5px solid var(--blue);
    border-radius: 5px;
    background: var(--surface);
}

.ledger-group.has-error {
    border-left-color: var(--amber);
}

.source-header,
.report-header {
    min-height: 88px;
    display: grid;
    grid-template-columns: minmax(240px, 1fr) auto minmax(260px, 0.78fr) auto;
    align-items: center;
    gap: 26px;
    border-bottom: 1px solid var(--line);
    padding: 18px 22px;
    background: #f9fbfd;
}

.source-title {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 13px;
}

.source-pulse {
    flex: 0 0 auto;
    width: 11px;
    height: 11px;
    border: 3px solid var(--blue-soft);
    border-radius: 50%;
    background: var(--blue);
    box-shadow: 0 0 0 1px var(--blue);
}

.source-title h2,
.report-header h2 {
    overflow: hidden;
    margin: 0;
    font-family: var(--font-display);
    font-size: 18px;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.source-title a {
    display: block;
    overflow: hidden;
    margin-top: 2px;
    color: var(--muted);
    font-family: var(--font-data);
    font-size: 11px;
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.source-title a:hover {
    color: var(--blue);
}

.source-total {
    display: grid;
    min-width: 140px;
    justify-items: end;
    gap: 2px;
}

.source-total span {
    color: var(--muted);
    font-size: 11px;
}

.source-total strong {
    font-family: var(--font-data);
    font-size: 22px;
    letter-spacing: -0.02em;
}

.assignment-form {
    display: flex;
    align-items: end;
    gap: 7px;
}

.assignment-form label {
    display: grid;
    flex: 1 1 auto;
    gap: 4px;
}

.assignment-form label > span:not(.sr-only) {
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
}

.assignment-form input {
    min-width: 0;
    height: 36px;
    min-height: 36px;
    padding: 6px 9px;
}

.assignment-form.compact {
    min-width: 190px;
    align-items: center;
}

.text-button {
    border: 0;
    padding: 7px 3px;
    color: var(--blue);
    background: transparent;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.text-button:hover {
    text-decoration: underline;
}

.text-button.danger {
    color: var(--red);
}

.source-meta {
    border-bottom: 1px solid var(--line);
    padding: 8px 22px;
    color: var(--muted);
    background: #fff;
    font-family: var(--font-data);
    font-size: 10px;
}

.source-error {
    display: flex;
    gap: 11px;
    border-bottom: 1px solid #efd7a9;
    padding: 9px 22px;
    color: #744d11;
    background: var(--amber-soft);
    font-size: 12px;
}

.source-error strong {
    flex: 0 0 auto;
}

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

.ledger-table {
    width: 100%;
    min-width: 850px;
    border-collapse: collapse;
    table-layout: fixed;
}

.ledger-table th {
    border-bottom: 1px solid var(--line);
    padding: 10px 16px;
    color: var(--muted);
    background: #f5f8fb;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.045em;
    text-align: left;
}

.ledger-table td {
    position: relative;
    height: 66px;
    border-bottom: 1px solid #e6ecf2;
    padding: 10px 16px;
    vertical-align: middle;
}

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

.ledger-table tbody tr:hover td {
    background: #fafcff;
}

.ledger-table th:nth-child(1) { width: 28%; }
.ledger-table th:nth-child(2) { width: 15%; }
.ledger-table th:nth-child(3) { width: 9%; }
.ledger-table th:nth-child(4) { width: 25%; }
.ledger-table th:nth-child(5) { width: 8%; }
.ledger-table th:nth-child(6) { width: 15%; }

.ledger-table b,
.ledger-table small {
    display: block;
}

.ledger-table b {
    overflow: hidden;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ledger-table small {
    margin-top: 2px;
    overflow: hidden;
    color: var(--muted);
    font-family: var(--font-data);
    font-size: 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.channel-cell {
    padding-left: 40px !important;
}

.ledger-node {
    position: absolute;
    top: 50%;
    left: 21px;
    width: 8px;
    height: 8px;
    border: 2px solid var(--blue);
    border-radius: 50%;
    background: #fff;
    transform: translateY(-50%);
}

.channel-cell::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 24px;
    width: 1px;
    background: #bfcdf6;
}

.status,
.person-label {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 700;
}

.status-on {
    color: #087161;
    background: var(--teal-soft);
}

.status-off {
    color: #6d7785;
    background: #edf1f5;
}

.numeric {
    text-align: right !important;
}

.data-number,
.money {
    font-family: var(--font-data);
    font-variant-numeric: tabular-nums;
}

.money {
    color: var(--ink);
    font-size: 15px;
    font-weight: 700;
}

.table-empty {
    height: 88px !important;
    color: var(--muted);
    text-align: center;
}

/* Grouped people views */
.report-group {
    border-left-color: var(--blue);
}

.report-group.partner-group {
    border-left-color: var(--teal);
}

.report-header {
    grid-template-columns: 1fr auto;
}

.report-header .eyebrow {
    margin-bottom: 3px;
}

.partner-group .report-header .eyebrow {
    color: var(--teal);
}

.report-table {
    min-width: 760px;
}

.report-table th:nth-child(1) { width: 24%; }
.report-table th:nth-child(2) { width: 34%; }
.report-table th:nth-child(3) { width: 18%; }
.report-table th:nth-child(4) { width: 9%; }
.report-table th:nth-child(5) { width: 15%; }

.person-label {
    color: var(--ink-soft);
    background: #edf2f8;
}

.person-label.muted {
    color: var(--muted);
    font-weight: 600;
}

/* Empty ledger */
.empty-ledger {
    position: relative;
    min-height: 360px;
    display: grid;
    place-content: center;
    justify-items: start;
    overflow: hidden;
    margin-top: 26px;
    border: 1px solid var(--line);
    border-left: 5px solid var(--blue);
    padding: 64px clamp(30px, 8vw, 120px);
    background: var(--surface);
}

.empty-ledger h2 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 34px;
    letter-spacing: -0.045em;
}

.empty-ledger > p:last-child {
    max-width: 560px;
    margin: 14px 0 0;
    color: var(--muted);
}

.empty-ledger code {
    color: var(--blue);
    font-family: var(--font-data);
}

.empty-mark {
    position: absolute;
    right: 9%;
    width: 84px;
    height: 210px;
    border-right: 5px solid var(--teal);
    border-left: 1px solid var(--line);
}

.compact-empty {
    min-height: 230px;
    margin-top: 0;
}

.app-footer {
    display: flex;
    justify-content: space-between;
    gap: 22px;
    border-top: 1px solid var(--line);
    padding: 24px clamp(20px, 4vw, 62px);
    color: var(--muted);
    background: #eaf0f6;
    font-size: 11px;
}

.app-footer span:first-child {
    font-family: var(--font-data);
    font-weight: 700;
    letter-spacing: 0.12em;
}

@media (max-width: 1080px) {
    .source-header {
        grid-template-columns: minmax(220px, 1fr) auto minmax(240px, 0.9fr);
    }

    .delete-form {
        position: absolute;
        top: 8px;
        right: 10px;
    }

    .sync-note {
        display: none;
    }
}

@media (max-width: 840px) {
    .login-page {
        padding: 0;
    }

    .login-shell {
        min-height: 100vh;
        grid-template-columns: 1fr;
        border: 0;
    }

    .login-ledger {
        min-height: 330px;
        padding: 34px 36px;
    }

    .login-ledger::after {
        right: 34px;
    }

    .login-copy {
        padding: 28px 0 10px;
    }

    .login-copy h1 {
        font-size: 66px;
    }

    .login-copy > p:last-child,
    .ledger-rules {
        display: none;
    }

    .login-panel {
        padding: 50px 30px 62px;
    }

    .app-header,
    .ledger-masthead,
    .control-strip {
        align-items: stretch;
    }

    .app-header {
        flex-wrap: wrap;
    }

    .header-actions {
        margin-left: auto;
    }

    .ledger-masthead,
    .control-strip {
        flex-direction: column;
    }

    .ledger-summary {
        justify-content: space-between;
    }

    .ledger-summary .summary-money {
        min-width: 0;
    }

    .date-filter {
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .source-header {
        grid-template-columns: 1fr auto;
        gap: 15px;
        padding-top: 25px;
    }

    .source-header .assignment-form {
        grid-column: 1 / -1;
        max-width: 420px;
    }
}

@media (max-width: 560px) {
    .app-header {
        padding: 12px 15px;
    }

    .wordmark small,
    .button-quiet {
        display: none;
    }

    .button {
        min-height: 39px;
        padding: 8px 12px;
        font-size: 13px;
    }

    .page-shell {
        width: calc(100% - 24px);
        padding-top: 28px;
    }

    .ledger-masthead {
        gap: 24px;
    }

    .ledger-summary {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 17px;
    }

    .ledger-summary .summary-money {
        grid-column: 1 / -1;
        border-top: 1px solid var(--line);
        border-left: 0;
        padding-top: 16px;
        padding-left: 0;
    }

    .view-tabs {
        width: 100%;
        justify-content: space-between;
    }

    .date-filter label {
        flex: 1 1 140px;
    }

    .date-filter input,
    .date-filter select {
        width: 100%;
        min-width: 0;
    }

    .quick-dates {
        width: 100%;
        margin: 4px 0 0;
    }

    .source-header {
        grid-template-columns: 1fr;
    }

    .source-total {
        justify-items: start;
    }

    .source-error {
        align-items: flex-start;
        flex-direction: column;
        gap: 2px;
    }

    .report-header {
        grid-template-columns: 1fr auto;
    }

    .empty-mark {
        display: none;
    }

    .empty-ledger {
        min-height: 300px;
        padding: 45px 28px;
    }

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

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}
