/* Clinical Coach: plain, mobile-first text layered on clinic-theme.css. Built
   for a phone on the wards (16px inputs so iOS doesn't zoom, 44px taps). */

:root {
    --soft: #F5F5F2;
    --warn: #9A3412;
    --radius: 10px;
}

[data-theme="dark"] {
    --soft: #1C1C1C;
    --warn: #FDBA74;
}

[hidden] { display: none !important; }

.coach-page {
    max-width: 760px;
    margin: 0 auto;
    padding: 1rem 1rem calc(5rem + env(safe-area-inset-bottom));
}

.coach-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.coach-head h1 { margin: 0; font-size: 1.6rem; }
.head-links { display: flex; gap: 0.5rem; }

.btn {
    font: inherit;
    font-size: 0.95rem;
    min-height: 44px;
    padding: 0.55rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.btn-small { min-height: 36px; padding: 0.3rem 0.75rem; font-size: 0.85rem; }

.linkbtn {
    font: inherit;
    font-size: 0.8rem;
    font-weight: 400;
    background: none;
    border: none;
    padding: 0 0.25rem;
    color: var(--link);
    text-decoration: underline;
    cursor: pointer;
}

/* ---- Mode toggle ---- */

.mode-toggle {
    display: inline-flex;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 3px;
    margin-bottom: 0.75rem;
    background: var(--soft);
}

.mode-toggle button {
    font: inherit;
    font-size: 0.9rem;
    min-height: 40px;
    padding: 0.3rem 1.1rem;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.mode-toggle button[aria-pressed="true"] { background: var(--accent); color: var(--bg); }
.mode-toggle button:disabled { cursor: default; }

/* ---- Composer ---- */

.composer {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.75rem;
    margin-bottom: 1.25rem;
}

.composer textarea {
    display: block;
    width: 100%;
    min-height: 5.5rem;
    font: inherit;
    font-size: 16px;
    line-height: 1.45;
    border: none;
    resize: none;
    overflow: hidden;
    background: transparent;
    color: var(--text);
}

.composer textarea:focus { outline: none; }
/* Round send button tucked into the bubble's bottom-right corner. */
.composer { position: relative; }
.composer textarea { padding-right: 3rem; }

.send {
    position: absolute;
    right: 0.6rem;
    bottom: 0.6rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.send:disabled { opacity: 0.35; cursor: default; }
.send.busy { opacity: 1; animation: pulse 1.2s ease-in-out infinite; }

.login-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    align-items: center;
}

.login-row label { width: 100%; font-size: 0.85rem; color: var(--muted); }

.login-row input {
    flex: 1 1 12rem;
    font: inherit;
    font-size: 16px;
    min-height: 44px;
    padding: 0.4rem 0.7rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
}

.login-row .err { width: 100%; color: var(--warn); font-size: 0.85rem; }

/* ---- Case header (parsed indices) ---- */

.case-card { border-bottom: 1px solid var(--line); padding-bottom: 0.75rem; margin-bottom: 1rem; }
.case-card p { margin: 0 0 0.25rem; }
.case-card .raw { font-size: 1.1rem; overflow-wrap: anywhere; }
.meta { font-size: 0.85rem; color: var(--muted); overflow-wrap: anywhere; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.8em; }
.warn, .error-box { color: var(--warn); font-size: 0.9rem; margin: 0.5rem 0; }

/* ---- Progress ---- */

.progress { margin-bottom: 1rem; font-size: 0.9rem; color: var(--muted); }
.progress .now { display: flex; align-items: center; gap: 0.5rem; }

.pulse {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--accent);
    animation: pulse 1.2s ease-in-out infinite;
    flex: 0 0 auto;
}

@keyframes pulse { 0%, 100% { opacity: 0.2; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }

.searches { list-style: none; margin: 0.3rem 0 0; padding: 0; font-size: 0.82rem; }
.searches li { overflow-wrap: anywhere; }
.searches li::before { content: 'Searching: '; }

/* ---- Plan: plain text ---- */

.plain h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 1.4rem 0 0.35rem;
}

.plain h3:first-child { margin-top: 0; }
.plain p { margin: 0 0 0.5rem; }
.plain ul, .plain ol { margin: 0 0 0.5rem; padding-left: 1.2rem; }
.plain li { margin-bottom: 0.2rem; overflow-wrap: anywhere; }
.plain .grp { margin: 0.6rem 0 0.1rem; font-style: italic; }
.lbl { font-weight: 600; }
.why { color: var(--muted); }
.ref { color: var(--muted); font-size: 0.8em; text-decoration: none; }
.sources li { font-size: 0.9rem; }
.disclaimer { font-size: 0.8rem; margin-top: 1.25rem; }
.appendix { margin: 1rem 0 0.5rem; }
.appendix summary { cursor: pointer; font-weight: 600; min-height: 32px; }
.appendix p { margin-top: 0.4rem; }

/* ---- History ---- */

.search-bar { display: flex; gap: 0.5rem; margin-bottom: 0.6rem; }

.search-bar input {
    flex: 1;
    min-width: 0;
    font: inherit;
    font-size: 16px;
    min-height: 44px;
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
}

.filter-panel { margin-bottom: 1rem; font-size: 0.9rem; }
.filter-row { margin-bottom: 0.5rem; }
.filter-row .tag-label { color: var(--muted); margin-right: 0.5rem; }

.chip-btn {
    font: inherit;
    font-size: 0.9rem;
    background: none;
    border: none;
    padding: 0.35rem 0;
    margin-right: 0.9rem;
    min-height: 36px;
    color: var(--muted);
    cursor: pointer;
}

.chip-btn.active { color: var(--text); text-decoration: underline; }
.pills { display: inline; }

.age-range { display: inline-flex; gap: 0.5rem; align-items: center; }

.age-range input, .icd-input {
    width: 5rem;
    font: inherit;
    font-size: 16px;
    min-height: 40px;
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
}

.icd-input { width: 7rem; text-transform: uppercase; }

.tracker { font-size: 0.85rem; color: var(--muted); margin-bottom: 1rem; }
.tracker p { margin: 0 0 0.25rem; }
.tracker summary { cursor: pointer; min-height: 32px; }
.usage-scroll { overflow-x: auto; }
.usage-table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; margin-top: 0.3rem; }
.usage-table th, .usage-table td { padding: 0.25rem 0.5rem; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; font-weight: 400; }
.usage-table th[scope=row], .usage-table th:first-child { text-align: left; }

.result-count { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.25rem; }
.results { list-style: none; margin: 0; padding: 0; }

.result a {
    display: block;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--line);
    text-decoration: none;
    color: var(--text);
}

.result p { margin: 0 0 0.15rem; }
.result .line { overflow-wrap: anywhere; }
.status-err { color: var(--warn); }

@media (min-width: 720px) {
    .coach-page { padding: 2rem 2rem 5rem; }
    .coach-head h1 { font-size: 2rem; }
}

@media print {
    .composer, .login-row, .mode-toggle, .head-links, .theme-toggle, .progress, .linkbtn { display: none !important; }
}
