/* Moving Matters — shared moving-budget tracker. Clean, mobile-friendly UI. */

:root {
    --bg: #f4f6f8;
    --card: #ffffff;
    --ink: #1f2933;
    --muted: #6b7785;
    --line: #e2e8f0;
    --brand: #2563eb;
    --brand-dark: #1d4ed8;
    --ok: #15803d;
    --ok-bg: #dcfce7;
    --err: #b91c1c;
    --err-bg: #fee2e2;
    --over: #b91c1c;
    --under: #15803d;
    --radius: 12px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .9rem 1.25rem;
    background: var(--brand);
    color: #fff;
}
.brand { font-weight: 700; font-size: 1.15rem; }
.who { display: flex; align-items: center; gap: 1rem; font-size: .9rem; }
/* Logout sits on the blue topbar — force a light color (brand-on-brand would be invisible). */
.who .link { color: #fff; opacity: .9; }
.who .link:hover { opacity: 1; color: #fff; }

.wrap { max-width: 1000px; margin: 1.5rem auto; padding: 0 1rem; }
.foot { text-align: center; color: var(--muted); padding: 2rem 1rem; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}
h1 { margin: 0 0 .25rem; }
h2 { margin: 0 0 1rem; font-size: 1.15rem; }
h3 { margin: 1rem 0 .5rem; font-size: .9rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.muted { color: var(--muted); }

/* Forms */
.stack { display: flex; flex-direction: column; gap: .85rem; }
.row { display: flex; gap: .85rem; }
.row > label { flex: 1; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; font-weight: 600; color: #374151; }
input[type=text], input[type=password], select {
    font: inherit;
    padding: .55rem .65rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--brand); border-color: var(--brand); }

button { font: inherit; cursor: pointer; }
button.primary {
    background: var(--brand);
    color: #fff;
    border: 0;
    padding: .6rem 1rem;
    border-radius: 8px;
    font-weight: 600;
}
button.primary:hover { background: var(--brand-dark); }
button.link { background: none; border: 0; color: var(--brand); padding: .2rem .35rem; font-weight: 600; }
button.link:hover { text-decoration: underline; }
button.link.danger { color: var(--err); }
form.inline { display: inline; }

/* Login */
.login { max-width: 380px; margin: 3rem auto; }

/* Summary cards */
.summary {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.stat {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: .25rem;
}
.stat-label { font-size: .8rem; color: var(--muted); }
.stat-value { font-size: 1.35rem; font-weight: 700; }
.stat-value.over { color: var(--over); }
.stat-value.under { color: var(--under); }

.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; align-items: start; }

/* Breakdown bars */
.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.bars li { display: grid; grid-template-columns: 9rem 1fr auto; align-items: center; gap: .6rem; font-size: .85rem; }
.bar-track { background: var(--line); border-radius: 6px; height: 10px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--brand); }
.bar-amt { font-variant-numeric: tabular-nums; }
.people { list-style: none; margin: 0; padding: 0; }
.people li { display: flex; justify-content: space-between; padding: .35rem 0; border-bottom: 1px solid var(--line); font-size: .9rem; }

/* Items table */
.table-wrap { overflow-x: auto; }
table.items { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.items th, table.items td { padding: .6rem .5rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.items th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
table.items .num { text-align: right; font-variant-numeric: tabular-nums; }
input.mini, select.mini { width: auto; max-width: 7rem; padding: .3rem .4rem; display: inline-block; }

/* Tabs (pure CSS: radios toggle panels) */
.tab-radio { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.tab-nav { display: flex; gap: .25rem; border-bottom: 2px solid var(--line); margin-bottom: 1.25rem; }
.tab-btn {
    padding: .6rem 1.1rem;
    cursor: pointer;
    font-weight: 600;
    color: var(--muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    user-select: none;
}
.tab-btn:hover { color: var(--ink); }
.tab-panel { display: none; }
/* Show the panel whose radio is checked; highlight its tab button. */
#tab-expenses:checked ~ #panel-expenses,
#tab-budget:checked   ~ #panel-budget { display: block; }
#tab-expenses:checked ~ .tab-nav .tab-btn[for="tab-expenses"],
#tab-budget:checked   ~ .tab-nav .tab-btn[for="tab-budget"] {
    color: var(--brand);
    border-bottom-color: var(--brand);
}
/* Keyboard focus visibility for the (visually hidden) radios. */
#tab-expenses:focus-visible ~ .tab-nav .tab-btn[for="tab-expenses"],
#tab-budget:focus-visible   ~ .tab-nav .tab-btn[for="tab-budget"] { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Budget status banner (Expenses tab) */
.budget-status .bs-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.budget-status .bs-head h2 { margin: 0 0 .75rem; }

/* Budget overview */
.budget-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.budget-head h2 { margin: 0; }
.inline-set, .target-add { display: flex; align-items: flex-end; gap: .6rem; flex-wrap: wrap; }
.target-add { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.inline-label { font-size: .8rem; }
input.mini-wide { width: 9rem; }
button.primary.small { padding: .5rem .8rem; }

.progress { background: var(--line); border-radius: 8px; height: 16px; overflow: hidden; margin: 1rem 0 .5rem; }
.progress-fill { display: block; height: 100%; background: var(--brand); transition: width .25s; }
.progress-fill.over, .bar-fill.over { background: var(--over); }
.progress-legend { margin: 0; font-size: .95rem; }
.progress-legend .over { color: var(--over); font-weight: 600; }
.progress-legend .under { color: var(--under); font-weight: 600; }

table.targets { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.targets th, table.targets td { padding: .55rem .5rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.targets th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
table.targets .num { text-align: right; font-variant-numeric: tabular-nums; }
table.targets .over { color: var(--over); }
table.targets .under { color: var(--under); }
table.targets .bar-track { min-width: 90px; }

/* Status badges */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.badge.status-planned   { background: #e0e7ff; color: #3730a3; }
.badge.status-purchased { background: #fef3c7; color: #92400e; }
.badge.status-paid      { background: var(--ok-bg); color: var(--ok); }

/* Row actions */
td.actions { white-space: nowrap; }
td.actions .link { padding: .2rem .4rem; }

/* Edit form */
.edit-card { max-width: 560px; }
.form-actions { display: flex; align-items: center; gap: 1rem; }
.btn-cancel { color: var(--muted); font-weight: 600; text-decoration: none; }
.btn-cancel:hover { text-decoration: underline; }
small.small, .muted.small { font-size: .8rem; }

/* Alerts */
.alert { padding: .7rem 1rem; border-radius: 8px; margin: 0 0 1rem; font-size: .9rem; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.error { background: var(--err-bg); color: var(--err); }

/* Mobile */
@media (max-width: 760px) {
    .summary { grid-template-columns: repeat(2, 1fr); }
    .cols { grid-template-columns: 1fr; }
    .row { flex-direction: column; }
    .bars li { grid-template-columns: 6rem 1fr auto; }
}

/* Narrow phones (e.g. iPhone 12 mini, 360px): collapse data tables into stacked cards
   so every field + the row actions are reachable without horizontal scrolling. */
@media (max-width: 600px) {
    .wrap { padding: 0 .75rem; }
    .card { padding: 1rem; }

    table.items, table.targets,
    table.items tbody, table.targets tbody,
    table.items tr, table.targets tr,
    table.items td, table.targets td { display: block; width: 100%; }

    table.items thead, table.targets thead { display: none; }   /* labels move into each cell */

    table.items tr, table.targets tr {
        border: 1px solid var(--line);
        border-radius: 10px;
        padding: .55rem .8rem;
        margin-bottom: .75rem;
    }

    table.items td, table.targets td {
        border: 0;
        padding: .3rem 0;
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: 1rem;
        text-align: right;
    }
    table.items td.num, table.targets td.num { text-align: right; }

    /* Field label, from the cell's data-label attribute. */
    table.items td::before, table.targets td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--muted);
        font-size: .78rem;
        text-align: left;
    }

    /* Lead cell (item name / category) = full-width card title, no inline label. */
    table.items td.cell-item, table.targets td.cell-item {
        display: block;
        text-align: left;
        font-size: 1.02rem;
        border-bottom: 1px solid var(--line);
        padding-bottom: .45rem;
        margin-bottom: .25rem;
    }
    table.items td.cell-item::before, table.targets td.cell-item::before { display: none; }

    /* Actions row: buttons grouped to the right, label pushed left. */
    table.items td.actions { justify-content: flex-end; gap: 1rem; padding-top: .5rem; }
    table.items td.actions::before { margin-right: auto; }

    /* Progress bar fills the available width in its card row. */
    table.targets td[data-label="Progress"] .bar-track { flex: 1; min-width: 0; }
}
