@font-face {
    font-family: "Noto Serif Display";
    src: url("../fonts/NotoSerifDisplay-SemiCondensedBold.woff2") format("woff2");
    font-style: normal;
    font-weight: 700;
    font-display: swap;
}

:root {
    color-scheme: light;
    --paper: #f3f5f8;
    --sheet: #ffffff;
    --ink: #172033;
    --muted: #526079;
    --rule: #c9d1de;
    --rule-strong: #8d9ab0;
    --cobalt: #154ed8;
    --cobalt-dark: #0d37a5;
    --cobalt-soft: #e8efff;
    --error: #a12232;
    --error-soft: #fff0f1;
    --success: #17633d;
    --success-soft: #e9f7ef;
    --focus: #ffbf47;
    --radius: 4px;
    --display-font: "Noto Serif Display", Georgia, serif;
}

* {
    box-sizing: border-box;
}

html {
    background: var(--paper);
}

body {
    min-width: 0;
    margin: 0;
    color: var(--ink);
    background: var(--paper);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 1rem;
    line-height: 1.5;
}

a {
    color: var(--cobalt-dark);
    text-underline-offset: 0.18em;
}

a:hover {
    color: var(--cobalt);
}

.skip-link {
    position: fixed;
    z-index: 10;
    top: 0.5rem;
    left: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--ink);
    color: white;
    transform: translateY(-150%);
}

.skip-link:focus {
    transform: translateY(0);
}

.app-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1.5rem;
    min-height: 5.25rem;
    padding: 1rem max(1rem, calc((100vw - 74rem) / 2));
    border-bottom: 1px solid var(--rule-strong);
    background: var(--sheet);
}

.identity {
    display: grid;
    gap: 0.1rem;
}

.wordmark {
    color: var(--ink);
    font-family: var(--display-font);
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    text-decoration: none;
}

.identity-owner,
.record-meta,
.field-help,
.page-heading p {
    color: var(--muted);
    font-size: 0.875rem;
}

.header-actions,
nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

nav a,
.button-quiet {
    display: inline-flex;
    min-height: 2.75rem;
    align-items: center;
    padding: 0.55rem 0.8rem;
    border: 0;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 650;
    text-decoration: none;
    cursor: pointer;
}

nav a:hover,
.button-quiet:hover {
    color: var(--ink);
    background: var(--paper);
}

nav a.is-active {
    border-bottom-color: var(--cobalt);
    color: var(--cobalt-dark);
}

.logout-form {
    margin-left: 0.5rem;
    border-left: 1px solid var(--rule);
    padding-left: 0.5rem;
}

.workspace,
.login-workspace {
    width: min(100% - 2rem, 74rem);
    margin: 0 auto;
    padding: 2.25rem 0 4rem;
}

.login-workspace {
    display: grid;
    min-height: calc(100vh - 5.25rem);
    place-items: start center;
    padding-top: clamp(2rem, 8vh, 6rem);
}

.login-panel {
    position: relative;
    width: min(100%, 29rem);
    margin-top: 0.75rem;
    border: 1px solid var(--rule-strong);
    background: var(--sheet);
    padding: clamp(1.25rem, 5vw, 2.25rem);
}

.login-panel::before {
    position: absolute;
    top: -0.75rem;
    left: -1px;
    width: 6rem;
    height: 0.75rem;
    border: 1px solid var(--rule-strong);
    border-bottom: 0;
    background: var(--sheet);
    content: "";
}

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

h1 {
    max-width: 18ch;
    margin: 0;
    font-family: var(--display-font);
    font-size: clamp(1.9rem, 5vw, 3.2rem);
    font-weight: 700;
    line-height: 1.05;
    letter-spacing: -0.035em;
}

.page-heading p,
.lede {
    max-width: 65ch;
    margin: 0.65rem 0 0;
}

.record-count {
    flex: 0 0 auto;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.workspace-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(19rem, 0.85fr);
    gap: 1.5rem;
    align-items: start;
}

.workspace-grid,
.login-panel {
    animation: workspace-reveal 280ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes workspace-reveal {
    from {
        opacity: 0.94;
        transform: translateY(0.35rem);
        clip-path: inset(0 0 3% 0);
    }

    to {
        opacity: 1;
        transform: translateY(0);
        clip-path: inset(0);
    }
}

.drawer {
    min-width: 0;
    border: 1px solid var(--rule-strong);
    background: var(--sheet);
}

.dashboard-availability .detail-list > div:first-child dd { font-size: 1.35rem; color: var(--cobalt-dark); }
.drawer-link { display:block; min-height:2.75rem; padding:0.75rem 1.25rem; border-top:1px solid var(--rule); font-weight:700; }

.section-tab {
    width: fit-content;
    max-width: calc(100% - 1.5rem);
    margin: -1px 0 0 -1px;
    padding: 0.65rem 1rem;
    border: 1px solid var(--rule-strong);
    border-bottom-color: var(--sheet);
    background: var(--sheet);
    color: var(--ink);
    font-size: 0.8rem;
    font-weight: 750;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.form-drawer .section-tab {
    border-top-color: var(--cobalt);
    color: var(--cobalt-dark);
}

.record-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.history-toggle,
.context-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--rule);
}

