/* «مساعد المذاكرة», the page /helper (Features/Helper/HelperPage.razor) and the chat that <tbm-helper> builds
   (js/helper.js). Loaded on /helper only (PageStyles). From the approved mockup (docs/superpowers/specs/
   2026-11-26-helper-web-mockup/mockup.css): its .hp- rules, except the two entry cards (home.css .home-helper,
   lessons.css .lp-helper) and the mockup-only .hp-demo- block. Tokens only: every colour comes from base.css, so both
   themes work. */

/* ---------- Visitor intro on /helper ---------- */
.hp-intro { max-width: 30rem; margin: 0 auto; display: grid; justify-items: center; gap: 12px; text-align: center; }
.hp-intro h1 { margin: 0; }
.hp-intro-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; text-align: start; }
.hp-intro-list li { display: flex; align-items: flex-start; gap: 10px; }
.hp-intro-list .icon { flex: none; margin-top: 3px; color: var(--link); }
.hp-intro .actions { justify-content: center; margin-top: 4px; }
.hp-intro-note { margin: 0; font-size: var(--fs-xs); color: var(--text-muted); }

/* ---------- The chat page: the frame ---------- */
/* The page fills the screen under the header: the messages scroll, the composer stays at the bottom of the chat
   column. No footer on this page (it is a tool, like the quiz round). The header and the phone tab bar stay.
   <tbm-helper> is rendered for a student only, so the visitor intro keeps the normal page. */
body:has(tbm-helper) { height: 100vh; height: 100dvh; overflow: hidden; }
body:has(tbm-helper) .site-footer { display: none; }
body:has(tbm-helper) .main {
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-width: 1320px;
    padding-top: 0;
    padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
.hp { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.hp-chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

/* On a phone the tab bar goes while the student types: the keyboard and the composer need the room. */
@media (max-width: 56.1875em) {
    body:has(.hp-input:focus) .tabbar { display: none; }
    body:has(.hp-input:focus) .main { padding-bottom: 0; }
}

/* ---------- The conversations: a drawer on a phone, a column on a wide screen ---------- */
.hp-side {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: min(20rem, 86vw);
    padding: 16px;
    background: var(--surface);
    border-inline-end: 2px solid var(--border);
    box-shadow: var(--shadow-float);
    transform: translateX(100%);
    visibility: hidden;
    transition: transform .25s var(--ease-out), visibility .25s;
}
/* Visible at once on open, so the focus can go in (a hidden link takes none); on close it stays visible while it slides out. */
.hp-side.is-open { transform: none; visibility: visible; transition: transform .25s var(--ease-out), visibility 0s; }
.hp-scrim { position: fixed; inset: 0; z-index: 55; background: var(--scrim); }
.hp-side-top { display: flex; align-items: center; gap: 8px; }
.hp-side-top .hp-new { flex: 1; }
.hp-side-title { margin: 6px 4px 0; font-size: var(--fs-md); }
.hp-side-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; margin-inline: -6px; padding: 4px 6px 8px; }
.hp-list { display: grid; gap: 2px; margin: 0 0 10px; padding: 0; list-style: none; }
.hp-item {
    display: grid;
    gap: 2px;
    min-height: 44px;
    padding: 8px 12px;
    border-inline-start: 4px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text);
    text-decoration: none;
}
.hp-item:hover { background: var(--surface-2); }
.hp-item:focus-visible { border-radius: var(--radius-sm); }
.hp-item[aria-current="page"] { border-inline-start-color: var(--primary); background: var(--primary-soft); }
.hp-item-title {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    font-weight: 500;
    line-height: 1.5;
    overflow-wrap: anywhere;
}
.hp-item-title.is-empty { color: var(--text-muted); font-weight: 400; }
.hp-item-date { font-size: var(--fs-xs); color: var(--text-muted); }
.hp-side-note { margin: 4px; font-size: var(--fs-sm); color: var(--text-muted); }
.hp-side-note.is-error { color: var(--danger); }

