/* ============================================================
 * RECORD LOG — the clinic's and guidance's shared record screens
 * ============================================================
 * A day-by-day log of visits / sessions / incidents, the "needs action" queue
 * pinned above it, the count chips that filter it, the search-and-dates
 * toolbar, the student band of a history page, and the side panel that opens
 * one record. Clinic (visits, patients) and Guidance (sessions, incidents,
 * student records) work the same way, so they share this one file and cannot
 * drift apart.
 *
 * Tones (rl-tone-ok / -warn / -bad / -info / -indigo / -muted) are the status
 * token pairs, so pills, chip icons and outcome buttons follow dark mode.
 * Selection and hover are the school color (theme-colors.css).
 */

/* ── The log ────────────────────────────────────────────────────
   One row per visit, grouped by day, with pending visits pinned on top and
   the full record in a side panel. Colors are tokens throughout: the outcome
   pills are the status pairs, selection and hover the school color, so dark
   mode follows without its own rules. */

/* Toolbar: search, dates, year, patient type */
.rl-toolbar {
    display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
    background: var(--color-surface); border-radius: var(--radius-lg);
    padding: 10px 12px; box-shadow: var(--shadow-sm); margin-bottom: var(--space-4);
}
.rl-search { position: relative; flex: 1 1 240px; min-width: 200px; }
.rl-search .bi { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--color-text-muted); pointer-events: none; }
.rl-search .form-control { padding-left: 32px; }
/* Wraps on a phone rather than pushing the page wider. */
.rl-ranges {
    flex-wrap: wrap; max-width: 100%;
    display: inline-flex; padding: 2px; gap: 2px;
    background: var(--color-surface-alt); border: 1px solid var(--color-border); border-radius: var(--radius-md);
}
.rl-range {
    padding: 5px 11px; border-radius: calc(var(--radius-md) - 2px);
    font-size: var(--text-base); font-weight: var(--font-semibold); white-space: nowrap;
    color: var(--color-text-secondary); text-decoration: none;
}
button.rl-range { border: 0; background: none; }
.rl-range:hover { color: var(--brand-ink); }
.rl-range.active { background: var(--color-surface); color: var(--brand-ink); box-shadow: var(--shadow-sm); }
/* The text must not run under a dropdown's arrow. */
.rl-select { width: auto; max-width: 100%; padding-right: 2.25rem; }
.rl-dates { display: inline-flex; align-items: center; gap: 6px; }
.rl-dates .form-control { width: auto; }

