/* ==========================================================================
   ExpenseList – Material Design 3, green (hue ~145)
   ========================================================================== */

/* ---------- Colour tokens (M3 baseline roles, green tonal palette) ---------- */
:root {
    color-scheme: light dark;

    --md-primary: #286b3a;
    --md-on-primary: #ffffff;
    --md-primary-container: #aef3b5;
    --md-on-primary-container: #00210c;
    --md-secondary-container: #d3e8d1;
    --md-on-secondary-container: #0f1f13;
    --md-surface: #f7f8f2;
    --md-surface-container-low: #f1f3ec;
    --md-surface-container: #ebefe6;
    --md-surface-container-high: #e5e9e0;
    --md-on-surface: #191c16;
    --md-on-surface-variant: #424940;
    --md-outline: #72796f;
    --md-outline-variant: #c2c9bd;
    --md-error: #ba1a1a;
    --md-error-container: #ffdad6;
    --md-on-error-container: #410002;
    --md-inverse-surface: #2e3129;
    --md-inverse-on-surface: #eff1e8;
    --md-scrim: rgba(0, 0, 0, 0.32);

    --md-shadow-1: 0 1px 2px rgba(0, 0, 0, .30), 0 1px 3px 1px rgba(0, 0, 0, .15);
    --md-shadow-3: 0 1px 3px rgba(0, 0, 0, .30), 0 4px 8px 3px rgba(0, 0, 0, .15);

    --md-font: Roboto, "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --md-shape-s: 8px;
    --md-shape-m: 12px;
    --md-shape-l: 16px;
    --md-shape-xl: 28px;
    --modal-size: min(100vw, 600px);
}

@media (prefers-color-scheme: dark) {
    :root {
        --md-primary: #92d79c;
        --md-on-primary: #00391a;
        --md-primary-container: #0a5229;
        --md-on-primary-container: #aef3b5;
        --md-secondary-container: #394b3b;
        --md-on-secondary-container: #d3e8d1;
        --md-surface: #191c16;
        --md-surface-container-low: #1f231c;
        --md-surface-container: #23271f;
        --md-surface-container-high: #2d312a;
        --md-on-surface: #e1e4da;
        --md-on-surface-variant: #c2c9bd;
        --md-outline: #8c9388;
        --md-outline-variant: #424940;
        --md-error: #ffb4ab;
        --md-error-container: #93000a;
        --md-on-error-container: #ffdad6;
        --md-inverse-surface: #e1e4da;
        --md-inverse-on-surface: #2e3129;
        --md-scrim: rgba(0, 0, 0, 0.6);
    }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--md-font);
    font-size: 16px;
    line-height: 1.5;
    letter-spacing: .5px;
    color: var(--md-on-surface);
    background: var(--md-surface);
    -webkit-font-smoothing: antialiased;
}

h1, h2, p { margin: 0; }

button, input, select { font: inherit; letter-spacing: inherit; color: inherit; }

svg { width: 24px; height: 24px; fill: currentColor; flex: none; }

[hidden] { display: none !important; }

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

/* ---------- Buttons ---------- */
.icon-button {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--md-on-surface-variant);
    cursor: pointer;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}
.icon-button::before,
.text-button::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: currentColor;
    opacity: 0;
    transition: opacity .15s;
}
.icon-button:hover::before, .text-button:hover::before { opacity: .08; }
.icon-button:active::before, .text-button:active::before { opacity: .12; }

.icon-button.filled {
    background: var(--md-primary);
    color: var(--md-on-primary);
}
.icon-button.small { width: 40px; height: 40px; }
.icon-button.small svg { width: 20px; height: 20px; }

.text-button {
    position: relative;
    min-height: 40px;
    padding: 0 12px;
    border: 0;
    border-radius: 20px;
    background: transparent;
    color: var(--md-primary);
    font-weight: 500;
    letter-spacing: .1px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.text-button:disabled { opacity: .38; cursor: default; }
.text-button.danger { color: var(--md-error); }

/* ---------- Login page ---------- */
.login-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.login-card {
    width: 100%;
    max-width: 400px;
    padding: 40px 32px 32px;
    border-radius: var(--md-shape-xl);
    background: var(--md-surface-container-low);
    box-shadow: var(--md-shadow-1);
    text-align: center;
}
.login-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    margin-bottom: 16px;
    border-radius: 50%;
    background: var(--md-primary-container);
    color: var(--md-on-primary-container);
}
.login-card h1 { font-size: 28px; line-height: 36px; font-weight: 400; letter-spacing: 0; }
.login-subtitle { margin: 4px 0 24px; font-size: 14px; color: var(--md-on-surface-variant); }
.login-error {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding: 12px 16px;
    border-radius: var(--md-shape-m);
    background: var(--md-error-container);
    color: var(--md-on-error-container);
    font-size: 14px;
    text-align: left;
}
.login-form { display: flex; flex-direction: column; gap: 20px; }

