/* ══════════════════════════════════════════════════════════════════════════
   Course Scheduler — Global Stylesheet
   All tokens are defined as CSS custom properties on :root so the entire
   theme can be changed by editing this one block.
   ══════════════════════════════════════════════════════════════════════════ */

/* ── Design Tokens ─────────────────────────────────────────────────────── */
:root {
  /* Brand / primary palette */
  --color-primary:        #1e3a5f;
  --color-primary-hover:  #254a78;
  --color-primary-mid:    #2d5a9e;
  --color-primary-dark:   #1e5fa0;

  /* Accent */
  --color-accent:         #4a90d9;
  --color-accent-bg:      #f0f7ff;
  --color-accent-hover:   #eef3ff;
  --color-accent-border:  #4a90d9;

  /* Text */
  --color-text:           #1e2a3a;
  --color-text-secondary: #374151;
  --color-text-medium:    #4a6080;
  --color-text-muted:     #5a7a9a;
  --color-text-subtle:    #64748b;
  --color-text-gray:      #6b7280;
  --color-text-light:     #8a9aaa;
  --color-text-faint:     #9ca3af;
  --color-text-border:    #b0c0d8;

  /* Surfaces */
  --color-bg:             #f4f6f9;
  --color-surface:        #ffffff;
  --color-surface-subtle: #f8fafc;
  --color-surface-hover:  #f0f4f8;
  --color-surface-accent: #fafcff;
  --color-surface-mid:    #f1f5f9;

  /* Borders */
  --color-border:         #e0e8f0;
  --color-border-medium:  #c0d0e0;
  --color-border-strong:  #b0bec8;
  --color-border-subtle:  #dde3ec;

  /* Semantic — success */
  --color-success:        #15803d;
  --color-success-mid:    #16a34a;
  --color-success-bg:     #f0fdf4;
  --color-success-light:  #d1fae5;
  --color-success-border: #bbf7d0;
  --color-success-dark:   #065f46;

  /* Semantic — error / danger */
  --color-error:          #b91c1c;
  --color-error-mid:      #dc2626;
  --color-error-bg:       #fff5f5;
  --color-error-light:    #fee2e2;
  --color-error-border:   #fecaca;

  /* Semantic — warning */
  --color-warning:        #d97706;
  --color-warning-bg:     #fffbeb;
  --color-warning-border: #fde68a;
  --color-warning-dark:   #92400e;

  /* Semantic — info / purple */
  --color-info:           #2563eb;
  --color-info-teal:      #0891b2;
  --color-info-blue:      #0369a1;
  --color-purple:         #7c3aed;
  --color-purple-bg:      #f5f3ff;
  --color-purple-border:  #ddd6fe;
  --color-purple-dark:    #6b21a8;

  /* Typography */
  --font-serif:  -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:   monospace;

  /* Type scale — all relative to 16 px browser default */
  --text-2xs:  0.5625rem;   /* 9 px  */
  --text-xs:   0.625rem;    /* 10 px */
  --text-sm:   0.6875rem;   /* 11 px */
  --text-base: 0.75rem;     /* 12 px */
  --text-md:   0.8125rem;   /* 13 px */
  --text-lg:   0.875rem;    /* 14 px */
  --text-xl:   1rem;        /* 16 px */
  --text-2xl:  1.125rem;    /* 18 px */
  --text-3xl:  1.25rem;     /* 20 px */
  --text-4xl:  1.375rem;    /* 22 px */

  /* Spacing */
  --space-1:   0.125rem;    /* 2 px  */
  --space-2:   0.25rem;     /* 4 px  */
  --space-3:   0.375rem;    /* 6 px  */
  --space-4:   0.5rem;      /* 8 px  */
  --space-5:   0.5625rem;   /* 9 px  */
  --space-6:   0.75rem;     /* 12 px */
  --space-7:   0.875rem;    /* 14 px */
  --space-8:   1rem;        /* 16 px */
  --space-9:   1.125rem;    /* 18 px */
  --space-10:  1.25rem;     /* 20 px */
  --space-11:  1.75rem;     /* 28 px */

  /* Border radii */
  --radius-sm:  0.25rem;    /* 4 px  */
  --radius-md:  0.3125rem;  /* 5 px  */
  --radius-lg:  0.375rem;   /* 6 px  */
  --radius-xl:  0.5rem;     /* 8 px  */
  --radius-pill: 0.625rem;  /* 10 px */

  /* Elevation / shadows */
  --shadow-xs:    0 1px 3px rgba(0,0,0,0.07);
  --shadow-sm:    0 1px 4px rgba(0,0,0,0.08);
  --shadow-md:    0 2px 10px rgba(0,0,0,0.09);
  --shadow-nav:   0 2px 8px rgba(0,0,0,0.20);
  --shadow-modal: 0 8px 32px rgba(0,0,0,0.18);

  /* Z-index scale */
  --z-sticky:  50;
  --z-overlay: 100;
  --z-modal:   200;

  /* Nav height — used for `calc(100vh - var(--nav-height))` offsets */
  --nav-height: 3rem;       /* 48 px */

  /* Nav text — dynamically overridden by applyThemeGlobal() when the
     primary color is too light for white text to meet 4.5:1 contrast */
  --color-nav-text:       #ffffff;
  --color-nav-text-muted: rgba(255,255,255,0.65);
  --color-nav-text-faint: rgba(255,255,255,0.50);
  --color-nav-tab-hover:  rgba(255,255,255,0.12);
  --color-nav-tab-active: rgba(255,255,255,0.18);
}


