/* Waowao — mobile first (360px), then wider screens. */

:root {
    --c-primary: #1e2178;
    --c-primary-text: #fff;
    --c-accent: #e91e78;
    --c-bg: #f4f5fa;
    --c-surface: #fff;
    --c-text: #1b1d2a;
    --c-muted: #5b5f73;
    --c-border: #d8dae6;
    --c-ok: #136f3a;
    --c-ok-bg: #e3f5ea;
    --c-warn: #8a5300;
    --c-warn-bg: #fff2d6;
    --c-danger: #a3132c;
    --c-danger-bg: #fde6ea;
    --c-info: #0b5f86;
    --c-info-bg: #e2f2fa;

    --c-focus: var(--c-accent);

    --radius: 10px;
    --gap: 12px;
    --tap: 44px;
    /* Latin from the system font; Khmer glyphs fall back to the Khmer fonts already on the phone
       (Noto Sans Khmer on Android, Khmer UI / Leelawadee UI on Windows). No web font: nothing to download on 4G. */
    --font-khmer: "Noto Sans Khmer", "Noto Sans Khmer UI", "Kantumruy Pro", "Battambang", "Khmer UI", "Leelawadee UI", "Khmer OS System", "Khmer Sangam MN";
    --font: system-ui, -apple-system, "Segoe UI", Roboto, var(--font-khmer), sans-serif;
    --line: 1.6;
    --small: .85rem;

    color-scheme: light dark;
    accent-color: var(--c-primary);
}

/* Khmer: diacritics go far above and below the line, small sizes become unreadable. */
:root:lang(km) {
    --font: var(--font-khmer), system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --line: 1.8;
    --small: .9rem;
}

@media (prefers-color-scheme: dark) {
    :root {
        --c-primary: #8f95ff;
        --c-primary-text: #0d0f24;
        --c-bg: #11121a;
        --c-surface: #1b1d29;
        --c-text: #eceef7;
        --c-muted: #a3a7bb;
        --c-border: #343748;
        --c-ok: #7fdca2;
        --c-ok-bg: #133523;
        --c-warn: #ffc966;
        --c-warn-bg: #3a2c0c;
        --c-danger: #ff8fa1;
        --c-danger-bg: #3d1219;
        --c-info: #8fd3f5;
        --c-info-bg: #0f2c3a;
    }
}

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

body {
    margin: 0;
    font-family: var(--font);
    line-height: var(--line);
    color: var(--c-text);
    background: var(--c-bg);
}

h1 { font-size: 1.35rem; margin: 0 0 var(--gap); }
h2 { font-size: 1.1rem; margin: calc(var(--gap) * 2) 0 var(--gap); }
h2 small, h1 small { font-weight: normal; color: var(--c-muted); }
a { color: var(--c-primary); }
.muted { color: var(--c-muted); }
.legend { font-size: .9rem; margin-top: 0; }
.mt { margin-top: var(--gap); }

:focus-visible { outline: 3px solid var(--c-focus); outline-offset: 2px; }
main:focus { outline: none; }

/* Skip link: first thing reached with the keyboard, hidden until focused. */
.skip-link {
    position: absolute; left: 8px; top: -100px; z-index: 20;
    padding: 10px 16px; border-radius: var(--radius);
    background: var(--c-surface); color: var(--c-primary); font-weight: 600;
}
.skip-link:focus { top: 8px; }

/* Turbo's bar shown while a page or a form is on its way (slow 4G). */
.turbo-progress-bar { height: 4px; background: var(--c-accent); }

/* Top bar */
.topbar {
    position: sticky; top: 0; z-index: 10;
    display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px;
    padding: 0 12px;
    background: var(--c-primary); color: var(--c-primary-text);
    --c-focus: var(--c-primary-text);
}
.topbar a { color: var(--c-primary-text); text-decoration: none; }
.brand, .logout, .account { display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 4px; }
.brand { font-weight: 700; }
.topbar nav { display: flex; gap: 2px; overflow-x: auto; order: 3; width: 100%; }
.topbar nav a { padding: 8px 10px; border-radius: 6px; white-space: nowrap; min-height: var(--tap); display: flex; align-items: center; }
.topbar nav a[aria-current="page"] { background: rgba(255,255,255,.18); font-weight: 600; }
.topbar :focus-visible { outline-offset: -3px; }
.logout, .account { font-size: .9rem; }
.account[aria-current="page"] { text-decoration: underline; text-underline-offset: 4px; }
.lang-switch { margin-left: auto; display: flex; gap: 2px; font-size: .9rem; }
.lang-switch a, .lang-switch strong { padding: 8px; min-height: var(--tap); display: flex; align-items: center; }
.lang-switch strong { text-decoration: underline; text-underline-offset: 4px; }
.lang-corner { display: flex; justify-content: flex-end; padding: 6px 12px; }
.lang-corner a { color: var(--c-primary); }

