/**
 * Sophia STARS – Time Out Page Styles
 * Extracted from inline styles during Holiday Audit Refactor – April 2026
 * Relocated to css/pages/timeout.css as the Phase 1 pilot migration
 * (roadmap §1.1) — timeout.html now loads css/tokens.css, but this file
 * is self-contained for its own token needs below and deliberately
 * overrides the global --text/--border/--primary at :root scope with
 * this page's own values (same names, page-specific tuning) rather than
 * being renamed to avoid touching every rule below that references them.
 */

/* ===== PAGE-LOCAL TOKENS (override the global tokens.css values by name) ===== */
:root {
  --primary:         #003057;
  --primary-dark:    #002040;
  --card:            #ffffff;
  --border:          #e2e8f0;
  --border-light:    #f1f5f9;
  --text:            #1e293b;
  --text-light:      #475569;
  --text-muted:      #94a3b8;
  --success:         #10b981;
  --warning:         #f59e0b;
  --danger:          #ef4444;
  --shadow-lg:       0 10px 25px rgba(0,0,0,0.12);
  --border-radius:   8px;
  /* Time Out accent – purple */
  --to-accent:       #7c3aed;
  --to-accent-dark:  #6d28d9;
  --to-accent-light: #ede9fe;
}

/* ===== LOADING OVERLAY ===== */
.to-loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: var(--z-modal, 9998);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1rem;
}
.to-loading-overlay.visible { display: flex; }

.to-spinner {
  width: 42px;
  height: 42px;
  border: 4px solid var(--border);
  border-top-color: var(--to-accent);
  border-radius: 50%;
  animation: to-spin 0.75s linear infinite;
}
@keyframes to-spin { to { transform: rotate(360deg); } }

/* ===== ACCESS DENIED ===== */
.to-access-denied {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 1rem;
  text-align: center;
  padding: 2rem;
}
.to-access-denied .icon { font-size: 3.5rem; }
.to-access-denied h2  { color: var(--danger); font-size: 1.55rem; margin: 0; }
.to-access-denied p   { color: var(--text-muted); max-width: 380px; margin: 0; }

/* ===== PAGE HEADER BADGE ===== */
.to-page-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--to-accent-light);
  color: #5b21b6;
  padding: 0.28rem 0.72rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  margin-top: 0.35rem;
}

/* ===== PAGE INTRO ===== */
.to-page-intro {
  padding: 1.25rem 0 0.25rem;
}
.to-page-intro h2 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--primary);
}
.to-page-intro p {
  margin: 0.25rem 0 0;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ===== TABS ===== */
.to-tab-nav {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 1.5rem;
  padding: 0;
}
.to-tab-btn {
  padding: 0.7rem 1.4rem;
  border: none;
  background: none;
  font-size: 0.93rem;
  font-weight: 600;
  color: var(--text-light);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: color 0.18s, border-color 0.18s;
  letter-spacing: 0.01em;
  min-height: 44px;
  touch-action: manipulation;
  border-radius: 0;
}
.to-tab-btn:hover   { color: var(--to-accent); }
.to-tab-btn.active  { color: var(--to-accent); border-bottom-color: var(--to-accent); }
.to-tab-btn:focus-visible {
  outline: 2px solid var(--to-accent);
  outline-offset: -2px;
}
.to-tab-content       { display: none; }
.to-tab-content.active { display: block; }

@media (max-width: 768px) {
  .to-tab-nav {
    flex-wrap: wrap;
    gap: 0.25rem;
    border-bottom: none;
    margin-bottom: 1rem;
  }
  .to-tab-btn {
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 0;
    flex: 1 1 180px;
  }
  .to-tab-btn.active {
    border-color: var(--to-accent);
    background: rgba(124,58,237,0.06);
  }
}

/* ===== FORM CARD ===== */
.to-form-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.75rem;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
}
.to-section-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding-bottom: 0.85rem;
  border-bottom: 2px solid var(--border-light);
  margin-bottom: 1.25rem;
}
.to-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.1rem;
}
@media (max-width: 768px) {
  .to-form-grid { grid-template-columns: 1fr; }
}
.to-form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.to-form-group.full-width { grid-column: 1 / -1; }
.to-form-group label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Field grouping (who -> when/where -> staff/support -> notes), same logic
   as Re-engagement Room's fieldset/legend pattern - reduces 6+ fields reading
   as one undifferentiated block before submit. */
