/*
 * Lyzor: a household expense log, used mostly on a phone right after paying.
 * Dark graphite base, warm paper-white text, Baltic amber for the one main action and the current tab.
 * One typeface (Bricolage Grotesque); its width axis does the work: condensed and heavy for money, normal for text.
 * Mobile first: everything is sized for a phone, and wider screens just get a centred column.
 */

/*
 * Bricolage Grotesque, self-hosted (wwwroot/fonts, SIL Open Font License in OFL.txt there).
 * One variable file per character subset, each covering every weight (300–800), width (75–100%) and optical size.
 * The browser only downloads a subset when the page uses a character in its unicode-range:
 * latin for the basics and €, latin-ext for ą č ę ė į š ų ū ž.
 */
@font-face {
    font-family: "Bricolage Grotesque";
    font-style: normal;
    font-weight: 300 800;
    font-stretch: 75% 100%;
    font-display: swap;
    src: url("/fonts/bricolage-grotesque-latin-ext.woff2") format("woff2");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
    font-family: "Bricolage Grotesque";
    font-style: normal;
    font-weight: 300 800;
    font-stretch: 75% 100%;
    font-display: swap;
    src: url("/fonts/bricolage-grotesque-latin.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
    color-scheme: dark; /* dark native date/month pickers, selects and scrollbars */
    --bg: #202020;
    --surface: #2a2a28;
    --line: #3a3936;
    --text: #eeeae3;
    --muted: #a19c94;
    --amber: #e8a33d;
    --amber-ink: #231807; /* text on amber */
    --error: #ff8a76;

    --font: "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", sans-serif;
    --radius: 10px;
    --column: 34rem;
    --tabbar-height: 4.25rem;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    /* 16px: inputs below 16px make iOS zoom in when tapped. */
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    line-height: 1.45;
    -webkit-tap-highlight-color: transparent;
}

main {
    max-width: var(--column);
    margin: 0 auto;
    padding: 0 1rem 2rem;
}

/* Room for the fixed tab bar, so the last row can scroll above it. */
body.app main {
    padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom) + 2rem);
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: 1.75rem;
    font-weight: 700;
    font-stretch: 85%;
    line-height: 1.15;
    margin: 0.5rem 0 1.5rem;
}

a {
    color: var(--amber);
}

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

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.icon {
    display: block;
    width: 1.5rem;
    height: 1.5rem;
}

.icon-button {
    display: inline-grid;
    place-items: center;
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--muted);
    cursor: pointer;
}

.icon-button:hover {
    color: var(--text);
    background: var(--surface);
}

/* ---------- Header ---------- */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: var(--column);
    margin: 0 auto;
    padding: calc(env(safe-area-inset-top) + 0.5rem) 0.5rem 0 1rem;
}

.app-header form {
    margin: 0;
}

.wordmark {
    font-size: 1.25rem;
    font-weight: 800;
    font-stretch: 75%;
    color: var(--text);
    text-decoration: none;
}

/* ---------- Bottom tab bar ---------- */

.tabbar {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 10;
    display: flex;
    justify-content: center;
    padding: 0.375rem 0.5rem calc(0.375rem + env(safe-area-inset-bottom));
    background: var(--bg);
    background: color-mix(in srgb, var(--bg) 90%, transparent);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--line);
}

.tab {
    flex: 1 1 0;
    max-width: 11rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.125rem;
    padding: 0.375rem 0;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 500;
    text-decoration: none;
}

.tab[aria-current="page"] {
    color: var(--text);
}

.tab[aria-current="page"] .icon {
    color: var(--amber);
}

/* Adding an expense is the app's main action: an amber disc that rises out of the bar. */
.tab-add .icon,
.tab-add[aria-current="page"] .icon {
    width: 3rem;
    height: 3rem;
    margin-top: -1.375rem;
    padding: 0.75rem;
    border-radius: 50%;
    background: var(--amber);
    color: var(--amber-ink);
    box-shadow: 0 0 0 4px var(--bg);
}

/* ---------- Month: switcher, total, split ---------- */

.month-switcher {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0.5rem -0.5rem 0;
}

/* The month name is the heading; a transparent native month input lies on top so tapping it opens the picker. */
.month-picker {
    position: relative;
    border-radius: var(--radius);
}

.month-picker h1 {
    margin: 0;
    padding: 0.375rem 0.75rem;
    font-size: 1.125rem;
    font-weight: 600;
    font-stretch: 100%;
}

.month-picker input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.month-picker:focus-within {
    outline: 2px solid var(--amber);
    outline-offset: 2px;
}

/* The one loud thing in the app: how much went out this month. */
.total {
    display: flex;
    align-items: baseline;
    gap: 0.375rem;
    margin: 1.25rem 0 0.75rem;
    font-variant-numeric: tabular-nums;
}

.total-number {
    font-size: clamp(3.25rem, 17vw, 4.75rem);
    font-weight: 800;
    font-stretch: 75%;
    line-height: 0.9;
    letter-spacing: -0.02em;
}

.total-currency {
    font-size: 1.75rem;
    font-weight: 600;
    font-stretch: 75%;
    color: var(--muted);
}

/* Who paid how much, under the total. */
.split {
    display: grid;
    gap: 0.25rem;
    margin: 0 0 1.75rem;
}