.card-overview-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.card-overview-list li {
    border-top: 1px solid var(--rule);
}

.card-overview-link {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 1rem;
    align-items: center;
    min-height: 4.5rem;
    padding: 1rem 1.25rem;
    color: var(--ink);
    text-decoration: none;
}

.card-overview-link:hover {
    background: var(--paper);
    color: var(--cobalt-dark);
}

.card-overview-link > span:last-child {
    text-align: right;
}

.card-overview-list .context-actions {
    padding-top: 0;
    border-top: 0;
}

.breadcrumb,
.invoice-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.invoice-focus,
.invoice-history {
    margin-top: 1.25rem;
}

.invoice-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.invoice-list li { border-top: 1px solid var(--rule); }

.invoice-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    min-height: 4rem;
    align-items: center;
    padding: 0.85rem 1.25rem;
    color: var(--ink);
    text-decoration: none;
}

.invoice-row:hover { background: var(--paper); color: var(--cobalt-dark); }
.invoice-total { text-align: right; }

.invoice-entries { margin-top: 1.25rem; }
.invoice-entry { display: block; border-top: 1px solid var(--rule); }
.invoice-entry summary { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 1rem; align-items: center; min-height: 3.5rem; padding: 0.85rem 1.25rem; cursor: pointer; }
.entry-disclosure-open, .invoice-entry[open] .entry-disclosure-closed { display: none; }
.invoice-entry[open] .entry-disclosure-open { display: inline; }
.responsibility-detail { padding: 0.75rem 1.25rem 1rem; border-top: 1px solid var(--rule); background: var(--paper); }
.responsibility-detail dl { margin: 0 0 0.75rem; }
.responsibility-detail dl div { display:flex; justify-content:space-between; gap:1rem; padding:0.25rem 0; }
.responsibility-detail dd { margin:0; }

.record-list li {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--rule);
}

.record-name,
.record-meta,
.record-values span,
.record-values a {
    display: block;
}

.record-name {
    font-weight: 700;
}

.record-values {
    text-align: right;
}

.money,
.record-count,
input[type="number"] {
    font-variant-numeric: tabular-nums;
}

.empty-state,
.prerequisite {
    margin: 0;
    padding: 1.5rem 1.25rem;
    border-top: 1px solid var(--rule);
    color: var(--muted);
}

.prerequisite {
    background: var(--cobalt-soft);
    color: var(--ink);
}

.stack-form {
    display: grid;
    gap: 1.25rem;
    padding: 1.35rem 1.25rem 1.5rem;
    border-top: 1px solid var(--rule);
}

.obligation-filters {
    display: flex;
    align-items: end;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--rule);
}

.obligation-filters .field {
    flex: 1 1 14rem;
}

.obligation-filters .check-field {
    flex: 0 1 auto;
}

.login-panel .stack-form {
    padding: 1.5rem 0 0;
    border-top: 0;
}

.field,
.field-row {
    min-width: 0;
}

.field-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.field label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 700;
}

input,
select,
button {
    min-height: 2.75rem;
}

input,
select {
    width: 100%;
    max-width: 100%;
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius);
    background: var(--sheet);
    color: var(--ink);
    font: inherit;
    padding: 0.65rem 0.75rem;
}

input:hover,
select:hover {
    border-color: var(--ink);
}

input:disabled,
select:disabled,
button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.field-help,
.field-error {
    margin: 0.35rem 0 0;
}

.field-error {
    color: var(--error);
    font-size: 0.875rem;
    font-weight: 650;
}

.has-error input,
.has-error select {
    border-color: var(--error);
    background: var(--error-soft);
}

.check-field {
    display: flex;
    min-height: 2.75rem;
    align-items: center;
    gap: 0.65rem;
    width: fit-content;
    cursor: pointer;
}

.check-field input {
    width: 1.2rem;
    min-height: 1.2rem;
    margin: 0;
}

.button-primary {
    display: inline-flex;
    width: fit-content;
    min-height: 2.75rem;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--cobalt);
    border-radius: var(--radius);
    background: var(--cobalt);
    color: white;
    font: inherit;
    font-weight: 750;
    padding: 0.65rem 1rem;
    text-decoration: none;
    cursor: pointer;
}

