/* RPH form: roomier fields, the section rail, focus mode (one question per
   screen) and the collapsible document preview. Paired with rph_focus.js.
   Every rule is scoped to #view-rph-form, so no other view is touched. */

/* ---------- Roomier fields (both modes) ---------- */
#view-rph-form .rph-step-content input[type="text"]:not(.rph-phase__dur):not(.rph-time-grid *),
#view-rph-form .rph-step-content input[type="date"],
#view-rph-form .rph-step-content input:not([type]),
#view-rph-form .rph-step-content select,
#view-rph-form .rph-step-content textarea {
  font-size: 15px;
  line-height: 1.5;
  padding: 0.65rem 0.85rem;
  border-radius: var(--r-md);
}
#view-rph-form .rph-step-content input[type="text"]:not(.rph-phase__dur):not(.rph-time-grid *),
#view-rph-form .rph-step-content input[type="date"],
#view-rph-form .rph-step-content select { min-height: 44px; }
#view-rph-form .rph-step-content textarea { min-height: 5.25rem; }
#view-rph-form .rph-step-content label.text-xs,
#view-rph-form .rph-step-content span.text-xs.font-semibold,
#view-rph-form .rph-step-content label.text-\[11px\] {
  font-size: 13.5px;
  margin-bottom: 0.4rem;
}
#view-rph-form #rph-kbat-options label { font-size: 14px; padding: 0.65rem 0.75rem; }

/* ---------- Header toggles ---------- */
#view-rph-form .rph-head__toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 12px;
  font-weight: 600;
  padding: 0.35rem 0.7rem;
  border-radius: var(--r-pill);
  border: 1px solid var(--g-border, rgba(0, 0, 0, 0.1));
  color: var(--g-ink-soft, #475569);
  background: transparent;
  cursor: pointer;
}
#view-rph-form .rph-head__toggle:hover { color: var(--g-ink, #0f172a); background: var(--g-surface-inset, rgba(0, 0, 0, 0.04)); }
#view-rph-form .rph-head__toggle:focus-visible { outline: 2px solid var(--g-accent, #2563eb); outline-offset: 2px; }
/* The preview only sits beside the form at xl; below that the pane switch
   already swaps the two. */
#view-rph-form .rph-preview-toggle { display: none; }
@media (min-width: 1280px) {
  #view-rph-form .rph-preview-toggle { display: inline-flex; }
}

/* ---------- Collapsible preview (xl) ---------- */
@media (min-width: 1280px) {
  #view-rph-form.rph-preview-off .rph-split-doc { display: none !important; }
  #view-rph-form.rph-preview-off .rph-split-form { grid-column: 1 / -1 !important; }
}

