/* =====================================================
   scheduler.css
   PURPOSE: Styles for the Study Scheduler screen ONLY.
   This includes the schedule-a-session form and the
   upcoming-sessions list.

   SCOPE: Everything inside #scheduler-screen
   DO NOT put styles for other screens in this file.
   ===================================================== */

#scheduler-screen {
  display:        flex;
  flex-direction: column;
  gap:            var(--space-5);
  /* Overrides animations.css's shared "#screen-container > *"
     entrance animation (transform-based translateX + fade) with
     an opacity-only version for JUST this screen. Reason: that
     shared transform creates a new containing block for any
     position:fixed descendant while it's running — and
     .scheduler-form is exactly that (see its own comment in
     this file). For the ~200ms the entrance animation plays,
     the fixed form was rendering relative to THIS element's own
     box instead of the real viewport, then visibly snapping
     ~190px down to its correct position the instant the
     animation ended — the "jumps from where it used to be"
     bug. Reuses the existing fadeIn keyframe (animations.css)
     rather than a new one — same duration/easing as the shared
     animation, just without the transform component that
     causes the problem. "#screen-container > #scheduler-screen"
     (two IDs) rather than a bare "#scheduler-screen" selector is
     needed to reliably out-specificity the shared rule
     regardless of the two files' <link> order in index.html —
     tied specificity would otherwise fall back to source order,
     and animations.css loads AFTER this file. */
}

#screen-container > #scheduler-screen {
  animation: fadeIn 0.2s cubic-bezier(0.25, 0.1, 0.25, 1);
}

/* --- Schedule-a-session form ────────────────────────────
   Floats fixed at the bottom of the screen, ~10px above the
   bottom nav bar — same "docked action panel" treatment as
   .quiz-deck-select__start (game-modes.css), including the
   same left:50%/translateX centering and bottom offset built
   from --bottom-nav-height + --safe-area-bottom rather than a
   guessed flat number, so it stays correctly clear of the nav
   bar on notched devices too. Not width-capped the way that
   single BUTTON is (max-width:400px there) — this is a whole
   multi-field card, so it keeps the same calc(100% - 32px)
   width (matching #screen-container's own 16px side padding)
   as everything else on this screen, rather than looking
   narrower once it's pulled out of the normal flow.

   Since this removes the form from #scheduler-screen's normal
   document flow, #scheduler-form-spacer (scheduler.js) reserves
   matching space in the SCROLLABLE content so the Upcoming
   Sessions list's last row doesn't end up hidden behind it —
   sized by actually measuring the form's real rendered height
   (ResizeObserver in scheduler.js) rather than a flat guess,
   the same lesson .quiz-deck-select-content-spacer's own
   comment (game-modes.css) already learned the hard way: a
   guessed height silently drifts out of sync with the real
   element and starts swallowing taps on whatever's behind it. */
.scheduler-form {
  position:      fixed;
  left:          50%;
  transform:     translateX(-50%);
  bottom:        calc(var(--bottom-nav-height) + var(--safe-area-bottom) + 10px);
  width:         calc(100% - 32px);
  z-index:       150;
  display:          flex;
  flex-direction:   column;
  gap:              var(--space-4);
  padding:          var(--space-4);
  background-color: var(--color-card-bg);
  border-radius:    var(--radius-lg);
  box-shadow:       var(--shadow-elevation-2);
}

/* Label sits IN FRONT of its own control on one line —
   "Deck [dropdown]", "Date [date picker]", "Time [time
   picker]" — rather than stacked above it. Each field is its
   own full-width row (Date and Time each get their own row
   rather than sharing one side by side): a shared row was
   tried once before in this file and specifically caused
   native date/time inputs to overlap on narrow phone screens
   (see the old min-width:0 comment this replaced) — adding
   inline labels on TOP of a side-by-side split would only
   make that worse, not better, so each field keeping the
   FULL row width is the safer choice given this app's mobile-
   first sizing. Three single-line rows instead of three
   stacked label-then-control pairs is what actually makes the
   form shorter overall. */
.scheduler-form__row {
  display:     flex;
  align-items: center;
  gap:         12px;
}

.scheduler-form__label {
  flex-shrink: 0;
  width:       50px;
  /* Fixed (not content-sized) so "Deck"/"Date"/"Time" all
     line up and every row's control starts at the same x
     position regardless of which word is shortest. */
  font-size:   var(--font-size-footnote);
  color:       var(--color-text-secondary);
  font-weight: 600;
}