/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body, #root { height: 100%; }
body {
  font-family: var(--font-serif);
  background: var(--color-bg);
  color: var(--color-text);
}
button, input, select, textarea { font-family: inherit; }


/* ── Scrollbars ─────────────────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 0.375rem; height: 0.375rem; }
::-webkit-scrollbar-track { background: var(--color-surface-hover); }
::-webkit-scrollbar-thumb { background: var(--color-border-medium); border-radius: var(--radius-sm); }


/* ══════════════════════════════════════════════════════════════════════════
   FLEX UTILITIES
   ══════════════════════════════════════════════════════════════════════════ */
.fl  { display: flex; }
.fla { display: flex; align-items: center; }
.flb { display: flex; align-items: center; justify-content: space-between; }
.flc { display: flex; align-items: center; justify-content: center; }
.fld { display: flex; flex-direction: column; }

.flex-1   { flex: 1; }
.flex-none { flex-shrink: 0; }
.flex-wrap { flex-wrap: wrap; }


/* ══════════════════════════════════════════════════════════════════════════
   TYPOGRAPHY UTILITIES
   ══════════════════════════════════════════════════════════════════════════ */

/* Heading inside a panel / card */
.text-heading {
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--color-text);
}

/* Smaller label-style heading (e.g. column name) */
.text-subheading {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--color-text-secondary);
}

/* Secondary / meta text below a heading */
.text-meta {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  margin-top: 0.125rem;
}

/* Placeholder / hint text */
.text-hint {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

/* Monospace (code, IDs, etc.) */
.text-mono {
  font-family: var(--font-mono);
}

/* Centered, muted message (loading / empty state) */
.text-center-muted {
  text-align: center;
  color: var(--color-text-light);
  font-size: var(--text-base);
  padding-top: 1.5rem;
}


/* ══════════════════════════════════════════════════════════════════════════
   FORM ELEMENTS
   ══════════════════════════════════════════════════════════════════════════ */
.field-label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03125rem;
  margin-bottom: 0.1875rem;
  display: block;
}

.field-input {
  width: 100%;
  padding: 0.375rem 0.5625rem;
  border: 1px solid var(--color-border-medium);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  background: var(--color-surface-subtle);
  color: var(--color-text);
}
.field-input:focus   { outline: none; border-color: var(--color-accent); background: var(--color-surface); }
.field-input:disabled { opacity: 0.55; cursor: not-allowed; }

