/* Class report tool page. Everything is scoped to .cr / .teacher-hero. */

.teacher-hero {
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    border: 1px solid #e2e8f0;
    border-inline-start: 6px solid #334155;
    color: #0f172a;
    border-radius: 16px;
    padding: 2rem 1.75rem;
    margin-bottom: 2rem;
}
.teacher-hero h1 { font-weight: 700; margin-bottom: .5rem; font-size: 1.75rem; color: inherit; }
.teacher-hero .mt-3, .teacher-hero .mt-3 > * { color: #334155; }

.visit-counter-box {
    background: linear-gradient(135deg, #e8f1ff, #dbeafe) !important;
    border-inline-start: 6px solid #0d6efd !important;
    border-radius: 10px !important;
    box-shadow: 0 2px 8px rgba(13,110,253,.08);
    text-align: center !important;
}

/* ── Upload form ─────────────────────────────────────────── */
.cr { --cr-accent: #0d6efd; --cr-ink: #0f172a; --cr-muted: #64748b; --cr-line: #e2e8f0; margin-bottom: 3rem; }
.cr-card {
    display: grid; gap: 1rem 1.25rem;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    align-items: end;
    background: #fff; border: 1px solid var(--cr-line); border-radius: 14px; padding: 1.25rem;
}
.cr-field { display: flex; flex-direction: column; gap: .35rem; }
.cr-field-file { grid-column: 1 / -1; }
.cr-field label { font-weight: 600; color: #334155; font-size: .92rem; }
.cr-field input, .cr-field select {
    box-sizing: border-box; width: 100%; min-height: 44px;
    border: 1.5px solid #cbd5e1; border-radius: 10px; padding: .55rem .75rem;
    font: inherit; background: #fff;
}
.cr-field input[type=number], .cr-field select { height: 44px; }
.cr-field input:focus-visible, .cr-field select:focus-visible,
.cr-btn:focus-visible, #cr-report:focus-visible { outline: 3px solid #93c5fd; outline-offset: 2px; }
.cr-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.cr-note { grid-column: 1 / -1; margin: 0; color: var(--cr-muted); font-size: .85rem; }

.cr-btn {
    border: 1.5px solid #cbd5e1; background: #fff; color: #334155; border-radius: 999px;
    padding: .55rem 1.3rem; font: inherit; font-weight: 600; cursor: pointer; min-height: 44px;
    transition: background .15s, border-color .15s, color .15s;
}
.cr-btn:hover { border-color: var(--cr-accent); color: var(--cr-accent); }
.cr-btn-primary { background: var(--cr-accent); border-color: var(--cr-accent); color: #fff; }
.cr-btn-primary:hover { background: #0b5ed7; border-color: #0b5ed7; color: #fff; }
.cr-btn[disabled] { opacity: .6; cursor: progress; }

/* ── Status / errors ─────────────────────────────────────── */
.cr-status { margin: 1rem 0; min-height: 1.5rem; font-weight: 600; color: #334155; }
.cr-status.is-error {
    background: #fde7e7; color: #a21d1d; border-radius: 10px; padding: .75rem 1rem;
    border-inline-start: 5px solid #dc2626;
}

/* Do NOT force direction on the detail line; the JS sets dir="auto" so
   Arabic messages stay RTL and English technical messages stay LTR. */
.cr-status.is-error small {
    display: block; font-weight: 400; margin-top: .25rem;
}

.cr-debug { margin-top: .6rem; font-weight: 400; }
.cr-debug summary { cursor: pointer; font-weight: 600; }
.cr-debug pre {
    margin: .5rem 0 0; padding: .75rem; max-height: 22rem; overflow: auto;
    font-size: .78rem; line-height: 1.45;
    background: #1e293b; color: #e2e8f0; border-radius: 8px;
    white-space: pre-wrap; word-break: break-word;
    direction: ltr; text-align: left;      /* technical output only */
}

/* ── Charts ─────────────────────────────────────────────── */
.cr-figure { margin: 1rem 0; text-align: center; }
.cr-figure img { max-width: 100%; height: auto; }

/* Shown when the API omits a chart; keeps the layout and tells the
   user the chart was expected but not delivered. */
.cr-figure-missing {
    border: 1px dashed var(--cr-line);
    border-radius: 10px;
    padding: 1rem;
    color: var(--cr-muted);
}
.cr-figure-missing figcaption { font-weight: 600; }
.cr-figure-missing::after {
    content: '—';
    display: block;
    font-size: 1.5rem;
    margin-top: .5rem;
}
.cr-status.is-error small { display: block; font-weight: 400; direction: ltr; text-align: left; margin-top: .25rem; }

/* ── Report ──────────────────────────────────────────────── */
.cr-report { background: #fff; border: 1px solid var(--cr-line); border-radius: 14px; padding: 1.5rem; }
.cr-toolbar {
    display: flex; flex-wrap: wrap; gap: .6rem; margin-bottom: 1.25rem; padding-bottom: 1rem;
    border-bottom: 1px solid var(--cr-line);
}
.cr-report h2 { font-size: 1.6rem; margin: 0 0 .25rem; color: var(--cr-ink); }
.cr-report h3 {
    font-size: 1.15rem; margin: 2rem 0 .9rem; padding-bottom: .4rem;
    color: #1f4e79; border-bottom: 2px solid var(--cr-line);
}
.cr-subtitle { color: var(--cr-muted); margin: 0 0 1rem; }
.cr-source { color: var(--cr-muted); font-size: .9rem; margin: .5rem 0 0; }
.cr-source span { font-weight: 600; }

.cr-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; }
.cr-metric {
    background: #f8fafc; border: 1px solid var(--cr-line); border-radius: 12px; padding: .85rem 1rem;
    display: flex; flex-direction: column; gap: .2rem;
}
.cr-metric span { color: var(--cr-muted); font-size: .85rem; }
.cr-metric strong { font-size: 1.4rem; color: #1f4e79; }

.cr-notice {
    background: #fff7e6; border: 1px solid #f59e0b; border-radius: 10px;
    padding: .7rem 1rem; margin: 1rem 0; color: #92400e;
}
.cr-figure { margin: 1rem 0; text-align: center; }
.cr-figure img { max-width: 100%; height: auto; }
.cr-table-wrap { overflow-x: auto; margin: 1rem 0; }
.cr-table-wrap table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.cr-table-wrap th, .cr-table-wrap td { padding: .55rem .75rem; border-bottom: 1px solid var(--cr-line); text-align: start; white-space: nowrap; }
.cr-table-wrap th { background: #f1f5f9; color: #334155; }

.cr-fineprint { color: var(--cr-muted); font-size: .85rem; margin: .25rem 0 .75rem; }
.cr-finding { border-radius: 10px; padding: .75rem 1rem; margin: .6rem 0; border-inline-start: 5px solid #0d6efd; background: #eff6ff; }
.cr-finding p { margin: .25rem 0 0; }
.cr-finding.cr-sev-attention { border-color: #f59e0b; background: #fffbeb; }
.cr-finding.cr-sev-critical  { border-color: #dc2626; background: #fef2f2; }
.cr-footer { margin-top: 2rem; color: var(--cr-muted); font-size: .85rem; text-align: center; }

@media print {
    .cr-card, .cr-status, .cr-toolbar, .visit-counter-box, .teacher-hero { display: none !important; }
    .cr-report { border: 0; padding: 0; }
    .cr-figure, .cr-metric, .cr-finding, tr { break-inside: avoid; }
}

/* ── Direction-aware text alignment inside the report body ─────
   .cr-body carries dir="rtl" (Arabic) or dir="ltr" (French/English)
   from the API presentation model. We anchor text-align on the body
   so every block (headings, paragraphs, cards, tables) inherits the
   correct side without needing per-element overrides. */

.cr-body[dir="rtl"] { text-align: right; }
.cr-body[dir="ltr"] { text-align: left; }

/* Metric tiles use flex-direction: column. Without this, the inner
   <span>/<strong> only take their text width, which makes the label
   and value look left-hugging inside the card. Blockify them and
   re-inherit the direction so the text fills the tile. */
.cr-body .cr-metric {
    align-items: stretch;
}

.cr-body .cr-metric span,
.cr-body .cr-metric strong {
    display: block;
    text-align: inherit;
}

/* Finding cards: paragraphs and headings follow the report language. */
.cr-body .cr-finding,
.cr-body .cr-finding p,
.cr-body .cr-finding strong {
    text-align: inherit;
}

/* Table cells: keep them aligned with the report, not the page. */
.cr-body .cr-table-wrap th,
.cr-body .cr-table-wrap td {
    text-align: start;
}

/* These blocks stay centered regardless of report language. */
.cr-body .cr-figure,
.cr-body .cr-figure figcaption,
.cr-body .cr-footer {
    text-align: center;
}

/* The toolbar is a sibling of .cr-body and holds Arabic UI labels.
   Keep it aligned right even when the report body is LTR. */
.cr-toolbar {
    justify-content: flex-start; /* = right in an RTL flex row */
}

.teacher-hero[dir="rtl"] { text-align: right; }


/* ─── Form text alignment ──────────────────────────────────────
   The form carries dir="rtl". Use text-align: start so every field
   follows that direction. This also beats the UA default and any
   generic reset that set text-align: left on form elements.
   ─────────────────────────────────────────────────────────── */

.cr-card,
.cr-field,
.cr-field label,
.cr-field input,
.cr-field select,
.cr-actions,
.cr-note {
    text-align: start;   /* start = right because form is dir="rtl" */
}

/* The numeric input has dir="ltr" in the template, so "start"
   already resolves to "left" for it — digits stay LTR while the
   label above it stays RTL. No extra rule needed. */


/* ─── File input: replace native chrome with themed styling ─── */

.cr-field input[type="file"] {
    /* the generic .cr-field input rule already gives border,
       padding, radius, and width — just refine the internals */
    padding: .4rem .5rem;
    color: #334155;
    cursor: pointer;
    font-size: .95rem;
    line-height: 1.5;

    /* Put the browse button on the right, filename text on its left,
       which is the correct RTL reading order. Inherited from the
       form already, but pinning it here protects against a browser
       that handles file inputs inconsistently in RTL. */
    direction: rtl;
}

/* The browse button — the piece browsers refuse to style normally.
   ::file-selector-button is the current standard (Chrome 89+,
   Firefox 82+, Safari 15.4+). */
.cr-field input[type="file"]::file-selector-button {
    margin-inline-end: .75rem;
    padding: .45rem .95rem;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #f1f5f9;
    color: #334155;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}
.cr-field input[type="file"]::file-selector-button:hover {
    background: #e2e8f0;
    border-color: #94a3b8;
}

/* WebKit fallback for Safari < 15.4 and old Chromium. Must be a
   separate rule — combining both pseudo-elements in one selector
   list invalidates the whole rule in engines that don't recognise
   one of them. */
.cr-field input[type="file"]::-webkit-file-upload-button {
    margin-inline-end: .75rem;
    padding: .45rem .95rem;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #f1f5f9;
    color: #334155;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}
.cr-field input[type="file"]::-webkit-file-upload-button:hover {
    background: #e2e8f0;
    border-color: #94a3b8;
}

/* Give the file input the same visible focus ring as the other fields */
.cr-field input[type="file"]:focus-visible {
    outline: 3px solid #93c5fd;
    outline-offset: 2px;
}

/* Status line: alignment must follow direction, not be centred/left */
.cr-status {
  text-align: start;          /* = right when dir is rtl */
}
.cr-status:dir(rtl) {
  text-align: right;
}
.cr-status:dir(ltr) {
  text-align: left;
}

/* The dir="auto" <small> detail and <pre> debug already handle themselves,
   but make sure nothing cascades into them. */
.cr-status > small { text-align: inherit; }
.cr-status > pre   { text-align: left; }   /* LTR by definition */

/* Class identity card — school / class / teacher / subject from the
   Massar worksheet header. Purely informational, so it stays muted
   and visually subordinate to the executive summary metrics below. */
.cr-context {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: .5rem 1.25rem;
  margin: 1rem 0 1.25rem;
  padding: .85rem 1rem;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #f8fafc;
  font-size: .9rem;
}
.cr-context > div { min-width: 0; }
.cr-context dt {
  margin: 0;
  color: #64748b;
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .01em;
}
.cr-context dd {
  margin: .1rem 0 0;
  color: #0f172a;
  font-weight: 600;
  overflow-wrap: anywhere;  /* long school names must wrap, not overflow */
}