/* Outlined text field with floating label (placeholder=" " trick) */
.text-field { position: relative; }
.text-field input {
    width: 100%;
    height: 56px;
    padding: 0 16px;
    border: 1px solid var(--md-outline);
    border-radius: 4px;
    background: transparent;
    outline: none;
    caret-color: var(--md-primary);
}
.text-field input:hover { border-color: var(--md-on-surface); }
.text-field input:focus { border: 2px solid var(--md-primary); padding: 0 15px; }
.text-field label {
    position: absolute;
    left: 12px;
    top: 16px;
    padding: 0 4px;
    background: var(--md-surface-container-low);
    color: var(--md-on-surface-variant);
    pointer-events: none;
    transform-origin: left top;
    transition: transform .15s ease, color .15s ease;
}
.text-field input:focus + label,
.text-field input:not(:placeholder-shown) + label {
    transform: translateY(-24px) scale(.75);
}
.text-field input:focus + label { color: var(--md-primary); }

.login-button {
    height: 40px;
    margin-top: 4px;
    padding: 0 24px;
    border: 0;
    border-radius: 20px;
    background: var(--md-primary);
    color: var(--md-on-primary);
    font-weight: 500;
    letter-spacing: .1px;
    cursor: pointer;
    transition: box-shadow .15s;
}
.login-button:hover { box-shadow: var(--md-shadow-1); }

/* ---------- App page layout ---------- */
.app-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;           /* only .expense-scroll scrolls */
}
.app-header {
    flex: none;                 /* top bar + balance never scroll away */
    z-index: 2;
    background: var(--md-surface);
}
.top-app-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 64px;
    padding: 0 4px 0 16px;
}
.top-app-bar-title {
    flex: 1;
    font-size: 22px;
    line-height: 28px;
    font-weight: 400;
    letter-spacing: 0;
}
.top-app-bar .icon-button { margin: 0 4px; }

.balance-card {
    margin: 4px 16px 12px;
    padding: 16px 20px;
    border-radius: var(--md-shape-xl);
    background: var(--md-primary-container);
    color: var(--md-on-primary-container);
    text-align: center;
    box-shadow: var(--md-shadow-1);
}
.balance-label { font-size: 14px; line-height: 20px; font-weight: 500; letter-spacing: .1px; }
.balance-amount { font-size: 36px; line-height: 44px; font-weight: 400; letter-spacing: 0; font-variant-numeric: tabular-nums; }
.balance-detail { margin-top: 4px; font-size: 12px; line-height: 16px; letter-spacing: .5px; opacity: .8; }