.toggle {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  cursor: pointer;
  font-size: var(--text-base);
}
.toggle input[type="checkbox"] { width: 0.875rem; height: 0.875rem; cursor: pointer; }


/* ══════════════════════════════════════════════════════════════════════════
   BUTTONS
   ══════════════════════════════════════════════════════════════════════════ */
.btn {
  padding: 0.375rem 0.8125rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--text-base);
  font-weight: 600;
  border: none;
  transition: background 0.12s, color 0.12s;
}

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

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-primary);
  border: 1px solid var(--color-border-medium);
}
.btn-secondary:hover { background: var(--color-surface-hover); }

.btn-ghost {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-light);
  font-size: var(--text-3xl);
  line-height: 1;
}

.btn-outline {
  background: var(--color-surface);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border-medium);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  padding: 0.25rem 0.625rem;
  cursor: pointer;
}
.btn-outline:hover { background: var(--color-surface-hover); }

.btn:disabled  { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

/* Small variant (used inline in toolbars) */
.btn-sm {
  font-size: var(--text-sm);
  padding: 0.1875rem 0.625rem;
}


/* ══════════════════════════════════════════════════════════════════════════
   BADGE
   ══════════════════════════════════════════════════════════════════════════ */
.badge {
  font-size: var(--text-2xs);
  padding: 0.125rem 0.375rem;
  border-radius: var(--radius-pill);
  font-weight: 700;
  white-space: nowrap;
}

/* Semantic badge variants */
.badge-success { background: var(--color-success-light); color: var(--color-success-dark); }
.badge-error   { background: var(--color-error-light);   color: var(--color-error); }
.badge-warning { background: var(--color-warning-bg);    color: var(--color-warning-dark); }
.badge-info    { background: var(--color-accent-bg);     color: var(--color-primary-dark); }


/* ══════════════════════════════════════════════════════════════════════════
   CARD
   ══════════════════════════════════════════════════════════════════════════ */
.card {
  padding: 0.75rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  transition: box-shadow 0.12s;
}
.card:hover { box-shadow: var(--shadow-md); }

/* Flat variant — no hover shadow */
.card-flat {
  padding: 0.75rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}

/* Section card — white panel with standard padding */
.section-card {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  border: 1px solid var(--color-border);
  padding: 1.25rem;
  margin-bottom: 1rem;
}


/* ══════════════════════════════════════════════════════════════════════════
   SECTION TITLE
   ══════════════════════════════════════════════════════════════════════════ */
.section-title {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--color-primary);
  text-transform: uppercase;
  letter-spacing: 0.05rem;
}

/* Muted variant used for group separators in lists */
.section-label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--color-text-gray);
  text-transform: uppercase;
  letter-spacing: 0.03125rem;
}


/* ══════════════════════════════════════════════════════════════════════════
   TOP NAVIGATION
   ══════════════════════════════════════════════════════════════════════════ */
.nav-bar {
  height: var(--nav-height);
  background: var(--color-primary);
  display: flex;
  align-items: center;
  padding: 0 var(--space-10);
  gap: 0.25rem;
  box-shadow: var(--shadow-nav);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
}

.nav-logo { color: var(--color-nav-text); font-weight: 700; font-size: var(--text-lg); margin-right: 1rem; }
.nav-sub  { color: var(--color-nav-text-faint); font-size: var(--text-xs); }

.nav-tab {
  padding: 0.375rem 1rem;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-nav-text-muted);
  background: transparent;
  transition: background 0.15s, color 0.15s;
}
.nav-tab:hover  { background: var(--color-nav-tab-hover);  color: var(--color-nav-text); }
.nav-tab.active { background: var(--color-nav-tab-active); color: var(--color-nav-text); }
.nav-tab.soon   { opacity: 0.38; cursor: not-allowed; pointer-events: none; }