.scheduler-form__select,
.scheduler-form__input {
  flex:              1;
  min-width:         0;
  /* min-width: 0 — without this, a flex item defaults to a
     content-based minimum width; native date/time inputs have
     their own intrinsic min-width that could otherwise refuse
     to shrink below on a narrow phone screen. */
  min-height:        44px;
  /* min-height fixes a mobile-only quirk: an EMPTY
     type="time" input (it starts blank — unlike the date
     input, which defaults to today's date) has no shadow-
     DOM content to size itself against once appearance is
     stripped below, so it renders squashed down to just
     the padding until tapped/focused, then visibly grows.
     A fixed min-height keeps it full-size from the start,
     whether or not it has a value yet. */
  padding:           10px 12px;
  background-color:  var(--ios-tertiarySystemFill);
  border:            none;
  border-radius:     var(--border-radius);
  color:             var(--color-text-primary);
  font-size:         var(--font-size-body);
  font-family:       var(--font-primary);
  text-align:        center;
  box-sizing:        border-box;
  /* Mobile browsers draw their own native background/box
     behind date and time inputs by default — border: none
     and background-color above don't fully replace it, so
     the OS's own control chrome was showing through as an
     offset "ghost" box behind our styled one. This removes
     that native chrome entirely so only our box renders. */
  appearance:         none;
  -webkit-appearance: none;
}

/* The Deck <select>'s displayed value (and its dropdown
   options) default to left-aligned text on mobile — center
   it instead so it matches the rest of the field's centered
   feel. text-align alone covers Chrome/Safari's closed-box
   rendering; text-align-last is what Firefox actually reads
   for a <select>'s own display text. */
.scheduler-form__select {
  text-align:      center;
  text-align-last: center;
}

/* The Deck field's own closed box gets a background/text
   color from the shared rule above, but its OPEN dropdown
   list (desktop only — mobile shows the OS's own picker
   sheet, styled by the OS, not this) is a separate native
   popup that doesn't inherit that background automatically.
   It only picks up the "color" we set on the <select> for its
   text, so without an explicit background here it renders on
   the browser's own default (near-white) popup background —
   in dark mode that's light text on a light popup, unreadable.
   Setting both explicitly on <option> keeps the popup legible
   in both themes. (Chrome/Edge/Firefox honor color/background-
   color on <option>; other option-list styling is much more
   limited, which is fine — only contrast matters here.) */
.scheduler-form__select option {
  text-align:       center;
  background-color: var(--color-card-bg);
  color:            var(--color-text-primary);
}

/* Wraps the submit button and, in edit mode, the Cancel
   button next to it. */
.scheduler-form__actions {
  display: flex;
  gap:     10px;
  margin-top: 4px;
}

.scheduler-form__submit {
  flex: 1;
}

/* --- Upcoming sessions list --- */

/* .section-title (main.css, shared across screens) carries its
   own margin-bottom on top of #scheduler-screen's flex "gap"
   between every child — the two stack (flex gaps don't collapse
   margins), which was pushing "Upcoming Sessions" further below
   "Study Scheduler" than intended. Cancelling it here (scoped to
   just this screen, not the shared rule) leaves the flex gap as
   the only source of spacing there. */
#scheduler-screen > .section-title {
  margin-bottom: 0;
}

.scheduler-upcoming-title {
  font-size:      var(--font-size-subheadline);
  font-weight:    600;
  color:          var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  /* Pulls this up closer under the title than the screen's
     shared var(--space-5) flex gap alone would put it — every
     OTHER gap on this screen (list → form, etc.) keeps that
     normal spacing; just this one pair reads as "directly
     under" instead. */
  margin-top: -12px;
}

#scheduler-list {
  display:        flex;
  flex-direction: column;
  /* Tighter than #deck-list's 12px gap (home.css) — these are
     smaller, denser rows than Home's deck cards, so a tighter
     gap keeps several sessions readable on screen at once
     instead of spreading them out like full deck cards. */
  gap:            8px;
}

/* Each session is its own rounded card now — same shape/
   elevation language as .deck-card (home.css), just without
   its accent-gradient background (this list has no per-item
   "identity" color the way decks do) and without individually
   overriding box-shadow on hover/press, since these rows
   aren't a primary navigation tap target the way a deck card
   is. Also no longer relies on a shared list container to
   clip/round its corners (there is no such container to clip
   anymore), which is what let .scheduler-item--new's glow stop
   getting flattened against a container edge and bloom outward
   freely, same as the Match game's tile glow. */
.scheduler-item {
  display:          flex;
  align-items:      center;
  gap:              12px;
  padding:          12px 14px;
  background-color: var(--color-card-bg);
  border-radius:    var(--border-radius-card);
  box-shadow:       var(--shadow-elevation-1);
  transition:       background-color 0.15s ease;
}

/* Highlights whichever row is currently open in the form
   above, so it's clear what "Update Session" would apply
   to on a list with several sessions. */
.scheduler-item--editing {
  background-color: var(--tint-accent-soft);
}

.scheduler-item__icon {
  display:          flex;
  align-items:      center;
  justify-content:  center;
  width:            34px;
  height:           34px;
  flex-shrink:      0;
  border-radius:    50%;
  background-color: var(--tint-accent-soft);
  color:            var(--color-accent-amber);
}