/* ---------- Section rail ---------- */
#view-rph-form .rph-rail {
  position: relative;
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding: 0.15rem 0.1rem 0.5rem;
  margin-bottom: 1rem;
  scrollbar-width: thin;
}
#view-rph-form .rph-rail:empty { display: none; }
#view-rph-form .rph-rail__item {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 13px;
  font-weight: 500;
  color: var(--g-ink-soft, #475569);
  padding: 0.5rem 0.75rem;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
}
#view-rph-form .rph-rail__item:hover { background: var(--g-surface-inset, rgba(0, 0, 0, 0.04)); color: var(--g-ink, #0f172a); }
#view-rph-form .rph-rail__item:focus-visible { outline: 2px solid var(--g-accent, #2563eb); outline-offset: 2px; }
#view-rph-form .rph-rail__item.is-current {
  color: var(--g-ink, #0f172a);
  background: var(--g-surface-raised, #fff);
  border-color: var(--g-border, rgba(0, 0, 0, 0.1));
}
#view-rph-form .rph-rail__name { flex: 1 1 auto; }
#view-rph-form .rph-rail__count { font-size: 11px; color: var(--g-ink-faint, #94a3b8); }
#view-rph-form .rph-rail__dot {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1.5px solid var(--g-border-strong, #94a3b8);
  box-sizing: border-box;
}
#view-rph-form .rph-rail__item.is-partial .rph-rail__dot {
  border-color: var(--g-accent, #2563eb);
  background: linear-gradient(90deg, var(--g-accent, #2563eb) 50%, transparent 50%);
}
#view-rph-form .rph-rail__item.is-done .rph-rail__dot {
  border-color: var(--g-accent, #2563eb);
  background: var(--g-accent, #2563eb);
  box-shadow: inset 0 0 0 2.5px var(--g-surface-raised, #fff);
}
#view-rph-form .rph-rail__foot { display: none; font-size: 12px; color: var(--g-ink-faint, #94a3b8); padding: 0.4rem 0.75rem 0; margin: 0; }

/* A wide form column gets the rail as a sidebar; a narrow one (preview open,
   tablet, phone) keeps it as a scrolling row above the step. */
@supports (container-type: inline-size) {
  @container rphform (min-width: 760px) {
    #view-rph-form .rph-body {
      display: grid;
      grid-template-columns: 190px minmax(0, 1fr);
      gap: 1.25rem;
      align-items: start;
    }
    #view-rph-form .rph-rail {
      flex-direction: column;
      overflow: visible;
      margin-bottom: 0;
      position: sticky;
      top: 0;
    }
    #view-rph-form .rph-rail__item { white-space: normal; }
    #view-rph-form .rph-rail__foot { display: block; }
  }
}

/* ---------- Focus mode: one question per screen ---------- */
#view-rph-form.rph-focus #rph-steps { display: none; }
#view-rph-form.rph-focus [data-rph-q]:not(.is-q-current) { display: none !important; }
#view-rph-form.rph-focus .rph-q-shell:not(:has(.is-q-current)) { display: none !important; }
/* The curriculum card's box and title would frame a single question; in focus
   mode the prompt does that job. */
#view-rph-form.rph-focus .rph-q-shell { border: 0; background: none; padding: 0; }
#view-rph-form.rph-focus .rph-q-shell > div:first-child { display: none; }
/* The step footers give way to the one focus bar. */
#view-rph-form.rph-focus .rph-step-content > .glass-actionbar:not(.rph-focus-bar) { display: none !important; }
/* One column, and no item spanning a column that no longer exists. */
#view-rph-form.rph-focus .rph-step-content .grid:not(#rph-kbat-options):not(.rph-time-grid) {
  grid-template-columns: minmax(0, 1fr);
}
#view-rph-form.rph-focus .rph-step-content .grid:not(#rph-kbat-options):not(.rph-time-grid) > * { grid-column: auto; }
#view-rph-form.rph-focus .rph-step-content { max-width: 46rem; }
/* The current phase is the whole screen: its collapse toggle has nothing to do. */
#view-rph-form.rph-focus .rph-phase.is-q-current .rph-phase__caret,
#view-rph-form.rph-focus .rph-phase.is-q-current .rph-phase__open { display: none; }

#view-rph-form .rph-focus-prompt { margin: 0.25rem 0 1.25rem; scroll-margin-top: 5rem; }
#view-rph-form .rph-focus-prompt[hidden] { display: none; }
#view-rph-form:not(.rph-focus) .rph-focus-prompt { display: none; }
#view-rph-form .rph-focus-prompt__meta {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--g-ink-soft, #475569);
}
#view-rph-form .rph-focus-prompt__meter { height: 4px; margin: 0.5rem 0 1.1rem; }
#view-rph-form .rph-focus-prompt__q {
  font-family: var(--g-font-display, inherit);
  font-size: 1.35rem;
  line-height: 1.3;
  color: var(--g-ink, #0f172a);
  margin: 0;
}
#view-rph-form .rph-focus-prompt__sub { font-size: 13.5px; color: var(--g-ink-soft, #475569); margin: 0.3rem 0 0; }
#view-rph-form .rph-focus-prompt__sub[hidden],
#view-rph-form .rph-focus-prompt__q[hidden] { display: none; }

#view-rph-form .rph-focus-bar { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
#view-rph-form .rph-focus-bar[hidden] { display: none !important; }
/* One height for every button in the bar. */
#view-rph-form .rph-focus-bar .glass-btn,
#view-rph-form .rph-focus-bar__next { min-height: 2.75rem; }
#view-rph-form .rph-focus-bar__hint { font-size: 11.5px; color: var(--g-ink-faint, #94a3b8); white-space: nowrap; }
/* Beside the open preview the form column is too narrow for the hint and the
   buttons on one row: with it, Back + Preview + DOCX + PDF + "Seterusnya"
   need ~760px and the Next button ran past the bar's edge in Bahasa Melayu
   at 1280px. Below 820px the hint goes. */