/* ---------- Expense list ---------- */
.expense-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0 16px 24px;
}
.expense-list {
    list-style: none;
    margin: 0 auto;
    padding: 0;
    max-width: 720px;
}
.expense-row {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 72px;
    padding: 8px 4px 8px 16px;
    border-bottom: 1px solid var(--md-outline-variant);
}
.expense-row:last-child { border-bottom: 0; }
.expense-main { flex: 1; min-width: 0; }
.expense-user { font-size: 12px; line-height: 16px; font-weight: 500; color: var(--md-primary); text-transform: uppercase; letter-spacing: .5px; }
.expense-comment { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.expense-date { font-size: 14px; line-height: 20px; color: var(--md-on-surface-variant); letter-spacing: .25px; }
.expense-amount { flex: none; font-size: 16px; font-weight: 500; font-variant-numeric: tabular-nums; }
.delete-button { flex: none; }
/* keep amounts aligned: rows without a trash icon reserve the same space */
.expense-row:not(:has(.delete-button)) { padding-right: 44px; }

.list-status { padding: 16px; text-align: center; font-size: 14px; color: var(--md-on-surface-variant); }
#sentinel { height: 1px; }

/* ---------- Dialogs: shared ---------- */
dialog {
    padding: 0;
    border: 0;
    color: var(--md-on-surface);
}
dialog::backdrop { background: var(--md-scrim); }

/* ---------- Add-expense modal: screen wide, max 600px, height = width ---------- */
dialog.expense-modal {
    width: var(--modal-size);
    height: var(--modal-size);
    max-width: 100vw;
    max-height: 100dvh;         /* safety net for landscape phones */
    margin: auto;
    border-radius: var(--md-shape-xl);
    background: var(--md-surface-container-high);
    box-shadow: var(--md-shadow-3);
    overflow: hidden;
}
dialog.expense-modal[open] { display: block; }
dialog.expense-modal form {
    display: flex;
    flex-direction: column;
    height: 100%;
}
@media (max-width: 600px) {
    dialog.expense-modal { border-radius: 0; }
}

.modal-header {
    flex: none;
    display: flex;
    align-items: center;
    height: 64px;
    padding: 0 8px;
}
.modal-title {
    flex: 1;
    text-align: center;
    font-size: 22px;
    line-height: 28px;
    font-weight: 400;
    letter-spacing: 0;
}
.close-button { color: var(--md-error); }
.save-button {
    font-variant: small-caps;   /* "save" in small caps */
    font-size: 18px;
    padding: 0 16px;
}

.modal-error {
    flex: none;
    margin: 0 16px 4px;
    padding: 8px 16px;
    border-radius: var(--md-shape-s);
    background: var(--md-error-container);
    color: var(--md-on-error-container);
    font-size: 14px;
    line-height: 20px;
}

/* four rows, spread evenly over the remaining height, label left / field right */
.modal-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 0 24px 16px;
}
.form-row {
    flex: 1 1 0;
    display: grid;
    grid-template-columns: minmax(80px, 30%) 1fr;
    align-items: center;
    gap: 16px;
    border-bottom: 1px solid var(--md-outline-variant);
}
.form-row:last-child { border-bottom: 0; }
.form-row label { font-size: 14px; font-weight: 500; letter-spacing: .1px; color: var(--md-on-surface-variant); }
.form-row input,
.form-row select {
    width: 100%;
    height: 48px;
    padding: 0 12px;
    border: 1px solid var(--md-outline);
    border-radius: 4px;
    background: var(--md-surface-container-high);
    outline: none;
    caret-color: var(--md-primary);
}
.form-row input:hover, .form-row select:hover { border-color: var(--md-on-surface); }
.form-row input:focus, .form-row select:focus { border: 2px solid var(--md-primary); padding: 0 11px; }
.form-row select option { background: var(--md-surface-container-high); color: var(--md-on-surface); }

/* comment suggestions (M3 menu surface) */
.suggest { position: relative; }
.suggest-list {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    z-index: 5;
    margin: 0;
    padding: 4px 0;
    list-style: none;
    overflow-y: auto;
    border-radius: var(--md-shape-s);
    background: var(--md-surface-container);
    box-shadow: var(--md-shadow-3);
}
.suggest-list.up { top: auto; bottom: calc(100% + 4px); }
.suggest-item {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 0 12px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    cursor: pointer;
    color: var(--md-on-surface);
}
.suggest-item strong { font-weight: 700; color: var(--md-primary); }
.suggest-item:hover, .suggest-item.active { background: var(--md-secondary-container); color: var(--md-on-secondary-container); }

.field-suffix { position: relative; }
.field-suffix input { padding-right: 56px; text-align: right; font-variant-numeric: tabular-nums; }
.field-suffix input:focus { padding-right: 55px; }
.field-suffix::after {
    content: attr(data-suffix);
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    color: var(--md-on-surface-variant);
    pointer-events: none;
}

/* ---------- Confirmation dialog ---------- */
dialog.confirm-dialog {
    width: min(calc(100vw - 48px), 312px);
    margin: auto;
    padding: 24px 24px 16px;
    border-radius: var(--md-shape-xl);
    background: var(--md-surface-container-high);
    box-shadow: var(--md-shadow-3);
}
.confirm-dialog h2 { font-size: 24px; line-height: 32px; font-weight: 400; letter-spacing: 0; margin-bottom: 16px; }
.confirm-dialog p { font-size: 14px; line-height: 20px; color: var(--md-on-surface-variant); overflow-wrap: anywhere; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }

/* ---------- Snackbar ---------- */
.snackbar {
    position: fixed;
    left: 50%;
    bottom: 16px;
    z-index: 10;
    max-width: calc(100vw - 32px);
    padding: 14px 16px;
    border-radius: 4px;
    background: var(--md-inverse-surface);
    color: var(--md-inverse-on-surface);
    font-size: 14px;
    line-height: 20px;
    box-shadow: var(--md-shadow-3);
    transform: translate(-50%, 24px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s, transform .2s;
}
.snackbar.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}