/* ══════════════════════════════════════════════════════════════════════════
   MODAL / OVERLAY
   ══════════════════════════════════════════════════════════════════════════ */

/* Full-screen scrim */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 3.75rem;
  background: rgba(0,0,0,0.35);
}

/* The floating panel that sits on top of the overlay */
.modal-panel {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-modal);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Standard modal header row */
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.modal-title {
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--color-primary);
}

/* Scrollable body */
.modal-body {
  overflow-y: auto;
  flex: 1;
}

/* Footer with action buttons */
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}


/* ══════════════════════════════════════════════════════════════════════════
   LOAD PANEL (Open Schedule / Session)
   ══════════════════════════════════════════════════════════════════════════ */

/* Separator between list groups */
.list-group-header {
  padding: 0.5rem 1rem 0.25rem;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--color-text-gray);
  text-transform: uppercase;
  letter-spacing: 0.03125rem;
  background: var(--color-surface-subtle);
  border-bottom: 1px solid var(--color-border);
}

.list-group-header + .list-group-header,
.list-group-header.list-group-divider {
  border-top: 2px solid var(--color-border);
}

/* Each clickable row in the load panel */
.list-row {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5625rem 1rem;
  border-bottom: 1px solid var(--color-surface-hover);
  cursor: pointer;
  background: var(--color-surface);
  transition: background 0.1s;
}
.list-row:hover      { background: var(--color-accent-hover); }
.list-row.is-current { background: var(--color-accent-hover); }

/* First row variant — slightly off-white "new" action */
.list-row-new {
  background: var(--color-surface-subtle);
}
.list-row-new:hover { background: var(--color-accent-hover); }

.list-row-icon { font-size: 1.0625rem; }

.list-row-label {
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-row-meta {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}


/* ══════════════════════════════════════════════════════════════════════════
   SIDEBAR PANEL (Schedule History / Version drawer)
   ══════════════════════════════════════════════════════════════════════════ */
.sidebar-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-modal);
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  box-shadow: var(--shadow-modal);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8125rem 1rem;
  background: var(--color-primary);
  flex-shrink: 0;
}

.sidebar-title {
  color: var(--color-surface);
  font-weight: 700;
  font-size: var(--text-lg);
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.875rem;
}


/* ══════════════════════════════════════════════════════════════════════════
   TOP BAR (within feature panels — below nav)
   ══════════════════════════════════════════════════════════════════════════ */
.panel-toolbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border-subtle);
  padding: 0.4375rem 1.125rem;
  display: flex;
  align-items: center;
  gap: 0.625rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.panel-toolbar-title {
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--color-primary);
  flex-shrink: 0;
}

/* Session-name pill shown in the toolbar */
.session-badge {
  display: flex;
  align-items: center;
  gap: 0.3125rem;
  background: var(--color-surface-hover);
  border-radius: var(--radius-sm);
  padding: 0.125rem 0.5625rem;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  flex-shrink: 0;
}
.session-badge-label { color: var(--color-text-faint); }

/* Thin vertical divider between toolbar groups */
.toolbar-divider {
  width: 1px;
  height: 1.125rem;
  background: var(--color-border);
  flex-shrink: 0;
}


/* ══════════════════════════════════════════════════════════════════════════
   SAVE-AS INLINE FORM (inside toolbar)
   ══════════════════════════════════════════════════════════════════════════ */
.save-as-input {
  font-size: var(--text-sm);
  padding: 0.1875rem 0.5rem;
  border: 1px solid var(--color-border-medium);
  border-radius: var(--radius-sm);
  width: 11.25rem;
  outline: none;
}

.btn-cancel-sm {
  font-size: var(--text-sm);
  padding: 0.1875rem 0.5rem;
  background: none;
  border: 1px solid var(--color-border-medium);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--color-text-gray);
}


/* ══════════════════════════════════════════════════════════════════════════
   STATUS / FEEDBACK MESSAGES
   ══════════════════════════════════════════════════════════════════════════ */
