/* =========================================================================
   Chore & Activity Tracker — styles
   Goals: kid-friendly, high contrast, large touch targets, fully keyboard
   accessible, and respectful of reduced-motion preferences.
   ========================================================================= */

:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-alt: #eef3fa;
    --ink: #16243a;
    --ink-soft: #44526a;
    --brand: #2b4fb0;
    --brand-dark: #274aa6;
    --good: #17603f;
    --good-dark: #124d33;
    --warn: #744a05;
    --bad: #9a2b1a;
    --star: #f2b705;
    --border: #d3deec;
    --control-border: #7e8da9;   /* >=3:1 vs white & tints (WCAG 1.4.11) for inputs/checkboxes/choices/tiles */
    --focus: #1a4fd6;
    --radius: 16px;
    --shadow: 0 2px 10px rgba(22, 36, 58, 0.08);
    --shadow-lg: 0 8px 28px rgba(22, 36, 58, 0.16);
    --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
/* Keep focused controls clear of the toast when the browser scrolls them into view (WCAG 2.4.11). */
html { scroll-padding-bottom: 110px; }

body {
    margin: 0;
    font-family: var(--font);
    color: var(--ink);
    background: var(--bg);
    font-size: 1.125rem; /* 18px at the default size, and follows the user's browser text size */
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ---- Accessibility utilities ---- */
.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;
}

.skip-link {
    position: absolute;
    left: 8px; top: -48px;
    background: var(--brand-dark);
    color: #fff;
    padding: 10px 16px;
    border-radius: 8px;
    z-index: 100;
    transition: top .15s ease;
}
.skip-link:focus { top: 8px; }

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}
/* On the blue header the normal ring is nearly invisible (1.1:1), so use white
   with a dark halo there (white on brand 7.4:1). */
.app-header :focus-visible, .skip-link:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 2px;
    box-shadow: 0 0 0 6px #16243a;
}

/* ---- Header / footer ---- */
.app-header {
    background: var(--brand);
    color: #fff;
    box-shadow: var(--shadow);
}
.app-header__inner {
    max-width: 1000px;
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
}
.app-logo { width: 34px; height: 34px; border-radius: 8px; display: block; flex: none; }
.app-title { font-size: 1.25rem; margin: 0; font-weight: 700; }
.app-header__actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.app-footer {
    margin-top: auto;
    text-align: center;
    color: var(--ink-soft);
    padding: 18px;
}

main {
    flex: 1;
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    padding: 22px 18px 40px;
}
main:focus { outline: none; }
/* Headings/regions focused only programmatically (for screen-reader announcements)
   aren't keyboard tab-stops, so no visible ring for sighted users. */
[tabindex="-1"]:focus { outline: none; }

