/*
 * NestThem Shared Component Library — Premium Redesign Phase 1 (Foundation)
 *
 * One implementation of each pattern the UX audit found hand-rebuilt from
 * scratch 3-10+ times across templates/*.html: modals, toasts, buttons,
 * the PIN keypad, empty states, cards, and the responsive table→card
 * collapse. Built from tokens.css. Class names match the naming already
 * most common across the existing templates (e.g. parent.html's
 * .modal-overlay/.modal-box, account_settings.html's .pin-key/.pin-dot)
 * so migrating a page onto this file later is a rename, not a rewrite.
 *
 * Phase 1 ships this file and links it everywhere; it does not yet
 * replace any page's existing bespoke modal/toast markup — that
 * migration is Phase 3/4, page by page.
 */

/* ── The one shared visibility utility ───────────────────────────────
   Toggled via classList everywhere across the app (parent.html alone
   toggles it 70+ times) — was independently hand-duplicated in 7 files
   (create/login/parent/reset_password/story, plus two real "never
   actually defined" bugs found and fixed in kids.html/studio.html in
   Phase 1). This is the one definition every template now shares. */
.hidden { display: none !important; }

/* ── Buttons — every variant clears --tap-min, no exceptions (fixes the
   parent.html .btn-sm 36px gap the audit flagged) ───────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: var(--tap-min); padding: .7rem 1.4rem;
  border-radius: var(--radius-full); border: 1px solid transparent;
  font-family: var(--font-body); font-weight: 700; font-size: .95rem;
  cursor: pointer; transition: transform var(--duration-fast) var(--ease-out),
    background var(--duration-base) var(--ease-out), box-shadow var(--duration-base) var(--ease-out);
  background: var(--surface); color: var(--ink); border-color: var(--border);
}
.btn:hover  { background: var(--surface-hover); }
.btn:active { transform: scale(.97); }
.btn:focus-visible { outline: none; box-shadow: var(--shadow-glow); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary-hover); }

.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--surface); }

.btn-danger { background: var(--error); border-color: var(--error); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }

/* Success/purple — added during the admin/teacher consistency pass to
   absorb teacher.html's two extra bespoke variants into the one system. */
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(1.1); }
.btn-purple { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-purple:hover { filter: brightness(1.1); }

/* Small variant still meets the tap-target minimum — it's smaller in
   padding/font only, never in touchable height. */
.btn-sm { min-height: var(--tap-min); padding: .45rem 1rem; font-size: .85rem; }

/* Icon-only buttons must always carry aria-label in markup — this class
   only handles sizing, not accessibility, which is a markup concern. */
.btn-icon { min-width: var(--tap-min); min-height: var(--tap-min); padding: 0; border-radius: var(--radius-md); }

/* ── Cards ────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}

/* ── Modal — one implementation replacing every hand-rolled overlay ────
   Sprint correction (Phase 3): Phase 1 originally gated visibility on an
   `.open` class + opacity/pointer-events transition — a mechanism that
   matched nothing else in the app. Every existing modal, and every other
   toggled element platform-wide, already uses `.hidden` (see above). This
   version uses that same convention as the actual show/hide mechanism;
   `.open` is now purely an optional visual enhancement (fade/scale-in)
   layered on top, never required for the modal to work. */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(8,12,24,.72); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: var(--space-4);
}
.modal-overlay.open { opacity: 1; }
.modal-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto;
  padding: var(--space-6); position: relative;
}
.modal-overlay.open .modal-box {
  animation: modal-pop var(--duration-base) var(--ease-out);
}
@keyframes modal-pop {
  from { transform: translateY(12px) scale(.98); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}
.modal-title {
  font-family: var(--font-display); font-weight: 700; font-size: 1.4rem;
  color: var(--ink); margin: 0 0 var(--space-4);
}
.modal-close {
  position: absolute; top: var(--space-4); right: var(--space-4);
  min-width: var(--tap-min); min-height: var(--tap-min);
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; color: var(--ink-muted); cursor: pointer;
  border-radius: var(--radius-full); font-size: 1.2rem;
}
.modal-close:hover { background: var(--surface-hover); color: var(--ink); }

/* Generic footer button row — same shape as .confirm-dialog-actions,
   named for use in any .modal-box (not only confirm dialogs). */
.modal-footer { display: flex; justify-content: flex-end; gap: var(--space-3); margin-top: var(--space-5); }

/* Usage contract: a modal is opened by removing the `hidden` class from
   `.modal-overlay` (the same convention every other toggled element in
   the app already uses) and closed by adding it back — optionally also
   toggling `.open` for the entrance animation. Closed either by a
   dedicated .modal-close button or a single delegated backdrop-click
   handler — never a per-modal bespoke inline onclick, which is what the
   audit found duplicated with subtly different logic per file. */

/* ── Confirm dialog — reuses .modal-box, one shared pattern replacing
   native confirm()/alert() for destructive actions ──────────────────── */
.confirm-dialog-body { color: var(--ink-muted); font-size: .95rem; margin-bottom: var(--space-5); }
.confirm-dialog-actions { display: flex; gap: var(--space-3); justify-content: flex-end; }

/* ── Toast — one implementation replacing 3 divergent per-file versions ── */
.toast-stack {
  position: fixed; bottom: var(--space-5); left: 50%; transform: translateX(-50%);
  z-index: 300; display: flex; flex-direction: column; gap: var(--space-2);
  width: min(92vw, 420px); pointer-events: none;
}
.toast {
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-md); padding: .85rem 1.1rem;
  box-shadow: var(--shadow-md); color: var(--ink); font-family: var(--font-body);
  font-size: .9rem; font-weight: 600;
  display: flex; align-items: center; gap: .6rem;
  opacity: 0; transform: translateY(8px); transition: opacity var(--duration-base), transform var(--duration-base);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { border-color: var(--success); }
.toast.error   { border-color: var(--error); }

/* ── Inline alert banners — replaces native alert()/confirm() usage ──── */
.alert-banner {
  border-radius: var(--radius-md); padding: .9rem 1.1rem; font-size: .9rem;
  font-weight: 600; display: flex; align-items: center; gap: .6rem; margin-bottom: var(--space-4);
}
.alert-banner.success { background: var(--success-bg); color: #6ee7b7; border: 1px solid var(--success); }
.alert-banner.error   { background: var(--error-bg);   color: #fca5a5; border: 1px solid var(--error); }
.alert-banner.warning { background: var(--warning-bg); color: #fcd34d; border: 1px solid var(--warning); }

/* ── PIN keypad — one implementation replacing account_settings.html's
   and kids.html's two divergent versions. Used for both the parent-level
   "step back out" lock and the new per-child entry PIN. ──────────────── */
.pin-dots { display: flex; gap: var(--space-3); justify-content: center; margin-bottom: var(--space-5); }
.pin-dot {
  width: 16px; height: 16px; border-radius: var(--radius-full);
  border: 2px solid var(--border-strong); transition: background var(--duration-fast), border-color var(--duration-fast);
}
.pin-dot.filled { background: var(--primary); border-color: var(--primary); }
.pin-keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-3); max-width: 280px; margin: 0 auto; }
.pin-key {
  min-height: 56px; border-radius: var(--radius-md); border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--ink); font-family: var(--font-display);
  font-size: 1.4rem; font-weight: 700; cursor: pointer;
}
.pin-key:hover { background: var(--surface-hover); }
.pin-key:active { transform: scale(.95); }
.pin-key.pin-key-clear { font-size: 1.1rem; color: var(--ink-muted); }

/* ── Empty state — generalizes parent.html's already-good pattern ────── */
.empty-state {
  text-align: center; padding: var(--space-7) var(--space-5);
  display: flex; flex-direction: column; align-items: center; gap: var(--space-3);
}
.empty-state-icon { font-size: 3rem; opacity: .8; }
.empty-state-title { font-family: var(--font-display); font-weight: 700; font-size: 1.2rem; color: var(--ink); }
.empty-state-body { color: var(--ink-muted); font-size: .95rem; max-width: 40ch; }
.empty-state-actions { display: flex; gap: var(--space-3); flex-wrap: wrap; justify-content: center; margin-top: var(--space-2); }

/* ── Responsive data table → card collapse — generalizes admin.html's
   already-good pattern for reuse anywhere a table needs to survive a
   narrow viewport (e.g. teacher.html's currently-unresponsive .prog-table). ── */
@media (max-width: 640px) {
  table.responsive-collapse, table.responsive-collapse thead, table.responsive-collapse tbody,
  table.responsive-collapse th, table.responsive-collapse td, table.responsive-collapse tr {
    display: block;
  }
  table.responsive-collapse thead { display: none; }
  table.responsive-collapse tr {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-md); margin-bottom: var(--space-3); padding: var(--space-3);
  }
  table.responsive-collapse td {
    display: flex; justify-content: space-between; gap: var(--space-3);
    padding: .4rem 0; border: none; text-align: right;
  }
  table.responsive-collapse td::before {
    content: attr(data-label); font-weight: 700; color: var(--ink-muted); text-align: left;
  }
}

