/* BlockReg - calm, touch-friendly styling */

:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --border: #e3e6ea;
    --text: #1f2933;
    --muted: #6b7682;
    --brand: #d0181f;
    --brand-dark: #a8131a;
    --primary: #1f2933;
    --success: #1e7d4f;
    --success-bg: #e7f4ec;
    --danger: #b42318;
    --danger-bg: #fdecea;
    --radius: 14px;
    --tap: 56px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

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

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 17px;
    line-height: 1.5;
    -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { margin: 0 0 .5em; line-height: 1.2; font-weight: 650; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }

.icon { width: 1.25em; height: 1.25em; flex: none; }

/* ---------- Top bar ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    padding-top: max(10px, env(safe-area-inset-top));
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); min-width: 0; }
.brand-full { height: 28px; width: auto; display: block; }
.brand-mark { display: none; height: 36px; width: 36px; }
.brand-name { display: none; font-weight: 700; font-size: 1.15rem; }

.topnav { display: flex; gap: 8px; }

@media (max-width: 640px) {
    .brand-full { display: none; }
    .brand-mark, .brand-name { display: block; }
    .topnav .btn span { display: none; }
    .topnav .btn { width: 48px; padding: 0; }
}

/* ---------- Page ---------- */

.page {
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 16px 48px;
    padding-bottom: max(48px, env(safe-area-inset-bottom));
}

.narrow { max-width: 480px; margin: 0 auto; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
}

@media (max-width: 480px) {
    .card { padding: 20px 16px; }
}

.muted { color: var(--muted); }
.center { text-align: center; }

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    padding: 0 18px;
    border: 1px solid transparent;
    border-radius: 12px;
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    touch-action: manipulation;
    transition: background-color .15s, border-color .15s, transform .05s;
}
.btn:active { transform: scale(.98); }
.btn:focus-visible, .input:focus-visible, .tile:focus-visible {
    outline: 3px solid rgba(208, 24, 31, .35);
    outline-offset: 2px;
}

.btn-lg { min-height: var(--tap); font-size: 1.1rem; width: 100%; }

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }

.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #8f1c13; }

.btn-icon { width: 44px; min-height: 44px; padding: 0; background: transparent; color: var(--muted); }
.btn-icon:hover { background: var(--danger-bg); color: var(--danger); }

.btn[aria-disabled="true"] { opacity: .35; pointer-events: none; }

/* ---------- Home tiles ---------- */

.tiles {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

@media (max-width: 720px) {
    .tiles { grid-template-columns: 1fr; }
}

.tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    min-height: 180px;
    padding: 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    color: var(--text);
    text-decoration: none;
    font-size: 1.2rem;
    font-weight: 600;
    transition: border-color .15s, transform .05s;
}
.tile:hover { border-color: #c9ced4; }
.tile:active { transform: scale(.99); }
.tile .icon { width: 44px; height: 44px; color: var(--muted); }
.tile-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.tile-primary .icon { color: #fff; }
.tile-primary:hover { border-color: var(--brand-dark); background: var(--brand-dark); }

@media (max-width: 720px) {
    .tile { flex-direction: row; justify-content: flex-start; min-height: 88px; padding: 20px 24px; gap: 18px; }
    .tile .icon { width: 32px; height: 32px; }
}

/* ---------- Forms ---------- */

.field { margin-bottom: 20px; }
.field label { display: block; font-weight: 600; margin-bottom: 8px; }
.field .hint { font-size: .9rem; color: var(--muted); margin-top: 6px; }

.input {
    display: block;
    width: 100%;
    min-height: var(--tap);
    padding: 12px 16px;
    font: inherit;
    font-size: 1.1rem; /* >= 16px prevents iOS zoom on focus */
    color: var(--text);
    background: var(--surface);
    border: 1px solid #cfd4da;
    border-radius: 12px;
    appearance: none;
}
.input:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px rgba(208, 24, 31, .15); }

.input-weight {
    min-height: 80px;
    font-size: 2.4rem;
    font-weight: 700;
    text-align: center;
    letter-spacing: .02em;
}

.input-unit { position: relative; }
.input-unit::after {
    content: "kg";
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 1.2rem;
    pointer-events: none;
}

fieldset.field { border: 0; padding: 0; margin: 0 0 20px; min-width: 0; }
fieldset.field legend { font-weight: 600; margin-bottom: 8px; padding: 0; }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice { position: relative; }
.choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.choice span {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 96px;
    padding: 12px;
    border: 2px solid #cfd4da;
    border-radius: 12px;
    background: var(--surface);
    font-size: 1.15rem;
    font-weight: 650;
    text-align: center;
    cursor: pointer;
    touch-action: manipulation;
    transition: border-color .15s, background-color .15s;
}
.choice small { font-size: .9rem; font-weight: 400; color: var(--muted); }
.choice input:checked + span { border-color: var(--brand); background: #fdf1f1; color: var(--brand-dark); }
.choice input:checked + span small { color: var(--brand-dark); }
.choice input:focus-visible + span { outline: 3px solid rgba(208, 24, 31, .35); outline-offset: 2px; }

/* ---------- Alerts ---------- */

.alert {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    margin-bottom: 20px;
    border-radius: var(--radius);
    font-size: 1.05rem;
}
.alert .icon { width: 28px; height: 28px; }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-danger { background: var(--danger-bg); color: var(--danger); }

/* ---------- Login ---------- */

.login {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
}
.login .card { width: 100%; max-width: 420px; }
.login-logo { display: block; width: 88px; height: 88px; margin: 0 auto 12px; }

/* ---------- Table ---------- */

.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 14px 8px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { font-size: .85rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }
.table .id { color: var(--muted); }
.table .id small { display: block; color: var(--text); }
.table .when small { display: block; color: var(--muted); }
.table .action { width: 44px; padding: 4px 0 4px 4px; text-align: right; }

/* ---------- Modal ---------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(16, 24, 40, .55);
}
.modal {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 20px 40px rgba(16, 24, 40, .25);
    padding: 24px;
}
.modal p { margin: 0 0 12px; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 20px; }

.summary {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}
.stat-label { font-size: .9rem; color: var(--muted); }
.stat-value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; }
.pager .btn { min-width: 56px; }

/* ---------- Bar charts ---------- */

.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.chart-total { color: var(--muted); font-variant-numeric: tabular-nums; }

.chart {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 220px;
    padding-top: 8px;
    border-bottom: 1px solid var(--border);
}
.chart-col { flex: 1 1 0; min-width: 0; height: 100%; display: flex; align-items: flex-end; }
.chart-bar {
    width: 100%;
    background: var(--brand);
    border-radius: 4px 4px 0 0;
    min-height: 2px;
}
.chart-bar.empty { background: var(--border); }
.chart-labels { display: flex; gap: 3px; margin-top: 6px; font-size: .75rem; color: var(--muted); }
.chart-labels span { flex: 1 1 0; min-width: 0; text-align: center; overflow: hidden; white-space: nowrap; }

.chart-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chart-scroll .chart, .chart-scroll .chart-labels { min-width: 640px; }

.year-nav { display: flex; align-items: center; justify-content: center; gap: 16px; margin-bottom: 20px; }
.year-nav strong { font-size: 1.4rem; min-width: 4ch; text-align: center; }
.year-nav .btn { width: 56px; padding: 0; }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