.page { max-width: 1100px; margin: 0 auto; padding: 16px 12px 96px; }

/* Cards */
.cards { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--gap); }
.card {
    background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius);
    padding: 14px; margin-bottom: var(--gap);
}
.cards .card { margin-bottom: 0; }
.card.narrow { max-width: 380px; margin: 10vh auto 0; }
.card-warn { border-color: var(--c-warn); background: var(--c-warn-bg); }
.shop-card-head, .reading-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 4px 8px; }
.shop-card-head h2 { margin: 0; }
.sales { list-style: none; padding: 0; margin: 8px 0; }

/* Badges & flashes */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: var(--small); font-weight: 600; white-space: nowrap; }
:root:lang(km) .badge { white-space: normal; }
.badge-ok { color: var(--c-ok); background: var(--c-ok-bg); }
.badge-warn { color: var(--c-warn); background: var(--c-warn-bg); }
.badge-danger { color: var(--c-danger); background: var(--c-danger-bg); }
.badge-info { color: var(--c-info); background: var(--c-info-bg); }

.flash { padding: 10px 12px; border-radius: var(--radius); margin: 0 0 var(--gap); }
.flash-success { color: var(--c-ok); background: var(--c-ok-bg); }
.flash-warning { color: var(--c-warn); background: var(--c-warn-bg); }
.flash-danger { color: var(--c-danger); background: var(--c-danger-bg); }
.flash-info { color: var(--c-info); background: var(--c-info-bg); }

/* Connection banner: network lost, or a form that could not be sent. */
.net-status {
    position: sticky; bottom: 0; z-index: 15;
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
    margin: 0; padding: 10px 12px;
    color: var(--c-warn); background: var(--c-warn-bg); border-top: 2px solid var(--c-warn);
}
.net-status[hidden] { display: none; }
.net-status p { margin: 0; flex: 1 1 200px; }
.net-status.is-ok { color: var(--c-ok); background: var(--c-ok-bg); border-color: var(--c-ok); }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: var(--tap); min-width: var(--tap); padding: 0 16px;
    border: 1px solid var(--c-border); border-radius: var(--radius);
    background: var(--c-surface); color: var(--c-text);
    font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn-primary { background: var(--c-primary); color: var(--c-primary-text); border-color: var(--c-primary); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .6; cursor: progress; }
.btn-block { width: 100%; margin-top: 10px; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }
.link { background: none; border: 0; padding: 8px 0; color: var(--c-primary); font: inherit; text-decoration: underline; cursor: pointer; min-height: var(--tap); }

/* Actions stay under the thumb */
.actions-bar {
    position: sticky; bottom: 0; z-index: 5;
    display: flex; gap: 8px; padding: 10px 0;
    background: linear-gradient(transparent, var(--c-bg) 30%);
}
.actions-bar .btn { flex: 1; }

/* Day navigation */
.day-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: var(--gap); }
.day-nav h1 { margin: 0; text-align: center; font-size: 1.15rem; }
.page-head { margin-bottom: var(--gap); }
.page-head h1 { margin: 4px 0 0; }
/* "‹ Back" links: big enough for a thumb. */
.page-head > a:first-child { display: inline-flex; align-items: center; min-height: var(--tap); }