/* ---------- The chat head ---------- */
.hp-head { display: flex; align-items: center; gap: 4px; min-height: 56px; border-bottom: 2px solid var(--border); }
.hp-title { flex: 1; min-width: 0; margin: 0; padding-inline: 4px; overflow: hidden; font-size: var(--fs-md); white-space: nowrap; text-overflow: ellipsis; }
.hp-head .btn-icon { min-width: 44px; min-height: 44px; padding: 0 10px; }

/* A line under the head: a lost stream, an error with its ✕. */
.hp-notice {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 2px;
    padding-inline-start: 12px;
    border-bottom: 2px solid var(--border);
    background: var(--surface);
    font-size: var(--fs-sm);
}
.hp-notice > .icon { flex: none; color: var(--text-soft); }
.hp-notice-text { flex: 1; min-width: 0; margin: 0; padding-block: 8px; }
.hp-notice.is-error { background: var(--danger-soft); color: var(--danger); }
.hp-notice.is-error > .icon { color: var(--danger); }
.hp-notice .btn { flex: none; }

/* ---------- The messages ---------- */
.hp-log {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 16px 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}
.hp-avatar { flex: none; display: block; }

/* The question: navy like the app, at the end side (the left in RTL). */
.hp-q {
    align-self: flex-end;
    max-width: min(82%, 34rem);
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    border-end-end-radius: 6px;
    background: var(--navy);
    color: var(--on-console);
}
.hp-q:has(.hp-q-photos) { width: min(82%, 22rem); }
.hp-q-text { margin: 0; white-space: pre-line; overflow-wrap: anywhere; }
.hp-q-photos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.hp-q-photos:has(> :only-child) { grid-template-columns: minmax(0, 1fr); }
.hp-q-photos + .hp-q-text { margin-top: 8px; }
.hp-q-photo { display: block; padding: 0; overflow: hidden; aspect-ratio: 4 / 3; border: 0; border-radius: var(--radius-sm); background: none; cursor: zoom-in; }
.hp-q-photo:focus-visible { border-radius: var(--radius-sm); }
/* A photo that did not load: its text in its place, and a tap loads it again. */
.hp-q-photo.is-failed { display: grid; place-items: center; padding: 8px; background: var(--surface-2); color: var(--text); font-size: var(--fs-xs); cursor: pointer; }
.hp-q-photo.is-failed .hp-ph { display: none; }
.hp-q-status { align-self: flex-end; margin: -10px 0 0; font-size: var(--fs-xs); color: var(--text-muted); }
.hp-q-fail { align-self: flex-end; display: grid; justify-items: end; gap: 4px; max-width: min(82%, 34rem); margin-top: -8px; }
.hp-q-error { margin: 0; color: var(--danger); font-size: var(--fs-sm); font-weight: 500; text-align: end; }
.hp-q-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

/* The reply: a card beside the 36 px robot. */
.hp-a { display: flex; align-items: flex-start; gap: 8px; }
.hp-a-card {
    flex: 1;
    min-width: 0;
    padding: 12px 14px 6px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    border-start-start-radius: 6px;
    background: var(--surface);
    box-shadow: 0 3px 0 var(--edge);
}
.hp-a-card:not(:has(.hp-fb)) { padding-bottom: 12px; }
.hp-a-text { margin: 0; line-height: 1.8; white-space: pre-line; overflow-wrap: anywhere; }
.hp-eq { unicode-bidi: isolate; direction: ltr; }
/* The end of a reply that the helper still writes: a blinking turquoise caret. With reduced motion it stays on. */
.hp-caret {
    display: inline-block;
    width: 8px;
    height: 1.05em;
    margin-inline-start: 4px;
    border-radius: 2px;
    background: var(--turquoise);
    vertical-align: -.18em;
    animation: hp-blink .6s ease-in-out infinite alternate both;
}
@keyframes hp-blink { to { opacity: .15; } }
.hp-links { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin-top: 12px; }
.hp-links .btn { max-width: 100%; white-space: normal; text-align: start; }
.hp-links .btn .icon { color: var(--link); }
.hp-a-stopped { margin: 6px 0 0; font-size: var(--fs-sm); color: var(--text-muted); }
.hp-a-error { margin: 8px 0 0; color: var(--danger); font-size: var(--fs-sm); font-weight: 500; }
.hp-a-card > .btn { margin-top: 10px; }