.split div {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.split dt {
    color: var(--muted);
}

.split dd {
    margin: 0;
    font-variant-numeric: tabular-nums;
}

/* ---------- Expense list, grouped by day ---------- */

.day + .day {
    margin-top: 1.5rem;
}

.day-name {
    margin: 0 0 0.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--muted);
}

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

.rows li {
    border-bottom: 1px solid var(--line);
}

.rows li:last-child {
    border-bottom: 0;
}

/* Each row is a link to edit it. The negative margin lets the pressed/hover background reach slightly past the
   text, while the text stays aligned with the rest of the page. */
.row {
    display: grid;
    grid-template-columns: 1fr auto;
    column-gap: 1rem;
    margin: 0 -0.5rem;
    padding: 0.75rem 0.5rem;
    border-radius: 8px;
    color: inherit;
    text-decoration: none;
}

.row:hover,
.row:active {
    background: var(--surface);
}

.row-title {
    font-weight: 500;
}

.row-amount {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-align: right;
    white-space: nowrap;
}

.row-details {
    grid-column: 1 / -1;
    font-size: 0.875rem;
    color: var(--muted);
}

.row-details:empty {
    display: none;
}

.empty {
    display: grid;
    justify-items: start;
    gap: 1rem;
    margin-top: 2.5rem;
    color: var(--muted);
}

/* ---------- Buttons ---------- */

.button,
.submit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 3rem;
    padding: 0 1.25rem;
    border: 0;
    border-radius: var(--radius);
    background: var(--amber);
    color: var(--amber-ink);
    font: inherit;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}

.submit:disabled {
    cursor: progress;
}

/* In a full form the button spans the width, where a thumb can't miss it. */
form:not(.inline-form) .submit {
    width: 100%;
    margin-top: 0.5rem;
}

/* Under the edit form: cancel on the left, delete on the right, both quieter than the save button. */
.secondary-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 1.5rem;
}

.secondary-actions form {
    margin: 0;
}

.danger-button {
    min-height: 3rem;
    padding: 0 1rem;
    border: 1px solid color-mix(in srgb, var(--error) 45%, transparent);
    border-radius: var(--radius);
    background: none;
    color: var(--error);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

/* ---------- Form fields ---------- */

.field {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    margin-bottom: 1rem;
}

.field label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--muted);
}

.field input,
.field select {
    width: 100%;
    min-height: 3rem;
    padding: 0 0.875rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 1rem;
}

.field input:focus,
.field select:focus {
    border-color: var(--amber);
}

.field select {
    appearance: none;
    padding-right: 2.75rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a19c94' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.875rem center;
    background-size: 1.25rem;
}

/* The amount, set like the month total: it's the number that matters. */
.field input.amount-input {
    min-height: 4.25rem;
    font-size: 2.5rem;
    font-weight: 800;
    font-stretch: 75%;
    font-variant-numeric: tabular-nums;
}

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

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

form > .error {
    margin-bottom: 1rem;
}

/* A field and its button side by side (add category, add sub-category). */
.inline-form {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: start;
    gap: 0 0.5rem;
}

.inline-form .field {
    margin-bottom: 0;
}

/* Line the button up with the input, below the label (label line height + gap).
   Secondary look: a page can have one of these per category, and amber is kept for the main action. */
.inline-form .submit {
    margin-top: calc(0.875rem * 1.45 + 0.375rem);
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text);
    font-weight: 600;
}

/* ---------- Categories ---------- */

#category-list {
    margin-top: 1.75rem;
}

.category {
    padding: 1.25rem 0;
    border-top: 1px solid var(--line);
}

.category h2 {
    margin-bottom: 0.625rem;
    font-size: 1.25rem;
    font-weight: 700;
    font-stretch: 85%;
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin: 0 0 1rem;
    padding: 0;
    list-style: none;
}

.chips li {
    padding: 0.25rem 0.75rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 0.875rem;
}

.muted {
    margin-bottom: 1rem;
    color: var(--muted);
}

/* ---------- Plain pages (login, register) ---------- */

body.plain main {
    max-width: 24rem;
    padding-top: max(2rem, 14vh);
}

.wordmark-large {
    margin: 0 0 2rem;
    font-size: 3.5rem;
    font-weight: 800;
    font-stretch: 75%;
    line-height: 1;
}

body.plain main > p {
    margin-top: 1.5rem;
    color: var(--muted);
}

/* ---------- Loading spinner ---------- */

/* htmx injects these rules itself, but only once its script has run; defined here too so a spinner
   never flashes while the page is still loading. */
.htmx-indicator {
    opacity: 0;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    opacity: 1;
    transition: opacity 200ms ease-in;
}

/* Add the htmx-indicator class so it only shows during an htmx request (see Lzml.SubmitButton). */
.spinner {
    display: inline-block;
    width: 1em;
    height: 1em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spinner-rotate 0.7s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
    .spinner {
        animation-duration: 2s;
    }
}

/* Submit button: the spinner is laid over the centre of the label instead of taking space beside it. */
.submit {
    position: relative;
}

.submit .spinner {
    position: absolute;
    inset: 0;
    margin: auto;
}

/* While the form's request runs, hide the label (keeping its space) so only the spinner shows. */
.htmx-request .submit .submit-label {
    visibility: hidden;
}