.to-fieldset {
  border: none;
  padding: 0;
  margin: 0 0 1.5rem;
}
.to-fieldset:last-of-type { margin-bottom: 0; }
.to-fieldset-legend {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0;
  margin: 0 0 0.75rem;
}

/* ===== FORM INPUTS ===== */
.to-input,
.to-select {
  padding: 0.65rem 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.94rem;
  background: var(--card);
  color: var(--text);
  width: 100%;
  box-sizing: border-box;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}
.to-input:focus,
.to-select:focus {
  outline: none;
  border-color: var(--to-accent);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.13);
}
.to-input:focus-visible,
.to-select:focus-visible {
  outline: 2px solid var(--to-accent);
  outline-offset: 2px;
}
textarea.to-input { resize: vertical; min-height: 76px; }

/* ===== STUDENT MINI CARD ===== */
.to-student-mini {
  display: none;
  align-items: center;
  gap: 0.9rem;
  background: var(--to-accent-light);
  border: 1px solid #ddd6fe;
  border-radius: 10px;
  padding: 0.75rem 1rem;
  margin-top: 0.4rem;
  animation: to-fade-in 0.2s ease;
}
.to-student-mini.visible { display: flex; }
@keyframes to-fade-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.to-student-photo {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  background: #ddd6fe;
  flex-shrink: 0;
}
.to-student-mini-name { font-weight: 700; font-size: 0.95rem; color: #1e1b4b; }
.to-student-mini-meta { font-size: 0.78rem; color: #5b21b6; margin-top: 0.15rem; }

/* ===== DROPDOWN ===== */
.to-dropdown {
  position: fixed;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  max-height: 290px;
  overflow-y: auto;
  z-index: var(--z-dropdown, 9999);
  display: none;
  scrollbar-width: thin;
}
.to-dropdown-item {
  padding: 0.62rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.18rem;
  transition: background 0.12s;
  min-height: 44px;
  touch-action: manipulation;
}
.to-dropdown-item:last-child  { border-bottom: none; }
.to-dropdown-item:hover        { background: var(--border-light); }
.to-dropdown-item.highlighted  {
  background: var(--to-accent);
  outline: none;
}
.to-dropdown-item.highlighted .to-dd-name,
.to-dropdown-item.highlighted .to-dd-detail { color: white; }
.to-dd-name   { font-weight: 600; font-size: 0.9rem; color: var(--text); }
.to-dd-detail { font-size: 0.77rem; color: var(--text-muted); }

/* ===== SUPPORT CHIPS ===== */
.to-support-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.15rem;
}
.to-support-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.42rem 0.95rem;
  border: 2px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text-light);
  background: white;
  transition: all 0.15s;
  user-select: none;
  min-height: 44px;
  touch-action: manipulation;
}
.to-support-chip input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.to-support-chip:hover     { border-color: var(--to-accent); color: var(--to-accent); }
.to-support-chip:focus-within {
  outline: 2px solid var(--to-accent);
  outline-offset: 2px;
}
.to-support-chip.selected  {
  background: var(--to-accent);
  border-color: var(--to-accent);
  color: white;
}