/* Like, dislike, report: icon buttons of 44 px. A pressed one is filled. */
.hp-fb { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; margin: 6px -8px 0; }
.hp-icon-btn, .hp-report {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border: 0;
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    cursor: pointer;
}
.hp-report { padding-inline: 10px; font-size: var(--fs-sm); }
.hp-icon-btn:hover, .hp-report:hover { background: var(--surface-3); color: var(--text); }
.hp-icon-btn:focus-visible, .hp-report:focus-visible { border-radius: var(--radius-pill); }
.hp-icon-btn[aria-pressed="true"], .hp-report.is-done { color: var(--link); }
:is(.hp-icon-btn[aria-pressed="true"], .hp-report.is-done) .hp-fill { fill: currentColor; }
.hp-report.is-done { cursor: default; }
.hp-report.is-done:hover { background: transparent; color: var(--link); }
.hp-icon-btn[disabled] { opacity: .45; cursor: not-allowed; }
.hp-icon-btn[disabled]:hover { background: transparent; color: var(--text-muted); }

/* The choices of a clarifying question, in line with the card. «حاجة تانية» is outlined. */
.hp-choices { display: flex; flex-wrap: wrap; gap: 8px; margin-top: -6px; padding-inline-start: 44px; }
.hp-choices .btn { white-space: normal; }

/* ---------- The reply slot while it waits ---------- */
/* The robot's screen, as the app: dark in both themes, glowing turquoise text. */
.hp-wait {
    flex: 1;
    min-width: 0;
    padding: 14px 16px;
    border: 2px solid color-mix(in srgb, var(--turquoise) 35%, transparent);
    border-radius: var(--radius);
    border-start-start-radius: 6px;
    background: var(--console);
    color: var(--turquoise);
    text-shadow: 0 0 12px color-mix(in srgb, var(--turquoise) 60%, transparent);
}
.hp-wait-row { display: flex; align-items: center; gap: 12px; }
.hp-wait-num { font-family: var(--font-title); font-size: 2.75rem; line-height: 1; }
.hp-wait-text { margin: 0; font-size: var(--fs-md); }
.hp-wait .hp-stop { margin-top: 12px; text-shadow: none; }
.hp-stop.btn {
    --btn-bg: transparent;
    --btn-fg: var(--on-console);
    --btn-border: var(--on-console-soft);
    --btn-edge: transparent;
}
.hp-stop.btn:hover { background: color-mix(in srgb, var(--on-console) 10%, transparent); }

/* The wait of a free student after the fast questions: the title and the text of the server, a big countdown. */
.hp-cool {
    flex: 1;
    min-width: 0;
    padding: 16px 16px 10px;
    border: 2px solid color-mix(in srgb, var(--primary) 45%, transparent);
    border-radius: var(--radius);
    border-start-start-radius: 6px;
    background: var(--primary-soft);
}
.hp-cool-title { margin: 0 0 6px; font-weight: 700; line-height: 1.5; }
.hp-cool-count { margin: 0; font-family: var(--font-title); font-size: var(--fs-lg); line-height: 1.4; }
.hp-cool-count .num { font-size: 2.2rem; color: var(--link); }
.hp-cool-text { margin: 6px 0 0; color: var(--text-muted); line-height: 1.5; }
.hp-cool-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }

/* ---------- Under the messages ---------- */
.hp-ai { margin: 0; padding: 4px 8px 6px; font-size: var(--fs-xs); line-height: 1.5; text-align: center; color: var(--text-muted); }
.hp-fast { margin: 0; padding: 0 8px 6px; font-size: var(--fs-xs); color: var(--text-muted); }
.hp-banner {
    display: grid;
    gap: 8px;
    margin-bottom: 8px;
    padding: 10px 14px;
    border: 2px solid var(--accent-edge);
    border-radius: var(--radius);
    background: var(--accent-soft);
    color: var(--text);
}
.hp-banner p { margin: 0; font-weight: 500; }
.hp-banner-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.hp-closed { display: grid; justify-items: center; gap: 10px; margin: 0; padding: 14px 8px 12px; border-top: 2px solid var(--border); text-align: center; }
.hp-closed p { margin: 0; color: var(--text-muted); }