.button-primary:hover {
    border-color: var(--cobalt-dark);
    background: var(--cobalt-dark);
    color: white;
}

.button-primary[aria-busy="true"] {
    min-width: 8.25rem;
    cursor: wait;
}

.button-secondary {
    display: inline-flex;
    min-height: 2.75rem;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius);
    background: var(--sheet);
    color: var(--ink);
    font: inherit;
    font-weight: 650;
    padding: 0.6rem 0.8rem;
    cursor: pointer;
}

.button-secondary:hover {
    border-color: var(--ink);
    background: var(--paper);
}

.entry-workspace,
.quick-entry-workspace,
.purchase-detail-workspace {
    max-width: 56rem;
}

.entry-drawer {
    max-width: 42rem;
}

.entry-type {
    display: grid;
    gap: 0.2rem;
    min-height: 4.5rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--rule);
    color: var(--ink);
    text-decoration: none;
}

.entry-type:hover {
    background: var(--paper);
    color: var(--cobalt-dark);
}

.entry-type-name {
    font-weight: 750;
}

.quick-entry-drawer {
    max-width: 46rem;
}

.purchase-form {
    gap: 1.1rem;
}

.payment-entry-fields {
    display: grid;
    gap: 1.25rem;
}

.payment-preview-summary {
    border: 1px solid var(--rule);
}

.audit-preview-summary {
    border: 1px solid var(--rule);
}

.payment-preview-summary h2,
.payment-preview-summary > p,
.audit-preview-summary h2,
.audit-preview-summary > p {
    margin: 0;
    padding-inline: 1rem;
}

.payment-preview-summary h2 {
    padding-top: 1rem;
}

.audit-preview-summary h2 {
    padding-top: 1rem;
}

.payment-preview-summary > p {
    padding-top: 0.3rem;
    padding-bottom: 1rem;
    color: var(--muted);
}

.audit-preview-summary > p {
    padding-top: 0.3rem;
    padding-bottom: 1rem;
    color: var(--muted);
}

.payment-summary-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin: 0;
    border-top: 1px solid var(--rule);
}

.audit-summary-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin: 0;
    border-top: 1px solid var(--rule);
}

.payment-summary-list > div {
    min-width: 0;
    padding: 0.8rem 1rem;
}

.audit-summary-list > div {
    min-width: 0;
    padding: 0.8rem 1rem;
}

.payment-summary-list > div + div {
    border-left: 1px solid var(--rule);
}

.audit-summary-list > div + div {
    border-left: 1px solid var(--rule);
}

.payment-summary-list > div:nth-child(4) {
    border-left: 0;
}

.audit-summary-list > div:nth-child(4) {
    border-left: 0;
}

.payment-summary-list > div:nth-child(n + 4) {
    border-top: 1px solid var(--rule);
}

.audit-summary-list > div:nth-child(n + 4) {
    border-top: 1px solid var(--rule);
}

.payment-summary-list dt,
.audit-summary-list dt {
    color: var(--muted);
    font-size: 0.875rem;
}

.payment-summary-list dd {
    margin: 0.2rem 0 0;
    overflow-wrap: anywhere;
    font-weight: 700;
}

.audit-summary-list dd {
    margin: 0.2rem 0 0;
    overflow-wrap: anywhere;
    font-weight: 700;
}

.allocation-fieldset {
    min-width: 0;
    margin: 0;
    padding: 1rem;
    border: 1px solid var(--rule);
}

.allocation-fieldset legend {
    padding: 0 0.35rem;
    font-weight: 750;
}

.allocation-list {
    margin-top: 0.8rem;
}

.allocation-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(8rem, 10rem);
    gap: 1rem;
    align-items: start;
    padding: 0.8rem 0;
    border-top: 1px solid var(--rule);
}

.allocation-copy {
    display: grid;
    gap: 0.2rem;
    padding-top: 0.35rem;
}

.allocation-copy strong {
    overflow-wrap: anywhere;
}

.allocation-amount label {
    font-size: 0.875rem;
}

.payment-actions {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.audit-actions {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.purchase-submit-bar {
    display: contents;
}

.share-fieldset {
    min-width: 0;
    margin: 0;
    padding: 1rem;
    border: 1px solid var(--rule);
}

.share-fieldset legend {
    padding: 0 0.35rem;
    font-weight: 750;
}

.share-list {
    display: grid;
    gap: 0.75rem;
    margin-top: 0.8rem;
}

.share-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(8rem, 0.65fr) auto;
    gap: 0.75rem;
    align-items: start;
    padding-top: 0.75rem;
    border-top: 1px solid var(--rule);
}

.share-row:first-child {
    padding-top: 0;
    border-top: 0;
}

.share-remove {
    margin-top: 1.8rem;
}

.share-add {
    margin-top: 0.9rem;
}

.field-optional {
    color: var(--muted);
    font-weight: 400;
}

.purchase-summary,
.purchase-shares-detail {
    margin-top: 1.25rem;
}

.detail-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin: 0;
}