/* ===== SUBMIT BUTTON ===== */
.to-submit-btn {
  width: 100%;
  margin-top: 0.75rem;
  padding: 0.9rem 2rem;
  background: linear-gradient(135deg, var(--to-accent), var(--to-accent-dark));
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 14px rgba(124,58,237,0.3);
  letter-spacing: 0.02em;
  min-height: 48px;
  touch-action: manipulation;
  font-family: inherit;
}
.to-submit-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #6d28d9, #5b21b6);
  box-shadow: 0 6px 18px rgba(124,58,237,0.4);
  transform: translateY(-1px);
}
.to-submit-btn:active:not(:disabled) { transform: none; }
.to-submit-btn:focus-visible {
  outline: 2px solid var(--to-accent);
  outline-offset: 3px;
}
.to-submit-btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ===== LOG TABLE ===== */
.to-log-section { margin-top: 2.25rem; }
.to-log-section h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
  margin: 0 0 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.to-log-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 400;
}
.to-log-wrapper {
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.to-log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.to-log-table th {
  background: var(--primary);
  color: white;
  padding: 0.62rem 0.9rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: var(--z-raised, 1);
}
.to-log-table td {
  padding: 0.58rem 0.9rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text);
  vertical-align: middle;
}
.to-log-table tr:last-child td { border-bottom: none; }
.to-log-table tbody tr:hover td { background: #faf5ff; }
.to-log-empty { text-align: center; padding: 2rem 1rem; color: var(--text-muted); }

.to-action-cell { display: flex; gap: 0.25rem; align-items: center; justify-content: center; }

.to-edit-btn,
.to-delete-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0.2rem 0.4rem;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  transition: background 0.15s, border-color 0.15s;
  opacity: 0.5;
}
.to-edit-btn:hover   { opacity: 1; background: var(--to-accent-light); border-color: #c4b5fd; }
.to-delete-btn:hover { opacity: 1; background: #fef2f2; border-color: #fca5a5; }

.to-notes-indicator {
  display: inline-flex;
  align-items: center;
  margin-left: 0.3rem;
  font-size: 0.7rem;
  opacity: 0.55;
  cursor: default;
  vertical-align: middle;
}

.to-support-tag {
  display: inline-flex;
  align-items: center;
  padding: 0.16rem 0.48rem;
  border-radius: 999px;
  background: var(--to-accent-light);
  color: #5b21b6;
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
  margin: 0.1rem;
}

/* ===== ANALYTICS TAB ===== */
.to-analytics-filter {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.to-analytics-filter label {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-muted);
}
.to-analytics-filter select {
  padding: 0.38rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.87rem;
  background: var(--card);
  color: var(--text);
  font-family: inherit;
}
.to-analytics-filter select:focus {
  outline: 2px solid var(--to-accent);
  outline-offset: 2px;
}

/* ===== STAT CARDS ===== */
.to-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}
.to-stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.2rem 1.35rem;
  position: relative;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
  transition: box-shadow 0.2s, transform 0.2s;
}
.to-stat-card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  transform: translateY(-1px);
}
.to-stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--card-color, linear-gradient(90deg, #7c3aed, #a855f7));
}
.to-stat-icon  { font-size: 1.55rem; margin-bottom: 0.35rem; line-height: 1; }
.to-stat-value {
  font-size: 2.15rem;
  font-weight: 800;
  color: var(--to-accent);
  line-height: 1;
  margin-bottom: 0.3rem;
}
.to-stat-label {
  font-size: 0.77rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.to-stat-sub { font-size: 0.8rem; color: var(--text-light); margin-top: 0.2rem; }

/* ===== CHART GRID =====
   Previously lived only in css/analytics-polish-2026.css (shared across
   several pages under generic names like .analytics-grid/.chart-card as
   well as these .to-* ones) — moved here since it's genuinely page-
   specific layout, not decoration, and belongs with the rest of this
   page's rules rather than a file named "polish". No !important needed:
   these class names aren't used or fought over anywhere else. */
.to-chart-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 1rem;
  align-items: stretch;
  margin: 0 0 1.35rem;
}
@media (max-width: 720px) {
  .to-chart-grid {
    grid-template-columns: 1fr;
  }
}

/* Explicit height is load-bearing, not decoration: these charts are
   created with maintainAspectRatio:false (timeout.html), which makes
   Chart.js fill whatever height it measures on the canvas's direct
   parent (.to-chart-card) — it sets that via an inline style on the
   canvas, which always wins over any CSS height put on the canvas
   itself. Without an explicit height here, .to-chart-card is sized by
   its content (the canvas), the canvas is sized by its parent's
   content-derived height — a feedback loop with no floor, which is
   what actually produced the runaway page-height chart. */
.to-chart-card {
  grid-column: span 6;
  height: 320px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.06);
  padding: 1rem 1rem 0.85rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.2s, transform 0.2s;
}
.to-chart-card:hover {
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.09);
  transform: translateY(-1px);
}
.to-chart-card-wide {
  grid-column: span 12;
  height: 365px;
}
@media (max-width: 1100px) {
  .to-chart-card {
    grid-column: span 12;
  }
}

.to-chart-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
  min-width: 0;
  flex-shrink: 0; /* keep its natural height; the canvas takes the rest */
}
.to-chart-heading h3 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--text);
}
.to-chart-heading span {
  flex: 0 1 auto;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  text-align: right;
  line-height: 1.3;
}
@media (max-width: 720px) {
  .to-chart-heading {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }
  .to-chart-heading span {
    text-align: left;
  }
}

.to-chart-card canvas {
  display: block;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0; /* flex items don't shrink below content size by default */
}

/* ===== ANALYTICS PANELS ===== */
.to-analytics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}
@media (max-width: 900px) { .to-analytics-grid { grid-template-columns: 1fr; } }

.to-analytic-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.to-analytic-panel.wide { grid-column: 1 / -1; }
.to-panel-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  padding: 0.78rem 1.2rem;
  font-weight: 700;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}