/* ---------- The composer ---------- */
.hp-composer { padding-bottom: 8px; }
.hp-box {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    padding: 4px;
    border: 2px solid var(--border-strong);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: 0 3px 0 var(--edge);
}
.hp-box:focus-within { border-color: var(--primary); box-shadow: var(--focus-ring); }
.hp-input {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    max-height: calc(1.6em * 5 + 20px);
    padding: 10px 6px;
    border: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    line-height: 1.6;
    resize: none;
    field-sizing: content;
}
.hp-input::placeholder { color: var(--text-soft); }
.hp-input:focus, .hp-input:focus-visible { outline: none; box-shadow: none; }
.hp-count { align-self: center; flex: none; font-size: var(--fs-xs); color: var(--accent-text); font-weight: 500; }
.hp-send {
    flex: none;
    display: inline-grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 2px solid var(--primary-edge);
    border-radius: 50%;
    background: var(--primary);
    color: var(--on-primary);
    box-shadow: 0 3px 0 var(--primary-edge);
    cursor: pointer;
}
.hp-send:focus-visible { border-radius: 50%; box-shadow: 0 3px 0 var(--primary-edge), var(--focus-ring); }
.hp-send[disabled] { border-color: var(--border); background: var(--surface-3); color: var(--text-soft); box-shadow: none; cursor: not-allowed; }
.hp-send.is-stop { border-color: var(--text); background: var(--text); color: var(--surface); box-shadow: 0 3px 0 var(--edge); }
.hp-keys { display: none; margin: 4px 10px 0; font-size: var(--fs-xs); color: var(--text-muted); }
.hp-keys kbd { padding: 0 5px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface-2); font-family: var(--font-code); font-size: .9em; }
@media (min-width: 56.25em) and (hover: hover) and (pointer: fine) { .hp-keys { display: block; } }

/* The photos picked for the next question, each with its ✕ (a 44 px target over the corner). */
.hp-photos { display: flex; gap: 8px; margin: 0 0 8px; padding: 0; list-style: none; }
.hp-thumb { position: relative; flex: none; width: 72px; height: 72px; overflow: hidden; border: 2px solid var(--border); border-radius: var(--radius-sm); }
.hp-thumb-x { position: absolute; inset-block-start: 0; inset-inline-end: 0; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; background: transparent; cursor: pointer; }
.hp-thumb-x span { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--console); color: var(--on-console); box-shadow: 0 0 0 2px var(--surface); }
.hp-thumb-x:focus-visible { border-radius: 50%; }
.hp-photo-note { margin: -2px 4px 8px; font-size: var(--fs-xs); color: var(--text-muted); }

/* A photo of a question: a preview, a sent photo, the viewer. */
.hp-ph { display: block; width: 100%; height: 100%; object-fit: cover; }

/* ---------- The empty chat ---------- */
.hp-empty { display: grid; justify-items: center; gap: 6px; margin: auto 0; padding: 8px 0; text-align: center; }
.hp-empty-title { margin: 8px 0 0; font-size: var(--fs-lg); }
.hp-empty p { margin: 0; color: var(--text-muted); }
.hp-suggest { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 10px 0 0; padding: 0; list-style: none; }
.hp-chip-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 44px;
    padding: 6px 16px;
    border: 2px solid var(--border-strong);
    border-radius: var(--radius-pill);
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 3px 0 var(--edge);
    font: 500 var(--fs-sm)/1.4 var(--font-text);
    cursor: pointer;
    transition: transform .12s var(--ease-out);
}
.hp-chip-btn:hover { border-color: var(--primary); transform: translateY(-2px); }
.hp-chip-btn:active { transform: translateY(2px); box-shadow: none; }
.hp-chip-btn:focus-visible { border-radius: var(--radius-pill); }
.hp-chip-btn .icon { color: var(--link); }
.hp-lesson {
    align-self: center;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    margin: 0;
    padding: 4px 14px;
    border: 2px solid color-mix(in srgb, var(--primary) 45%, transparent);
    border-radius: var(--radius-pill);
    background: var(--primary-soft);
    color: var(--link);
    font-size: var(--fs-sm);
    font-weight: 500;
}