.scheduler-item__info {
  flex:           1;
  min-width:      0;
  display:        flex;
  flex-direction: column;
  gap:            2px;
}

.scheduler-item__deck {
  font-size:     var(--font-size-body);
  font-weight:   600;
  color:         var(--color-text-primary);
  overflow:      hidden;
  text-overflow: ellipsis;
  white-space:   nowrap;
}

/* "New" badge — only for the session just created this
   visit (see renderScheduler()'s newSessionId param in
   scheduler.js). Pure CSS animation, same technique as
   .card-thumb__new-badge in deck.css: fully visible for
   ~5s, fades out over ~0.6s, then stays hidden. Inline next
   to the deck name (not a corner overlay like the card
   thumbnail badge) since a list row has no free corner —
   the icon and Edit/Delete buttons already occupy those. */
.scheduler-item__new-badge {
  display:          inline-block;
  vertical-align:   1px;
  margin-left:      6px;
  padding:          1px 6px;
  border-radius:    9px;
  background-color: var(--color-accent-amber);
  color:            #fff;
  font-size:        9px;
  font-weight:      700;
  text-transform:   uppercase;
  letter-spacing:   0.02em;
  animation:        scheduler-item-new-badge-fade 5.6s ease forwards;
}

@keyframes scheduler-item-new-badge-fade {
  0%, 89%  { opacity: 1; }
  100%     { opacity: 0; }
}

/* Green glowing border for the same just-created session —
   IDENTICAL keyframes/timing/colors to the Match game's
   .match-tile--matched glow (see @keyframes match-tile-glow
   in game-modes.css), duplicated here rather than shared
   across files per this app's per-screen CSS scoping (see
   this file's own header comment). Unlike that one, this
   doesn't leave a lasting border once the glow fades — "new"
   here is a one-shot arrival cue, not a permanent state, and
   the "New" text badge above already covers the lasting-
   indicator role. */
.scheduler-item--new {
  animation: scheduler-item-new-glow 1400ms ease-out;
  /* #scheduler-list is a flex column, so z-index applies to
     these cards even without an explicit position (same as
     flex/grid items generally) — the glow's box-shadow can
     still bleed past the 8px gap into the NEXT card's box, and
     that sibling paints AFTER this one, so without raising this
     card above it, a --editing/--missed card landing right
     below the glowing one (the only siblings with a background
     of their own) would paint over and hide part of the glow.
     Identical reasoning to .match-tile--matched's z-index in
     game-modes.css. */
  z-index: 2;
}

@keyframes scheduler-item-new-glow {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--ios-systemGreen) 0%, transparent);
  }
  25%, 60% {
    box-shadow: 0 0 0 4px    color-mix(in srgb, var(--ios-systemGreen) 100%, transparent),
                0 0 26px 8px  color-mix(in srgb, var(--ios-systemGreen) 85%, transparent),
                0 0 42px 16px color-mix(in srgb, var(--ios-systemGreen) 45%, transparent);
  }
  100% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--ios-systemGreen) 0%, transparent);
  }
}

.scheduler-item__time {
  font-size: var(--font-size-footnote);
  color:     var(--color-text-secondary);
}

/* --- Missed session state ──────────────────────────────
   Applied when a session's time has already passed but it
   isn't marked complete yet — see isSessionMissed() in
   scheduler.js. Still shown (not hidden) for the same
   reason as home.js's reminder card: no real push
   notifications yet, so silently dropping it once its time
   passes risks it going unseen entirely. Warm orange accent
   (icon circle + time text) instead of the default accent
   color, plus a swapped warning-triangle icon, so it reads
   clearly as "needs attention" rather than a plain upcoming
   row. */
.scheduler-item--missed {
  background-color: color-mix(in srgb, var(--ios-systemOrange) 8%, transparent);
}

.scheduler-item__icon--missed {
  background-color: color-mix(in srgb, var(--ios-systemOrange) 18%, transparent);
  color:             var(--ios-systemOrange);
}

.scheduler-item__time--missed {
  color:       var(--ios-systemOrange);
  font-weight: 600;
}

/* Edit and Delete share the same small round-button
   shape — Edit sits to the left of Delete (matches the
   order they're written in scheduler.js's markup) and
   tints accent-blue instead of red on hover. */
.scheduler-item__edit,
.scheduler-item__delete {
  display:          flex;
  align-items:      center;
  justify-content:  center;
  flex-shrink:      0;
  width:            26px;
  height:           26px;
  border:           none;
  border-radius:    50%;
  background-color: var(--ios-tertiarySystemFill);
  color:            var(--ios-systemGray);
  cursor:           pointer;
  transition:        background-color 0.15s ease, color 0.15s ease;
}

.scheduler-item__edit:hover {
  background-color: var(--tint-accent-soft);
  color:            var(--color-accent-amber);
}

.scheduler-item__delete:hover {
  background-color: color-mix(in srgb, var(--ios-systemRed) 15%, transparent);
  color:            var(--ios-systemRed);
}