.detail-list > div {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--rule);
}

.detail-list > div + div {
    border-left: 1px solid var(--rule);
}

.detail-list dd {
    margin: 0.2rem 0 0;
    font-weight: 750;
}

.share-detail {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--rule);
}

.share-detail-heading,
.installment-list li {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 1rem;
    align-items: baseline;
}

.installment-list {
    margin: 0.8rem 0 0;
    padding: 0;
    list-style: none;
}

.installment-list li {
    grid-template-columns: minmax(6rem, 1fr) minmax(6rem, auto) minmax(6rem, auto);
    padding: 0.55rem 0;
    border-top: 1px solid var(--rule);
}

.flash,
.error-summary {
    width: min(100% - 2rem, 74rem);
    margin: 1rem auto 0;
    padding: 0.8rem 1rem;
    border: 1px solid currentColor;
}

.flash-success {
    background: var(--success-soft);
    color: var(--success);
}

.flash-entry {
    max-width: 56rem;
}

.flash-error,
.error-summary {
    background: var(--error-soft);
    color: var(--error);
}

.error-summary {
    display: grid;
    width: 100%;
    margin: 0;
}

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

input,
select,
button,
a {
    transition: color 120ms ease-out, background-color 120ms ease-out, border-color 120ms ease-out;
}

@media (max-width: 760px) {
    .app-header,
    .header-actions {
        align-items: stretch;
        flex-direction: column;
        gap: 0.5rem;
    }

    .app-header {
        padding-bottom: 0;
    }

    .header-actions {
        width: 100%;
    }

    nav {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    nav a {
        justify-content: center;
        padding-inline: 0.35rem;
    }

    .logout-form {
        position: absolute;
        top: 0.6rem;
        right: 0.5rem;
        border-left: 0;
    }

    .workspace,
    .login-workspace {
        width: min(100% - 1rem, 74rem);
        padding-top: 1.5rem;
    }

    .page-heading {
        align-items: start;
        flex-direction: column;
        margin-bottom: 1.25rem;
    }

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

    .form-drawer {
        grid-row: 1;
    }

    .field-row {
        grid-template-columns: 1fr;
    }

    .share-row,
    .allocation-row,
    .payment-summary-list,
    .audit-summary-list,
    .detail-list {
        grid-template-columns: 1fr;
    }

    .payment-summary-list > div + div,
    .audit-summary-list > div + div {
        border-left: 0;
        border-top: 1px solid var(--rule);
    }

    .payment-actions {
        align-items: stretch;
        flex-direction: column-reverse;
    }

    .payment-actions .button-secondary {
        width: 100%;
    }

    .audit-actions {
        align-items: stretch;
        flex-direction: column-reverse;
    }

    .audit-actions .button-primary,
    .audit-actions .button-secondary {
        width: 100%;
    }

    .obligation-filters {
        align-items: stretch;
        flex-direction: column;
    }

    .obligation-filters .field,
    .obligation-filters .check-field,
    .obligation-filters .button-secondary {
        width: 100%;
    }

    .installment-list li {
        grid-template-columns: minmax(0, 1fr) auto auto;
        gap: 0.5rem;
    }

    .installment-list li span:nth-child(2),
    .installment-list li strong {
        white-space: nowrap;
    }

    .share-remove {
        width: 100%;
        margin-top: 0;
    }

    .detail-list > div + div {
        border-left: 0;
    }

    .button-primary {
        width: 100%;
    }

    .purchase-submit-bar {
        display: block;
        position: sticky;
        z-index: 2;
        bottom: 0;
        margin-inline: -1.25rem;
        padding: 0.75rem 1.25rem max(0.75rem, env(safe-area-inset-bottom));
        border-top: 1px solid var(--rule);
        background: var(--sheet);
    }

    .record-list li {
        align-items: start;
        flex-direction: column;
    }

    .record-values {
        text-align: left;
    }

    .card-overview-link {
        grid-template-columns: 1fr;
        gap: 0.35rem;
    }

    .card-overview-link > span:last-child {
        text-align: left;
    }

    .invoice-row { align-items: start; flex-direction: column; }
    .invoice-total { text-align: left; }
    .invoice-entry summary { grid-template-columns: minmax(0, 1fr) auto; }
    .invoice-entry summary > span:last-child { grid-column: 1 / -1; }
}

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

    .workspace-grid,
    .login-panel {
        animation: none;
    }
}