/* A conversation that did not open (no network): in the place of the messages. */
.hp-open-failed { display: grid; justify-items: center; gap: 12px; margin: auto 0; text-align: center; }
.hp-open-failed .icon { color: var(--danger); }
.hp-open-failed p { margin: 0; }
/* A conversation that loads. */
.hp-loading { margin: auto 0; text-align: center; color: var(--text-muted); }

/* ---------- Dialogs: the full size photo, the dislike sheet, the report ---------- */
.hp-dialog {
    width: min(28rem, calc(100% - 32px));
    max-height: calc(100dvh - 32px);
    padding: 20px;
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-float);
}
.hp-dialog::backdrop { background: var(--scrim); }
.hp-dialog-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.hp-dialog-head h2 { flex: 1; margin: 0; font-size: var(--fs-lg); }
.hp-dialog .field { margin-bottom: 12px; }
.hp-dialog textarea { min-height: 88px; resize: vertical; }
.hp-dialog-actions { display: grid; gap: 8px; }
.hp-dialog-actions .btn { width: 100%; }
.hp-dialog .link-button { justify-self: center; min-height: 44px; padding: 0 8px; text-align: center; }
.hp-reasons { display: grid; gap: 2px; margin: 0 0 12px; padding: 0; border: 0; }
.hp-reason { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 8px; border-radius: var(--radius-sm); cursor: pointer; }
.hp-reason:hover { background: var(--surface-2); }
.hp-reason input { width: 22px; height: 22px; margin: 0; accent-color: var(--primary); }
.hp-thanks { display: grid; justify-items: center; gap: 12px; padding: 8px 0 0; text-align: center; }
.hp-thanks .icon { color: var(--success); }
.hp-thanks p { margin: 0; }
.hp-thanks .btn { justify-self: stretch; }
/* On a phone the dislike is a bottom sheet, as in the app. */
@media (max-width: 37.4375em) {
    .hp-sheet { width: 100%; max-width: 100%; margin: auto 0 0; padding-bottom: calc(20px + env(safe-area-inset-bottom)); border-width: 2px 0 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
}

/* The photo at full size: the whole screen, dark in both themes. Esc or the ✕ closes it. */
.hp-viewer {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    background: color-mix(in srgb, var(--console-edge) 92%, transparent);
    color: var(--on-console);
}
.hp-viewer[open] { display: grid; grid-template-rows: auto minmax(0, 1fr); }
.hp-viewer-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; }
.hp-viewer-bar p { flex: 1; margin: 0; font-family: var(--font-title); }
.hp-viewer-img { display: grid; place-items: center; min-height: 0; padding: 0 16px 16px; }
.hp-viewer-img .hp-ph { width: auto; height: auto; max-width: 100%; max-height: calc(100dvh - 96px); object-fit: contain; border-radius: var(--radius-sm); }

/* ---------- Wide screens: the list is a column on the right, the chat a readable column beside it ---------- */
@media (min-width: 56.25em) {
    body:has(tbm-helper) .main { padding-top: 16px; padding-bottom: 16px; }
    .hp { grid-template-columns: 17rem minmax(0, 46rem); justify-content: center; gap: 24px; }
    .hp-side {
        position: static;
        z-index: auto;
        width: auto;
        min-height: 0;
        border: 2px solid var(--border);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-1);
        transform: none;
        visibility: visible;
        transition: none;
    }
    .hp-scrim, .hp-side-close, .hp-menu, .hp-head .hp-new-icon { display: none; }
    .hp-head { padding-inline: 4px; }
}
/* From 900 to 1199 px the header has the HUD and the phone tab bar stays (layout.css). */
@media (min-width: 56.25em) and (max-width: 74.9375em) {
    body:has(.site-header .hud):has(tbm-helper) .main { padding-bottom: calc(var(--tabbar-h) + 16px); }
}