/* Outcome chips: a count each, and a filter */
.rl-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--space-4); }
.rl-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 14px; border-radius: var(--radius-pill);
    border: 1px solid var(--color-border); background: var(--color-surface);
    color: var(--color-text); font-size: var(--text-base); font-weight: var(--font-semibold);
    text-decoration: none; transition: var(--transition-fast);
}
.rl-chip:hover { border-color: var(--brand-border); color: var(--color-text); }
.rl-chip .bi { color: var(--rl-fg, inherit); }
.rl-chip.active { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.rl-chip.active .bi { color: inherit; }
.rl-chip-num { font-weight: var(--font-bold); opacity: .7; }
.rl-chip.active .rl-chip-num { opacity: .9; }

/* Outcomes: a status color pair each, shared by pill, chip icon and button */
.rl-tone-ok { --rl-bg: var(--color-success-bg); --rl-fg: var(--color-success-text); }
.rl-tone-warn  { --rl-bg: var(--color-warning-bg); --rl-fg: var(--color-warning-text); }
.rl-tone-bad   { --rl-bg: var(--color-danger-bg);  --rl-fg: var(--color-danger-text); }
.rl-tone-muted { --rl-bg: var(--color-surface-alt); --rl-fg: var(--color-text-secondary); }
.rl-tone-indigo { --rl-bg: var(--color-indigo-bg); --rl-fg: var(--color-indigo-text); }
.rl-tone-info   { --rl-bg: var(--color-blue-bg); --rl-fg: var(--color-blue-text); }
.rl-pill {
    display: inline-block; padding: 3px 11px; border-radius: var(--radius-pill);
    font-size: var(--text-xs); font-weight: var(--font-bold); white-space: nowrap;
    background: var(--rl-bg); color: var(--rl-fg);
}
.rl-btn { background: var(--rl-bg); color: var(--rl-fg); border: 1px solid transparent; font-weight: var(--font-semibold); font-size: var(--text-base); }
.rl-btn:hover, .rl-btn:focus-visible { background: var(--rl-bg); color: var(--rl-fg); border-color: currentColor; }

/* Needs a decision */
.rl-queue {
    background: var(--color-surface); border-radius: var(--radius-lg); overflow: hidden;
    border: 1px solid var(--color-border); border-left: 4px solid var(--color-warning);
    box-shadow: var(--shadow-sm); margin-bottom: var(--space-4);
}
.rl-queue-head {
    display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
    padding: 9px 14px; background: var(--color-warning-bg); color: var(--color-warning-text);
    font-weight: var(--font-bold);
}
.rl-queue-hint { margin-left: auto; font-size: var(--text-sm); font-weight: var(--font-normal, 400); opacity: .85; }
.rl-queue-row {
    display: grid; grid-template-columns: 84px minmax(0, 1fr) auto; gap: 12px; align-items: center;
    padding: 10px 14px; border-top: 1px solid var(--color-border); cursor: pointer;
}
.rl-queue-row:hover { background: var(--brand-soft); }
.rl-queue-row:focus-visible { outline: 2px solid var(--brand-border); outline-offset: -2px; }
.rl-queue-when { font-size: var(--text-base); font-weight: var(--font-semibold); color: var(--color-text); }
.rl-queue-when span { display: block; font-weight: var(--font-normal, 400); color: var(--color-text-muted); }
.rl-queue-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
@media (max-width: 1199.98px) {
    .rl-queue-row { grid-template-columns: 72px minmax(0, 1fr); }
    .rl-queue-actions { grid-column: 1 / -1; justify-content: flex-start; }
}

/* The log */
.rl-log { background: var(--color-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); overflow: hidden; }
.rl-log-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 11px 16px; border-bottom: 1px solid var(--color-border); }
.rl-table { --bs-table-bg: transparent; color: var(--color-text); }
.rl-table thead th {
    padding: 8px 12px; white-space: nowrap;
    font-size: var(--text-xs); font-weight: var(--font-bold); text-transform: uppercase; letter-spacing: .04em;
    color: var(--color-text-muted); background: var(--color-surface-alt); border-bottom: 1px solid var(--color-border);
}
.rl-table td { padding: 9px 12px; vertical-align: top; border-color: var(--color-border); background: transparent; color: var(--color-text); font-size: var(--text-base); }
.rl-day td {
    padding: 6px 12px; font-size: var(--text-base); font-weight: var(--font-bold);
    background: var(--color-surface-alt); color: var(--color-text);
}
.rl-day-count { font-weight: var(--font-normal, 400); color: var(--color-text-muted); }
.rl-today {
    display: inline-block; margin-left: 6px; padding: 0 8px; border-radius: var(--radius-pill);
    font-size: var(--text-2xs); text-transform: uppercase; letter-spacing: .04em;
    background: var(--brand-soft); color: var(--brand-ink);
}
.rl-row { cursor: pointer; }
.rl-row:hover td { background: var(--brand-soft); }
.rl-row:focus-visible { outline: 2px solid var(--brand-border); outline-offset: -2px; }
.rl-col-time { width: 100px; white-space: nowrap; color: var(--color-text-secondary); }
.rl-when-date { font-weight: var(--font-semibold); color: var(--color-text); }
.rl-col-complaint { width: 28%; }
.rl-col-treat { width: 22%; }
.rl-col-out { width: 1%; white-space: nowrap; }
.rl-col-go { width: 1%; color: var(--color-text-muted); }
.rl-name { font-size: var(--text-md); font-weight: var(--font-semibold); color: var(--color-text); line-height: 1.3; }
.rl-sub { font-size: var(--text-sm); color: var(--color-text-muted); line-height: 1.4; }
/* Two lines at most; the panel has the rest. */
.rl-complaint, .rl-treat { line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.rl-vitals { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.rl-vital {
    padding: 1px 7px; border-radius: var(--radius-pill); white-space: nowrap;
    font-size: var(--text-xs); color: var(--color-text-secondary);
    background: var(--color-surface-alt); border: 1px solid var(--color-border);
}
.rl-mobile-meta { display: none; }
.rl-pages { padding: 12px; border-top: 1px solid var(--color-border); }
/* Phones: time and patient, with the complaint and outcome under the name. A
   patient's history has no patient column, so there the complaint stays. */
@media (max-width: 767.98px) {
    .rl-table:not(.rl-history) .rl-col-complaint,
    .rl-table:not(.rl-history) .rl-col-out,
    .rl-col-treat { display: none; }
    .rl-mobile-meta { display: block; margin-top: 4px; font-size: var(--text-sm); color: var(--color-text-secondary); }
    .rl-mobile-meta .rl-pill { margin-left: 4px; }
    .rl-col-time { width: 70px; }
    .rl-queue-hint { margin-left: 0; width: 100%; }
    /* Buttons two to a row; pills keep their size. A button inside a form (Mark done) counts as one. */
    .rl-queue-actions > .rl-btn, .rl-queue-actions > form { flex: 1 1 calc(50% - 6px); }
    .rl-queue-actions > form { display: flex; }
    .rl-queue-actions > form .rl-btn { flex: 1; }
}

/* The patient (history view): one band -- the face, the name, the facts */
.rl-patient {
    display: flex; align-items: center; flex-wrap: wrap; gap: 16px 22px;
    padding: 18px 22px; border-radius: var(--radius-lg);
    background: var(--gradient-primary); color: #fff; box-shadow: var(--shadow-sm);
}
.rl-patient-photo {
    width: 80px; height: 80px; flex-shrink: 0; object-fit: cover; object-position: top center;
    border-radius: var(--radius-md); border: 3px solid rgba(255, 255, 255, .4); background: rgba(255, 255, 255, .15);
    display: flex; align-items: center; justify-content: center;
    font-size: 28px; font-weight: var(--font-bold); color: #fff;
}
.rl-patient-name { font-size: var(--text-3xl); font-weight: var(--font-bold); line-height: 1.2; overflow-wrap: anywhere; }
.rl-patient-kind {
    margin-left: 8px; padding: 3px 10px; border-radius: var(--radius-pill); vertical-align: middle;
    font-size: var(--text-xs); font-weight: var(--font-bold); text-transform: uppercase; letter-spacing: .05em;
    background: rgba(255, 255, 255, .22);
}
.rl-patient-facts { display: flex; flex-wrap: wrap; gap: 4px 20px; margin-top: 6px; font-size: var(--text-md); }
.rl-fact-label { margin-right: 4px; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .05em; opacity: .75; }
.rl-patient-stats { display: flex; gap: 10px; }
.rl-patient-stats > div { min-width: 104px; padding: 10px 16px; text-align: center; border-radius: var(--radius-md); background: rgba(255, 255, 255, .16); }
.rl-stat-num { font-size: var(--text-3xl); font-weight: var(--font-bold); line-height: 1.1; }
.rl-stat-label { margin-top: 2px; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .05em; opacity: .85; }

/* The side panel: reading a record, so larger than the list. The name wraps
   (a long one used to push the close button off the panel); the button never
   shrinks. */
.rl-panel { --bs-offcanvas-width: 500px; background: var(--color-surface); color: var(--color-text); }
.rl-panel .offcanvas-header { align-items: flex-start; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--color-border); }
.rl-panel-photo {
    width: 80px; height: 80px; flex-shrink: 0; overflow: hidden;
    border-radius: var(--radius-md); background: var(--gradient-primary); box-shadow: var(--shadow-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 28px; font-weight: var(--font-bold); color: #fff;
}
.rl-panel-photo img { width: 100%; height: 100%; object-fit: cover; object-position: top center; }
.rl-panel-who { flex: 1 1 auto; min-width: 0; }
.rl-panel .offcanvas-title { font-size: var(--text-3xl); font-weight: var(--font-bold); line-height: 1.25; overflow-wrap: anywhere; }
.rl-panel-sub { margin-top: 4px; font-size: var(--text-md); color: var(--color-text-muted); }
.rl-panel .btn-close { flex-shrink: 0; margin: 2px 0 0; }
.rl-panel .offcanvas-body { padding: 18px 20px; }
.rl-panel-meta { display: grid; gap: 4px; margin-bottom: 14px; font-size: var(--text-lg); color: var(--color-text-secondary); }
.rl-panel .rl-pill { font-size: var(--text-md); padding: 4px 14px; }
.rl-field { margin-bottom: 16px; }
.rl-field-label { margin-bottom: 3px; font-size: var(--text-sm); font-weight: var(--font-bold); text-transform: uppercase; letter-spacing: .05em; color: var(--color-text-muted); }
.rl-field-value { font-size: var(--text-xl); line-height: 1.5; color: var(--color-text); }
.rl-panel .rl-sub { font-size: var(--text-md); }
.rl-vital-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.rl-vital-box { padding: 8px 10px; text-align: center; border-radius: var(--radius-md); background: var(--color-surface-alt); }
.rl-vital-label { font-size: var(--text-sm); font-weight: var(--font-bold); text-transform: uppercase; color: var(--color-text-muted); }
.rl-vital-value { font-size: var(--text-2xl); font-weight: var(--font-bold); color: var(--color-text); }
.rl-panel-decide { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px; margin-bottom: 16px; border-radius: var(--radius-md); background: var(--color-warning-bg); }
.rl-panel .rl-btn { padding: 6px 12px; }
/* A note in the panel (a confidential session: the notes stay in the full record). */
.rl-panel-note {
    display: flex; align-items: flex-start; gap: 4px; padding: 12px; margin-bottom: 16px;
    border-radius: var(--radius-md); background: var(--color-surface-alt); color: var(--color-text-secondary);
    font-size: var(--text-lg);
}
.rl-panel-foot { display: flex; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--color-border); }
.rl-panel-foot .btn { font-size: var(--text-lg); padding: 8px 14px; }

/* A record page (guidance session / incident): the band above, then a main
   card and a side card in the same type as the side panel. */
.rl-doc { padding: 20px 22px; }
.rl-note-box {
    padding: 12px 14px; border-radius: var(--radius-md);
    background: var(--color-surface-alt); border-left: 3px solid var(--brand-border);
}