.status-msg         { font-size: var(--text-sm); flex-shrink: 0; }
.status-msg.success { color: var(--color-success); }
.status-msg.error   { color: var(--color-error); }

/* Inline alert banner (e.g. S2 notice, schedule-conflict warning) */
.alert-banner {
  flex-shrink: 0;
  padding: 0.3125rem 1.375rem;
  font-size: var(--text-sm);
  display: flex;
  gap: 0.875rem;
  align-items: center;
  flex-wrap: wrap;
}
.alert-banner-warn {
  background: var(--color-warning-bg);
  border-bottom: 1px solid var(--color-warning-border);
  color: var(--color-warning-dark);
}
.alert-banner-error {
  background: var(--color-error-bg);
  border-bottom: 2px solid var(--color-error-mid);
  color: var(--color-error);
}
.alert-banner-info {
  background: var(--color-accent-bg);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-primary);
}

/* Diff-list items inside conflict banners */
.diff-added   { font-size: var(--text-sm); padding: 0.25rem 0.5625rem; background: var(--color-success-bg);  border-radius: var(--radius-sm); margin-bottom: 0.1875rem; border-left: 3px solid var(--color-success-mid); }
.diff-removed { font-size: var(--text-sm); padding: 0.25rem 0.5625rem; background: var(--color-error-bg);    border-radius: var(--radius-sm); margin-bottom: 0.1875rem; border-left: 3px solid var(--color-error-mid); }


/* ══════════════════════════════════════════════════════════════════════════
   EMPTY STATE
   ══════════════════════════════════════════════════════════════════════════ */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.125rem;
}

.empty-state-icon  { font-size: 2.75rem; }
.empty-state-title { font-size: 1.25rem; color: var(--color-primary); }
.empty-state-desc  { font-size: var(--text-base); color: var(--color-text-light); max-width: 23.75rem; text-align: center; }

.btn-open-primary {
  padding: 0.625rem 1.75rem;
  border-radius: 0.4375rem;
  border: 2px solid var(--color-accent);
  background: var(--color-accent-bg);
  font-size: var(--text-md);
  color: var(--color-primary-dark);
  cursor: pointer;
  transition: background 0.12s;
}
.btn-open-primary:hover { background: var(--color-accent-hover); }


/* ══════════════════════════════════════════════════════════════════════════
   SCHEDULE GRID UTILITIES
   ══════════════════════════════════════════════════════════════════════════ */

/* Shared page wrapper that fills the space below the nav */
.page-fill {
  height: calc(100vh - var(--nav-height));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--color-bg);
  color: var(--color-text);
}

/* Scrollable full-page view (non-flex) */
.page-scroll {
  overflow-y: auto;
  height: calc(100vh - var(--nav-height));
}

/* Constrained content column (e.g. settings, catalog) */
.page-content {
  max-width: 43.75rem;
  margin: 0 auto;
  padding: 1.75rem;
}

/* Semester toggle (S1 / S2 segmented control) */
.semester-toggle {
  display: flex;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 2px solid var(--color-accent);
  flex-shrink: 0;
}

.semester-btn {
  padding: 0.1875rem 0.75rem;
  border: none;
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 700;
}
.semester-btn.active   { background: var(--color-accent); color: var(--color-surface); }
.semester-btn.inactive { background: var(--color-accent-bg); color: var(--color-primary-dark); }


/* ══════════════════════════════════════════════════════════════════════════
   ADMIN / MANAGEMENT PANELS
   ══════════════════════════════════════════════════════════════════════════ */
.admin-page {
  overflow-y: auto;
  height: calc(100vh - var(--nav-height));
}

.admin-content {
  max-width: 43.75rem;
  margin: 0 auto;
  padding: 1.75rem;
}

.admin-page-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: 0.25rem;
}

.admin-page-desc {
  font-size: var(--text-base);
  color: var(--color-text-light);
  margin-bottom: 1.5rem;
}
