/* ---------------------------------------------------------------------------
   Lickety Split

   One stylesheet, written by hand. The app has perhaps a dozen kinds of thing on
   screen, which is far less than a framework's worth, and the parts that matter
   here — tap targets a thumb can hit, a layout that survives a notch, numbers
   that line up — are the parts a framework would have to be argued with about.

   Mobile first throughout: the single-column rules are the defaults and the only
   media query widens things out for a desktop.
   --------------------------------------------------------------------------- */

:root {
    color-scheme: dark;

    --bg: #101317;
    --surface: #181c22;
    --surface-2: #1f242c;
    --surface-3: #262d37;
    --line: #2a313b;
    --line-strong: #3a4350;

    --text: #e9edf2;
    --muted: #94a1b2;
    --faint: #6b7783;

    --accent: #2dd4bf;
    --accent-dim: #1d8f82;
    --accent-ink: #04201d;

    /* Being owed and owing are the two things the app is about, so they get the
       two clearest colours — and never colour alone: every figure carries a sign
       and a word beside it, for anyone who cannot tell these two apart. */
    --good: #5ee39b;
    --bad: #fb8a9d;
    --warn: #f5c14e;

    --radius: 14px;
    --radius-sm: 10px;

    /* The insets a phone reports for its notch and home bar. Zero everywhere else. */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;

    /* Stops the whole page bouncing on iOS when a list is scrolled past its end,
       which in a standalone app looks like the app itself coming loose. */
    overscroll-behavior-y: none;
}

h1, h2, h3 {
    margin: 0;
    line-height: 1.2;
    font-weight: 650;
    letter-spacing: -0.01em;
}

h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.95rem; }

p { margin: 0 0 0.75rem; }

a {
    color: var(--accent);
    text-decoration: none;
}

/* Numbers in a column have to line up, or a list of amounts is unreadable.
   Tabular figures give every digit the same width. */
.money,
.tnum {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
}

/* --------------------------------------------------------------- boot screen */

.boot {
    position: fixed;
    inset: 0;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 1rem;
    background: var(--bg);
}

.boot-mark {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 3px solid var(--surface-3);
    border-top-color: var(--accent);
    animation: spin 0.9s linear infinite;
}

.boot-text {
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

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

@media (prefers-reduced-motion: reduce) {
    .boot-mark { animation-duration: 3s; }
    * { transition: none !important; }
}

/* -------------------------------------------------------------------- layout */

.app {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: calc(var(--safe-top) + 0.7rem) calc(var(--safe-right) + 1rem) 0.7rem calc(var(--safe-left) + 1rem);
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
}

.topbar-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* The router moves focus to the heading after every navigation so that a screen
   reader starts at the top of the new page. That is worth keeping, but it should
   not leave a box drawn around the title for everybody else. */
.topbar-title:focus {
    outline: none;
}

.topbar-sub {
    display: block;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--muted);
    letter-spacing: 0;
}

main {
    flex: 1;
    width: 100%;
    max-width: 780px;
    margin: 0 auto;
    padding: 1rem calc(var(--safe-right) + 1rem) calc(var(--safe-bottom) + 6rem) calc(var(--safe-left) + 1rem);
}

/* Room at the bottom for the floating action button on a phone; on a desktop the
   button sits in the flow and the gap is not needed. */
@media (min-width: 900px) {
    main {
        max-width: 1040px;
        padding-bottom: calc(var(--safe-bottom) + 2rem);
    }

    .two-up {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 1rem;
        align-items: start;
    }
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.spread {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

/* --------------------------------------------------------------------- cards */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--line);
}

.card-body {
    padding: 1rem;
}

.card-body.tight {
    padding: 0.5rem 0;
}

.section-title {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    margin: 0 0 0.6rem;
}

.section-title h2 {
    color: var(--text);
}

.count {
    font-size: 0.8rem;
    color: var(--faint);
    font-weight: 500;
}

/* ---------------------------------------------------------------------- list */

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

.list > li + li {
    border-top: 1px solid var(--line);
}

.item {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    width: 100%;
    padding: 0.8rem 1rem;
    background: none;
    border: 0;
    color: inherit;
    font: inherit;
    text-align: left;
    /* 44px is the smallest target a thumb reliably hits. */
    min-height: 56px;
}

a.item,
button.item {
    cursor: pointer;
}

a.item:active,
button.item:active {
    background: var(--surface-2);
}

.item-main {
    flex: 1;
    min-width: 0;
}