.to-panel-body { padding: 1.2rem; }

/* ===== BAR CHARTS ===== */
.to-bar-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.to-bar-item  { display: flex; flex-direction: column; gap: 0.18rem; }
.to-bar-row   { display: flex; justify-content: space-between; align-items: baseline; }
.to-bar-label { font-size: 0.85rem; font-weight: 600; color: var(--text); }
.to-bar-count { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; }
.to-bar-track { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.to-bar-fill  {
  height: 100%;
  background: linear-gradient(90deg, #7c3aed, #a855f7);
  border-radius: 4px;
  transition: width 0.5s ease;
}

/* ===== TOP STUDENT TABLE ===== */
.to-top-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}
.to-top-table th {
  text-align: left;
  padding: 0.48rem 0.72rem;
  color: var(--text-muted);
  font-size: 0.73rem;
  font-weight: 700;
  text-transform: uppercase;
  border-bottom: 2px solid var(--border);
}
.to-top-table td {
  padding: 0.52rem 0.72rem;
  border-bottom: 1px solid var(--border-light);
}
.to-top-table tr:last-child td { border-bottom: none; }
.to-top-table tbody tr:hover td { background: #faf5ff; }

.to-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 23px;
  height: 23px;
  border-radius: 50%;
  background: var(--to-accent);
  color: white;
  font-size: 0.7rem;
  font-weight: 800;
}
.to-rank.gold   { background: #f59e0b; }
.to-rank.silver { background: #64748b; }
.to-rank.bronze { background: #92400e; }

/* ===== EMPTY STATE ===== */
.to-empty-state { text-align: center; padding: 2rem 1rem; color: var(--text-muted); }
.to-empty-icon  { font-size: 2.2rem; margin-bottom: 0.4rem; }

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  .to-spinner        { animation: none; opacity: 0.7; }
  .to-student-mini   { animation: none; }
  .to-bar-fill       { transition: none; }
  .to-submit-btn,
  .to-stat-card      { transition: none; transform: none !important; }
}

/* ===== DARK MODE ===== */
.dark-mode .to-form-card,
.dark-mode .to-stat-card,
.dark-mode .to-analytic-panel {
  background: #1e293b;
  border-color: #334155;
}
.dark-mode .to-input,
.dark-mode .to-select {
  background: #0f172a;
  color: #e2e8f0;
  border-color: #475569;
}
.dark-mode .to-input:focus,
.dark-mode .to-select:focus {
  border-color: #a78bfa;
  box-shadow: 0 0 0 3px rgba(167,139,250,0.2);
}
.dark-mode .to-student-mini  { background: #1e1b4b; border-color: #4c1d95; }
.dark-mode .to-student-mini-name { color: #ddd6fe; }
.dark-mode .to-student-mini-meta { color: #a78bfa; }
.dark-mode .to-support-chip       { background: #1e293b; border-color: #475569; color: #cbd5e1; }
.dark-mode .to-support-chip:hover { border-color: #a78bfa; color: #a78bfa; }
.dark-mode .to-support-chip.selected { background: var(--to-accent); border-color: var(--to-accent); color: white; }
.dark-mode .to-log-table th   { background: #082f49; }
.dark-mode .to-log-table td   { color: #e2e8f0; border-bottom-color: #1e293b; }
.dark-mode .to-log-table tbody tr:hover td { background: #1e293b; }
.dark-mode .to-stat-value     { color: #a78bfa; }
.dark-mode .to-bar-fill       { background: linear-gradient(90deg, #7c3aed, #a78bfa); }
.dark-mode .to-top-table th,
.dark-mode .to-top-table td   { color: #e2e8f0; border-color: #334155; }
.dark-mode .to-top-table tbody tr:hover td { background: #334155; }
.dark-mode .to-dropdown        { background: #1e293b; border-color: #334155; }
.dark-mode .to-dropdown-item:hover { background: #334155; }
.dark-mode .to-dd-name         { color: #e2e8f0; }
.dark-mode .to-dd-detail       { color: #94a3b8; }
.dark-mode .to-analytics-filter select { background: #0f172a; color: #e2e8f0; border-color: #475569; }
.dark-mode .to-log-table tbody tr:hover td { background: #1e293b; }
.dark-mode .to-stat-card       { border-color: #334155; }
.dark-mode .to-form-card       { box-shadow: 0 2px 10px rgba(0,0,0,0.3); }