/* ── Forms — consistent field sizing, 16px inputs prevent iOS zoom ──── */
.field { margin-bottom: var(--space-4); }
.field label { display: block; font-size: .85rem; font-weight: 700; color: var(--ink-muted); margin-bottom: .4rem; }
.field input, .field select, .field textarea {
  width: 100%; min-height: var(--tap-min); padding: .7rem .9rem;
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--ink); font-family: var(--font-body); font-size: 1rem;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: var(--shadow-glow);
}

/* ── Password show/hide toggle — was independently duplicated (identical
   CSS) in login.html/account_settings.html/reset_password.html; this is
   the one shared definition. Pair with a local togglePw(id, btn) JS
   function (tiny enough that it isn't worth a shared script include). */
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 2.8rem; }
.pw-eye {
  position: absolute; right: .75rem; top: 50%; transform: translateY(-50%);
  min-width: var(--tap-min); min-height: var(--tap-min);
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer; color: var(--ink-muted);
  font-size: 1.1rem; line-height: 1; padding: 0;
}
.pw-eye:hover { color: var(--ink); }

/* ── Reduced motion — respects OS-level accessibility setting by
   neutralizing the transition/animation declarations above (button
   hover/active transforms, modal-pop entrance, toast slide-in). Any
   page-local animation should follow this same guard. ──────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  .btn:active { transform: none; }
  .pin-key:active { transform: none; }
  .modal-overlay.open .modal-box { animation: none; }
}