@supports (container-type: inline-size) {
  @container rphform (max-width: 820px) {
    #view-rph-form .rph-focus-bar__hint { display: none; }
  }
}
#view-rph-form .rph-focus-bar__next {
  display: inline-flex;
  align-items: center;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: var(--g-oum-blue, #1e3a8a);
  padding: 0.65rem 1.15rem;
  border: 0;
  border-radius: var(--r-md);
}
#view-rph-form .rph-focus-bar__next:hover { filter: brightness(1.1); }
#view-rph-form .rph-focus-bar__next:focus-visible { outline: 2px solid var(--g-accent, #2563eb); outline-offset: 2px; }
@media (max-width: 639.98px) {
  #view-rph-form .rph-focus-bar__hint { display: none; }
  /* One row on a phone: the pinned bar would otherwise wrap to two and cover
     the question. Back, DOCX and PDF go icon-only; their text stays for screen
     readers. */
  #view-rph-form .rph-focus-bar,
  #view-rph-form .rph-focus-bar > div { flex-wrap: nowrap; }
  #view-rph-form .rph-focus-bar .glass-btn--ghost > span,
  #view-rph-form .rph-step-content > .glass-actionbar .glass-btn--ghost > span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
  #view-rph-form .rph-focus-prompt__q { font-size: 1.15rem; }

  /* "Show all fields" mode: each step's pinned footer held Back, DOCX, PDF and
     a long "Next: …" button, and wrapped to three rows — a quarter of a phone
     screen. Back goes icon-only too and the right-hand group stays on one row,
     so the footer is one row from 375px and two at most below that. Step 4's
     four actions sit in a 2 × 2 grid under Back. */
  #view-rph-form .rph-step-content > .glass-actionbar:not(.rph-focus-bar) { align-items: center; row-gap: 0.5rem; }
  #view-rph-form .rph-step-content > .glass-actionbar:not(.rph-focus-bar) > div { flex-wrap: nowrap; gap: 0.4rem; }
  #view-rph-form .rph-step-content > .glass-actionbar [data-i18n="rph_btn_back"] {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
  #view-rph-form .rph-step-content > .glass-actionbar > button:first-child:has([data-i18n="rph_btn_back"]) { min-width: 2.75rem; padding-left: 0.6rem; padding-right: 0.6rem; justify-content: center; }
  #view-rph-form .rph-step-content > .glass-actionbar :is(button, .glass-btn) { min-height: 2.75rem; white-space: nowrap; }
  #view-rph-form .rph-step-content > .glass-actionbar:not(.rph-focus-bar) .glass-btn--ghost { padding-left: 0.6rem; padding-right: 0.6rem; min-width: 0; }
  #view-rph-form .rph-step-content > .glass-actionbar:not(.rph-focus-bar) { column-gap: 0.4rem; }
  /* Five actions are too many to pin over the form; on a phone step 4's
     footer stays at the end of the step, where the teacher finishes. */
  #view-rph-form #rph-step-4 > .glass-actionbar { flex-wrap: wrap; position: static; }
  #view-rph-form #rph-step-4 > .glass-actionbar > div {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    margin: 0 !important;
  }
  #view-rph-form #rph-step-4 > .glass-actionbar > div > * {
    min-width: 0;
    margin: 0 !important;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    justify-content: center;
    white-space: nowrap;
  }
}
@media (max-width: 359.98px) {
  #view-rph-form #rph-step-4 > .glass-actionbar > div { grid-template-columns: minmax(0, 1fr); }
}
/* The smallest phones (320–399px): five buttons on one row only fit with
   tighter gaps and padding. */
@media (max-width: 399.98px) {
  #view-rph-form .rph-focus-bar,
  #view-rph-form .rph-focus-bar > div { gap: 0.25rem; }
  #view-rph-form .rph-focus-bar .glass-btn--ghost { padding-left: 0.6rem; padding-right: 0.6rem; min-width: 0; }
  #view-rph-form .rph-focus-bar__next { padding-left: 0.85rem; padding-right: 0.85rem; }
}