/* ---- Buttons ---- */
.btn {
    font: inherit;
    font-weight: 600;
    color: #fff;
    background: var(--brand);
    border: none;
    border-radius: 12px;
    padding: 12px 20px;
    min-height: 48px;
    cursor: pointer;
    transition: background .15s ease, transform .05s ease;
}
.btn:hover { background: var(--brand-dark); }
.btn:active { transform: translateY(1px); }
.btn--lg { font-size: 1.15rem; padding: 16px 26px; min-height: 60px; }
.btn--block { display: block; width: 100%; }
.btn--ghost { background: transparent; color: var(--brand-dark); border: 2px solid var(--brand); }
.btn--ghost:hover { background: var(--surface-alt); }
.btn--good { background: var(--good); }
.btn--good:hover { background: var(--good-dark); }
.btn--danger { background: var(--bad); }
.btn--danger:hover { background: #b03f2d; }
.btn--small { min-height: 44px; padding: 8px 14px; font-size: .92rem; border-radius: 9px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.header-btn {
    background: rgba(0,0,0,.18);
    color: #fff;
    border: 1px solid rgba(255,255,255,.6);
    border-radius: 10px;
    padding: 8px 14px;
    min-height: 44px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.header-btn:hover { background: rgba(0,0,0,.32); }

/* ---- Cards / panels ---- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
    margin-bottom: 18px;
}
.card h2 { margin-top: 0; }

.panel-title { font-size: 1.4rem; margin: 0 0 4px; }
.panel-sub { color: var(--ink-soft); margin: 0 0 18px; }

/* ---- Forms ---- */
label { display: block; font-weight: 600; margin-bottom: 6px; }
.field { margin-bottom: 16px; }
input[type=text], input[type=password], input[type=date], input[type=search],
input[type=number], select, textarea {
    font: inherit;
    width: 100%;
    padding: 12px 14px;
    border: 2px solid var(--control-border);
    border-radius: 10px;
    background: #fff;
    color: var(--ink);
}
input:focus, select:focus, textarea:focus {
    border-color: var(--brand);
    outline: 2px solid var(--focus);
    outline-offset: 1px;
}
textarea { min-height: 90px; resize: vertical; }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 160px; }
.help { color: var(--ink-soft); font-size: .9rem; margin-top: 4px; }
/* A button styled as a text link (for in-app actions that aren't navigation). */
.linklike {
    background: none; border: none; padding: 4px 6px;
    color: var(--brand-dark); text-decoration: underline;
    font: inherit; font-weight: 600; cursor: pointer;
}
/* Inline validation error tied to a field via aria-describedby. */
.field-err { color: var(--bad); font-weight: 600; font-size: .92rem; margin: 6px 0 0; }
.field--check { display: flex; align-items: center; gap: 10px; }
.field--check input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--brand, #2b4fb0); flex: none; }
.field--check label { font-weight: 600; }

/* Accessible time picker (Hour : Minutes  AM/PM) built from native selects */
.time-field { display: flex; align-items: center; gap: 8px; }
.time-field select { width: auto; flex: 0 1 auto; min-width: 72px; padding: 12px 8px; }
.time-field__sep { font-weight: 700; color: var(--ink-soft); }

/* ---- Tabs (login + parent nav) ---- */
.tabs { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.tab {
    font: inherit; font-weight: 600;
    background: var(--surface-alt);
    color: var(--ink-soft);
    border: 2px solid transparent;
    border-radius: 10px;
    padding: 10px 18px;
    min-height: 46px;
    cursor: pointer;
}
.tab[aria-current="true"] {
    background: #fff;
    color: var(--brand-dark);
    border-color: var(--brand);
}

/* ---- Login chooser ---- */
.login-grid { display: grid; gap: 18px; grid-template-columns: 1fr; max-width: 520px; margin: 0 auto; }

/* ---- Kid dashboard ---- */
.kid-hello { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }
.kid-avatar {
    width: 64px; height: 64px; border-radius: 50%;
    display: grid; place-items: center; font-size: 2rem; color: #fff;
    box-shadow: var(--shadow);
}
.kid-hello h2 { margin: 0; font-size: 1.6rem; }

.progress-wrap { margin: 16px 0 26px; }
.progress-label { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 6px; }
.progress-bar {
    height: 22px; background: var(--surface-alt);
    border-radius: 999px; overflow: hidden; border: 1px solid var(--border);
}
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--good), #46c089);
    width: 0%;
    transition: width .4s ease;
}

.group-title {
    font-size: 1.15rem; margin: 26px 0 12px;
    display: flex; align-items: center; gap: 8px;
}

.task-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

/* A task tile is a big toggle button */
.task {
    display: flex; align-items: center; gap: 14px;
    text-align: left;
    background: var(--surface);
    border: 2px solid var(--control-border);
    border-radius: 14px;
    padding: 16px;
    min-height: 84px;
    cursor: pointer;
    font: inherit;
    color: var(--ink);
    transition: border-color .15s, background .15s, transform .05s;
}
.task:hover { border-color: var(--brand); }
.task:active { transform: scale(.99); }
.task__emoji { font-size: 2rem; line-height: 1; }
.task__body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.task__title { font-weight: 600; font-size: 1.1rem; }
.task__sub { font-size: .82rem; color: var(--ink-soft); font-weight: 500; }
.task__check {
    margin-left: auto;
    width: 34px; height: 34px;
    border-radius: 50%;
    border: 3px solid var(--control-border);
    display: grid; place-items: center;
    color: transparent; font-weight: 800; font-size: 1.2rem;
    flex-shrink: 0;
}
/* Fully done: main + all follow-ups checked */
.task[data-state="done"] {
    background: #eafaf1;
    border-color: var(--good);
}
.task[data-state="done"] .task__check {
    background: var(--good); border-color: var(--good); color: #fff;
}
.task[data-state="done"] .task__title { text-decoration: line-through; color: var(--ink-soft); }

/* Partly done: main checked, but follow-ups still pending */
.task[data-state="partial"] {
    background: #fff7e9;
    border-color: var(--warn);
}
.task[data-state="partial"] .task__check {
    background: var(--warn); border-color: var(--warn); color: #fff;
}
.task[data-state="partial"] .task__sub { color: var(--warn); font-weight: 600; }

/* generic flex-grow cell + skipped schedule rows */
.grow { flex: 1; min-width: 0; }
/* Skipped rows: shown with a dashed border, grey fill and strikethrough, never
   by fading, so every word and button keeps full contrast. */
.list-item.is-skipped { border-style: dashed; background: #f1f3f6; }
.list-item.is-skipped .name { text-decoration: line-through; }

/* ---- Task wrapper + follow-up checks (sub-steps) ---- */
.task-wrap { display: flex; flex-direction: column; }
.task-wrap .task { width: 100%; }
.subtasks {
    margin: 8px 0 0; padding: 12px 14px;
    border: 2px dashed var(--good); border-radius: 12px;
    background: #f1fbf5; display: grid; gap: 8px;
}
/* An explicit author `display` overrides the UA [hidden] rule, so restore it. */
.subtasks[hidden] { display: none; }
.subtasks__title { margin: 0; font-weight: 700; font-size: .9rem; color: var(--good-dark); }
.subcheck {
    display: flex; align-items: center; gap: 10px;
    background: #fff; border: 2px solid var(--control-border); border-radius: 10px;
    padding: 10px 12px; min-height: 46px; font: inherit; color: var(--ink);
    cursor: pointer; text-align: left;
}
.subcheck:hover { border-color: var(--good); }
.subcheck__box {
    width: 26px; height: 26px; border-radius: 7px; border: 2px solid var(--control-border);
    display: grid; place-items: center; color: transparent; font-weight: 800; flex-shrink: 0;
}
.subcheck[aria-pressed="true"] { background: #eafaf1; border-color: var(--good); }
.subcheck[aria-pressed="true"] .subcheck__box { background: var(--good); border-color: var(--good); color: #fff; }
.subcheck[aria-pressed="true"] span:last-child { text-decoration: line-through; color: var(--ink-soft); }

/* ---- "My Day" follow-up sub-items (nested list inside their task) ---- */
.summary-sublist { flex-basis: 100%; list-style: none; margin: 4px 0 0 22px; padding: 0; display: grid; gap: 8px; }
.summary-subitem {
    display: flex; align-items: center; gap: 12px;
    padding: 8px 14px; border-radius: 10px;
    border: 1px dashed var(--border); background: var(--surface);
    font-size: .95rem;
}
.summary-subitem.done { background: #f1fbf5; border-color: var(--good); }
.summary-subitem .badge { margin-left: auto; font-weight: 700; font-size: .8rem; }
.summary-subitem.done .badge { color: var(--good-dark); }
.summary-subitem.todo .badge { color: var(--ink-soft); }

/* ---- Follow-up checks editor (parent task modal) ---- */
.sub-edit-list { display: grid; gap: 8px; margin-bottom: 8px; }
.sub-edit-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.sub-edit-row input { flex: 1 1 12rem; min-width: 0; }
.btn[aria-disabled="true"] { opacity: 1; color: var(--ink-soft); border-style: dashed; cursor: default; }

.empty {
    text-align: center; color: var(--ink-soft);
    padding: 30px; border: 2px dashed var(--border); border-radius: 14px;
}

/* ---- "My Day" summary ---- */
.summary-hero { text-align: center; padding: 10px 0 4px; }
.ring-wrap { display: grid; place-items: center; margin: 10px 0; }
.ring { transform: rotate(-90deg); }
.ring__bg { fill: none; stroke: var(--surface-alt); }
.ring__fg { fill: none; stroke: var(--good); stroke-linecap: round; transition: stroke-dashoffset .6s ease; }
.ring__text {
    transform: rotate(90deg);
    transform-origin: center;
    fill: var(--ink); font-weight: 800; font-size: 26px; text-anchor: middle;
}
.cheer { font-size: 1.3rem; font-weight: 700; margin: 6px 0; }
.stars { font-size: 1.6rem; letter-spacing: 4px; }

.summary-list { list-style: none; padding: 0; margin: 18px 0 0; display: grid; gap: 10px; }
.summary-item {
    display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
    padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border);
    background: var(--surface);
}
.summary-item.done { background: #eafaf1; border-color: var(--good); }
.summary-item.partial { background: #fff7e9; border-color: var(--warn); }
.summary-item .badge { margin-left: auto; font-weight: 700; font-size: .85rem; }
.summary-item.done .badge { color: var(--good-dark); }
.summary-item.partial .badge { color: var(--warn); }
.summary-item.todo .badge { color: var(--ink-soft); }

/* ---- Stat chips ---- */
.stat-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); margin: 6px 0 18px; }
.stat {
    background: var(--surface-alt); border-radius: 12px; padding: 14px;
    text-align: center; border: 1px solid var(--border);
}
.stat__num { font-size: 1.8rem; font-weight: 800; color: var(--brand-dark); }
.stat__label { color: var(--ink-soft); font-size: .9rem; }

/* ---- Lists (children, tasks in parent view) ---- */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.list-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px; border: 1px solid var(--border);
    border-radius: 12px; background: var(--surface);
}
.list-item .pill-emoji {
    width: 42px; height: 42px; border-radius: 50%;
    display: grid; place-items: center; color: #fff; font-size: 1.2rem; flex-shrink: 0;
}
.list-item .grow { flex: 1; min-width: 0; }
.list-item .name { font-weight: 700; }
.list-item .meta { color: var(--ink-soft); font-size: .9rem; }
.list-item .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.tag {
    display: inline-block; font-size: .75rem; font-weight: 700;
    padding: 2px 9px; border-radius: 999px; vertical-align: middle;
}
.tag--chore { background: #e3edff; color: var(--brand-dark); }
.tag--activity { background: #fff2cf; color: #8a6400; }
.tag--inactive { background: #f0e0dd; color: var(--bad); }

/* ---- Mood / rating selectors ---- */
.choice-row { display: flex; gap: 8px; flex-wrap: wrap; }
.choice {
    font: inherit; cursor: pointer;
    border: 2px solid var(--control-border); background: #fff;
    border-radius: 10px; padding: 10px 14px; min-height: 46px;
}
.choice[aria-pressed="true"], .choice[aria-checked="true"] { border-color: var(--brand); background: #eef3fa; font-weight: 700;
    box-shadow: inset 0 0 0 2px var(--brand); position: relative; }
/* A check mark on selected choices, so selection isn't shown by colour alone. */
.choice[aria-pressed="true"]::after, .choice[aria-checked="true"]::after {
    content: "✓"; position: absolute; top: -9px; right: -9px;
    width: 22px; height: 22px; border-radius: 50%;
    background: var(--brand); color: #fff; font-size: 14px; line-height: 22px; text-align: center;
    border: 2px solid #fff; font-weight: 800;
}
.label { display: block; font-weight: 600; margin-bottom: 6px; }
.fieldset { border: 0; padding: 0; margin: 0 0 16px; min-width: 0; }
.fieldset > legend { font-weight: 600; padding: 0; margin-bottom: 6px; }

/* ---- Toast ---- */
.toast {
    position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
    background: var(--ink); color: #fff;
    padding: 14px 22px; border-radius: 12px;
    box-shadow: var(--shadow-lg); z-index: 90; max-width: 90vw;
    pointer-events: none; /* never blocks a tap on what's underneath */
}
.toast--error { background: var(--bad); }
.toast--success { background: var(--good-dark); }

/* ---- Modal ---- */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(15,25,40,.55);
    display: grid; place-items: center; padding: 18px; z-index: 80;
}
.modal {
    background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-lg);
    width: 100%; max-width: 480px; padding: 24px; max-height: 90vh; overflow: auto;
}
.modal h2 { margin-top: 0; }
.modal__actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }

/* ---- BHIS report output ---- */
.report-sheet {
    background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
    padding: 26px; box-shadow: var(--shadow);
}
.report-sheet h2 { margin-top: 0; }
.report-sheet table { width: 100%; border-collapse: collapse; margin: 10px 0 20px; }
.report-sheet th, .report-sheet td {
    border: 1px solid var(--border); padding: 8px 10px; text-align: left; font-size: .95rem;
}
.report-sheet th { background: var(--surface-alt); }
.report-day { border-left: 4px solid var(--brand); padding: 6px 14px; margin: 12px 0; background: var(--surface-alt); border-radius: 0 10px 10px 0; }
.report-day h4 { margin: 0 0 4px; }
.muted { color: var(--ink-soft); }
.bar-mini {
    display: inline-block; height: 10px; border-radius: 5px;
    background: var(--good); vertical-align: middle;
}

hr.sep { border: none; border-top: 1px solid var(--border); margin: 22px 0; }

/* ---- Responsive ---- */
@media (max-width: 540px) {
    body { font-size: 17px; }
    .app-title { font-size: 1.05rem; }
    main { padding: 16px 12px 32px; }
    .card { padding: 16px; }
}

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

/* ---- Print (for BHIS report / kid day) ---- */
@media print {
    .app-header, .app-footer, .skip-link, .no-print, .toast { display: none !important; }
    body { background: #fff; }
    main { max-width: none; padding: 0; }
    .report-sheet, .card { box-shadow: none; border: none; }
    .report-day { background: #fff; }
}

/* ---- Idle-lock warning (parent area) ---- */
.idle-warning {
    position: fixed; left: 50%; top: 16px; transform: translateX(-50%);
    z-index: 200; width: min(92vw, 420px);
    background: #fff; color: var(--ink); border: 3px solid var(--brand);
    border-radius: 14px; padding: 18px 20px; box-shadow: var(--shadow-lg);
}
.idle-warning h2 { margin: 0 0 6px; font-size: 1.2rem; }
.idle-warning p { margin: 0 0 12px; }