.item-title {
    display: block;
    font-weight: 550;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.item-note {
    display: block;
    font-size: 0.82rem;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.item-end {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
    text-align: right;
}

.chev {
    color: var(--faint);
    flex-shrink: 0;
}

/* -------------------------------------------------------------------- avatar */

/* Initials rather than a picture: there are no accounts to take one from, and a
   coloured disc is enough to tell five names apart at a glance. */
.avatar {
    display: grid;
    place-content: center;
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--surface-3);
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 650;
    letter-spacing: 0.01em;
}

.avatar.small {
    width: 30px;
    height: 30px;
    font-size: 0.72rem;
}

/* ------------------------------------------------------------------- figures */

.amount {
    font-weight: 650;
    font-variant-numeric: tabular-nums;
}

.amount.good { color: var(--good); }
.amount.bad { color: var(--bad); }
.amount.flat { color: var(--muted); }

.lede {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------- buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    min-height: 48px;
    padding: 0 1.1rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease;
}

.btn:hover:not(:disabled) {
    background: var(--surface-3);
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
}

.btn.primary:hover:not(:disabled) {
    background: color-mix(in srgb, var(--accent) 88%, white);
}

.btn.ghost {
    background: none;
    border-color: transparent;
    color: var(--accent);
}

.btn.ghost:hover:not(:disabled) {
    background: var(--surface-2);
}

.btn.danger {
    background: none;
    border-color: color-mix(in srgb, var(--bad) 45%, transparent);
    color: var(--bad);
}

.btn.danger:hover:not(:disabled) {
    background: color-mix(in srgb, var(--bad) 12%, transparent);
}

.btn.small {
    min-height: 38px;
    padding: 0 0.75rem;
    font-size: 0.85rem;
}

.btn.block {
    width: 100%;
}

.btn-row {
    display: flex;
    gap: 0.6rem;
}

.btn-row .btn {
    flex: 1;
}

/* The one floating control: adding a bill is what the app is for, and on a phone
   it should be reachable without scrolling back to the top. */
.fab {
    position: fixed;
    right: calc(var(--safe-right) + 1rem);
    bottom: calc(var(--safe-bottom) + 1rem);
    z-index: 30;
    min-height: 56px;
    padding: 0 1.35rem;
    border-radius: 28px;
    box-shadow: 0 8px 24px rgb(0 0 0 / 45%);
}

@media (min-width: 900px) {
    /* No need to float on a screen with room for it, but it should not stretch
       the full width of a desktop either — that reads as a banner, not a button. */
    .fab {
        position: static;
        box-shadow: none;
        align-self: center;
        min-width: 16rem;
    }
}

/* -------------------------------------------------------------------- inputs */

label {
    display: block;
    margin-bottom: 0.3rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--muted);
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="number"],
select,
textarea {
    width: 100%;
    min-height: 48px;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    /* 16px exactly: anything smaller and iOS zooms the page when the field is
       focused, and never zooms back out. */
    font-size: 16px;
    font-family: inherit;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.btn:focus-visible,
a:focus-visible,
.item:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

input::placeholder {
    color: var(--faint);
}

.field {
    margin-bottom: 0.9rem;
}

.field-row {
    display: flex;
    gap: 0.6rem;
}

.field-row > * {
    flex: 1;
}

.hint {
    margin: 0.35rem 0 0;
    font-size: 0.8rem;
    color: var(--faint);
}

.hint.warn {
    color: var(--warn);
}

/* An amount field with the currency sign built into it, so the sign cannot be
   typed into the number. */
.money-field {
    position: relative;
}

.money-field span {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
}

.money-field input {
    padding-left: 1.9rem;
}

/* ---------------------------------------------------------------- split rows */

.split-row {
    display: grid;
    /* The percentage column has to hold "33.3333" without clipping it, which is
       what an even three-way split actually is. */
    grid-template-columns: auto minmax(0, 1fr) 7rem 5rem;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0;
}

.split-row + .split-row {
    border-top: 1px solid var(--line);
}

.split-row input[type="number"] {
    min-height: 42px;
    padding: 0.35rem 0.45rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.split-row .share {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--muted);
}

.split-row.out {
    opacity: 0.4;
}

.split-row .name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* A checkbox big enough to hit, which the browser default is not on a phone. */
input[type="checkbox"] {
    width: 22px;
    height: 22px;
    accent-color: var(--accent);
    margin: 0;
}

/* ------------------------------------------------------------------ messages */

.banner {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.75rem 0.9rem;
    border-radius: var(--radius-sm);
    border: 1px solid;
    font-size: 0.88rem;
}

.banner.info {
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    border-color: color-mix(in srgb, var(--accent) 35%, transparent);
    color: var(--text);
}

.banner.warn {
    background: color-mix(in srgb, var(--warn) 10%, transparent);
    border-color: color-mix(in srgb, var(--warn) 35%, transparent);
}

.banner.bad {
    background: color-mix(in srgb, var(--bad) 10%, transparent);
    border-color: color-mix(in srgb, var(--bad) 35%, transparent);
}

.banner p { margin: 0; }
.banner .btn { margin-left: auto; }

.empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--muted);
}

.empty h2 {
    margin-bottom: 0.4rem;
    color: var(--text);
}

/* ---------------------------------------------------------------- sync badge */

.sync {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.6rem;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
}

.dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--faint);
    flex-shrink: 0;
}

.dot.good { background: var(--good); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

.dot.busy {
    background: var(--accent);
    animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
    50% { opacity: 0.25; }
}

/* ------------------------------------------------------------------ settling */

.transfer {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.8rem 1rem;
    flex-wrap: wrap;
}

.transfer .arrow {
    color: var(--faint);
}

.transfer .who {
    font-weight: 600;
}

.transfer .btn {
    margin-left: auto;
}

.settled {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 1.1rem 1rem;
    color: var(--good);
    font-weight: 600;
}

/* --------------------------------------------------------------------- misc */

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.chip {
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    font-size: 0.8rem;
    color: var(--muted);
}

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

hr {
    border: 0;
    border-top: 1px solid var(--line);
    margin: 1rem 0;
}

/* Blazor's own error strip, restyled so it does not look like a different app. */
#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    padding: 0.9rem calc(var(--safe-right) + 1rem) calc(var(--safe-bottom) + 0.9rem) calc(var(--safe-left) + 1rem);
    background: var(--warn);
    color: #1a1500;
    font-weight: 600;
}

#blazor-error-ui a {
    color: #1a1500;
    text-decoration: underline;
}

#blazor-error-ui .dismiss {
    float: right;
    cursor: pointer;
}