/* Forms */
.field, form div:has(> label + input), form div:has(> label + select), form div:has(> label + textarea), form div:has(> label + ul) { margin-bottom: 10px; }
label, .label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 4px; }
:root:lang(km) label, :root:lang(km) .label { font-size: 1rem; }
/* Checkboxes: the whole row (box + text) is the 44px target. */
label.check, form div:has(> input[type="checkbox"]) { display: flex; align-items: center; min-height: var(--tap); font-weight: normal; }
form div:has(> input[type="checkbox"]) label { display: flex; align-items: center; flex: 1; min-height: var(--tap); margin: 0; font-weight: normal; cursor: pointer; }
.static-value { margin: 0; min-height: var(--tap); display: flex; align-items: center; }
input[type="text"], input[type="tel"], input[type="password"], input[type="number"], input[type="date"], select, textarea {
    width: 100%; min-height: var(--tap); padding: 8px 10px;
    border: 1px solid var(--c-border); border-radius: 8px;
    background: var(--c-surface); color: var(--c-text); font: inherit; font-size: 1rem; /* 16px avoids zoom on iOS */
}
input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; vertical-align: middle; margin-right: 6px; flex: none; }
[aria-invalid="true"] { border-color: var(--c-danger) !important; border-width: 2px !important; }
/* Expanded choices (radio buttons): one 44px row per choice, the text is part of the target. */
.radio-group { border: 0; padding: 0; margin: 0 0 10px; min-width: 0; }
.radio-group legend { padding: 0; }
.radio-group > div { display: grid; grid-template-columns: auto 1fr; align-items: center; }
.radio-group > div > label { display: flex; align-items: center; min-height: var(--tap); margin: 0; font-weight: normal; cursor: pointer; }
.form-error-message, ul:has(> li) .form-error-message { color: var(--c-danger); }
form ul:not(.cards):not(.sales) { color: var(--c-danger); font-weight: 600; padding-left: 18px; margin: 4px 0; }
.form-error { color: var(--c-danger); font-weight: 600; margin: 4px 0; }
.help-text, [id$="_help"] { font-size: var(--small); color: var(--c-muted); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid-2 > div { min-width: 0; }

/* Review */
.readings { list-style: none; padding: 0; margin: 0; }
.reading.is-doubtful { border-left: 5px solid var(--c-warn); }
.sheet-photo { margin: 0 0 var(--gap); }
.sheet-photo img { width: 100%; max-height: 60vh; object-fit: contain; border-radius: var(--radius); border: 1px solid var(--c-border); background: #000; }
.sheet-photo figcaption { font-size: var(--small); color: var(--c-muted); text-align: center; }

/* Stock */
.slot-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.slot-link { display: flex; flex-direction: column; text-decoration: none; color: inherit; margin: 0; min-height: 72px; }

/* Report */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: var(--gap); }
.kpi { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); padding: 10px 12px; }
.kpi span { display: block; font-size: var(--small); color: var(--c-muted); }
.kpi strong { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.table-wrap:focus-visible { outline-offset: -3px; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: 6px 8px; border-bottom: 1px solid var(--c-border); text-align: left; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .neg { color: var(--c-danger); font-weight: 700; }

/* Table title with an "i" button: the explanation opens under the whole title row. */
.title-info { position: relative; display: flex; align-items: center; gap: 4px; margin: calc(var(--gap) * 2) 0 var(--gap); }
.title-info h2, .title-info h3 { margin: 0; }
.info summary { list-style: none; cursor: pointer; display: grid; place-items: center; min-width: 44px; min-height: 44px; }
.info summary::-webkit-details-marker { display: none; }
.info summary span {
    display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
    border: 2px solid var(--c-primary); color: var(--c-primary); font: italic 700 .9rem/1 Georgia, serif;
}
.info[open] summary span { background: var(--c-primary); color: var(--c-primary-text); }
.info summary:focus-visible { outline: 3px solid var(--c-focus); outline-offset: -4px; border-radius: 50%; }
.info-text {
    position: absolute; left: 0; right: 0; top: 100%; z-index: 10; max-width: 40rem;
    background: var(--c-surface); color: var(--c-text); border: 1px solid var(--c-border); border-radius: var(--radius);
    box-shadow: 0 6px 20px rgb(0 0 0 / .18); padding: 12px 14px; font-size: .95rem; font-weight: normal;
}
.info-text p { margin: 0 0 8px; }
.info-text dl { margin: 0; display: grid; grid-template-columns: minmax(7rem, max-content) 1fr; gap: 4px 12px; }
.info-text dt { font-weight: 700; }
.info-text dd { margin: 0; }
@media (max-width: 480px) { .info-text dl { grid-template-columns: 1fr; } .info-text dd { margin-bottom: 6px; } }

@media (min-width: 800px) {
    .topbar nav { order: 0; width: auto; }
    .kpis { grid-template-columns: repeat(5, 1fr); }
    .review-layout:has(.sheet-photo) { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 20px; align-items: start; }
    .review-layout .sheet-photo { position: sticky; top: 64px; }
    .review-layout .sheet-photo img { max-height: 85vh; }
}

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

/* Dashboard */
.tabs { display: flex; gap: 4px; margin-bottom: var(--gap); border-bottom: 1px solid var(--c-border); }
.tabs a { display: inline-flex; align-items: center; padding: 10px 14px; min-height: var(--tap); text-decoration: none; color: var(--c-muted); border-bottom: 3px solid transparent; }
.tabs a[aria-current="page"] { color: var(--c-text); font-weight: 600; border-bottom-color: var(--c-primary); }
.period-picker summary { cursor: pointer; min-height: var(--tap); display: flex; align-items: center; font-weight: 600; }
.period-picker form { margin-top: 8px; }
.period-picker .btn-block { grid-column: 1 / -1; }
.kpi strong.neg, .table td.neg { color: var(--c-danger); }
.chart { margin: 0; }
.chart svg { width: 100%; height: 180px; display: block; }
.chart-axis { stroke: var(--c-border); stroke-width: .3; vector-effect: non-scaling-stroke; }
.chart-bar { fill: var(--c-primary); }
.chart-bar.is-historical, .swatch.is-historical { fill: var(--c-primary); opacity: .45; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 2px; background: var(--c-primary); vertical-align: middle; }
.swatch.is-historical { opacity: .45; }
.chart-caption { display: flex; justify-content: space-between; gap: 8px; font-size: var(--small); color: var(--c-muted); font-variant-numeric: tabular-nums; }
.sparkline { width: 90px; height: 24px; display: block; }
.sparkline polyline { fill: none; stroke: var(--c-primary); stroke-width: 1.5; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.table th[scope="row"] { font-weight: 600; white-space: nowrap; }
.table tr.is-low-cover { background: var(--c-warn-bg); }
.category-bars { list-style: none; display: grid; gap: 8px; }
.category-bars li { display: grid; grid-template-columns: minmax(80px, 30%) 1fr auto; align-items: center; gap: 8px; }
.category-bar { height: 12px; border-radius: 6px; background: linear-gradient(to right, var(--c-accent) var(--share), var(--c-border) var(--share)); }
.category-bars strong { font-variant-numeric: tabular-nums; }

/* Guide */
.guide-toc { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--gap); }
.guide-steps { padding-left: 0; margin: 0; list-style-position: inside; display: grid; gap: var(--gap); }
.guide-steps > li::marker { font-weight: 700; color: var(--c-primary); }
.guide-step { margin: 0; }
.guide-step h3 { display: inline; font-size: 1rem; }
.guide-step ol { padding-left: 20px; margin: 8px 0; }
.guide-step p { margin: 8px 0; }
.guide-step-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.guide-time { font-weight: 600; color: var(--c-muted); font-variant-numeric: tabular-nums; }
.guide-step code { padding: 1px 6px; border-radius: 4px; background: var(--c-info-bg); color: var(--c-info); font-weight: 600; }

/* My account */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0; }
.facts dt { font-weight: 600; color: var(--c-muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.account-card { max-width: 480px; }

/* Monthly target */
.targets { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); margin-bottom: var(--gap); }
.target h3 { margin: 0 0 6px; font-size: 1rem; }
.target-bar { display: block; width: 100%; height: 14px; margin: 6px 0; accent-color: var(--c-primary); }
.target-figures { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 12px; margin: 0; font-size: var(--small); font-variant-numeric: tabular-nums; }
.target-figures .neg { color: var(--c-danger); font-weight: 700; }
.target-figures .pos { color: var(--c-ok); font-weight: 700; }
.target-title { margin: 8px 0 0; }
.targets .target-title { margin-top: 0; }
