/* ========================================
   CE Chart - Cascading Style Sheet
   ======================================== */

:root {
  --bg-page: #000000;
  --bg-panel: #0b0b0d;
  --bg-panel-alt: #131316;
  --bg-panel-2: #08080a;
  --border-color: rgba(255,255,255,0.09);
  --border-color-strong: rgba(255,255,255,0.18);
  --text-primary: #f4f4f5;
  --text-secondary: #9a9aa2;
  --text-muted: #6b6b74;
  --accent: #10B981;
  --accent-soft: rgba(16,185,129,0.12);
  --card-empty-bg: #141416;
  --card-empty-text: #4b4b52;
  --card-empty-border: rgba(255,255,255,0.12);
  --scrollbar-track: #111;
  --scrollbar-thumb: #333;
  --shadow-card: 0 1px 2px rgba(0,0,0,0.4);
  --card-ring-color: rgba(255,255,255,0.55);
  --card-ring-color-hover: rgba(255,255,255,0.75);
}

html.light {
  --bg-page: #f4f4f6;
  --bg-panel: #ffffff;
  --bg-panel-alt: #f7f7f9;
  --bg-panel-2: #eeeef1;
  --border-color: rgba(0,0,0,0.08);
  --border-color-strong: rgba(0,0,0,0.14);
  --text-primary: #18181b;
  --text-secondary: #52525b;
  --text-muted: #8b8b93;
  --accent: #059669;
  --accent-soft: rgba(5,150,105,0.10);
  --card-empty-bg: #ffffff;
  --card-empty-text: #b4b4bb;
  --card-empty-border: rgba(0,0,0,0.14);
  --scrollbar-track: #e8e8ea;
  --scrollbar-thumb: #c8c8cc;
  --shadow-card: 0 1px 3px rgba(0,0,0,0.08);
  --card-ring-color: rgba(24,24,27,0.35);
  --card-ring-color-hover: rgba(24,24,27,0.5);
}

body {
  font-family: 'Vazirmatn', sans-serif;
  font-feature-settings: "ss01";
  background-color: var(--bg-page);
  color: var(--text-primary);
  transition: background-color 0.25s ease, color 0.25s ease;
}

.panel { 
  background-color: var(--bg-panel); 
  border-color: var(--border-color) !important; 
}

.panel-alt { 
  background-color: var(--bg-panel-alt); 
}

.panel-2 { 
  background-color: var(--bg-panel-2); 
}

.text-secondary { 
  color: var(--text-secondary); 
}

.text-muted { 
  color: var(--text-muted); 
}

.border-themed { 
  border-color: var(--border-color) !important; 
}

/* ========== SCROLLBAR STYLING ========== */

::-webkit-scrollbar { 
  width: 8px; 
  height: 8px; 
}

::-webkit-scrollbar-track { 
  background: var(--scrollbar-track); 
}

::-webkit-scrollbar-thumb { 
  background: var(--scrollbar-thumb); 
  border-radius: 4px; 
}

#grid-scroll { 
  scroll-snap-type: x proximity; 
  -webkit-overflow-scrolling: touch; 
}

#grid-scroll::-webkit-scrollbar { 
  height: 6px; 
}

/* ========== THEME TOGGLE ========== */

.theme-toggle {
  position: relative; 
  width: 42px; 
  height: 24px; 
  border-radius: 999px;
  background: var(--bg-panel-2); 
  border: 1px solid var(--border-color-strong);
  cursor: pointer; 
  transition: background 0.2s ease; 
  flex-shrink: 0;
}

.theme-toggle-knob {
  position: absolute; 
  top: 2px; 
  right: 2px; 
  width: 18px; 
  height: 18px;
  border-radius: 999px; 
  background: var(--accent); 
  transition: transform 0.25s ease;
  display: flex; 
  align-items: center; 
  justify-content: center; 
  font-size: 10px;
}

html.light .theme-toggle-knob { 
  transform: translateX(-18px); 
}

/* ========== STAT CARD ========== */

.stat-card { 
  background: var(--bg-panel-alt); 
  border: 1px solid var(--border-color); 
  border-radius: 10px; 
}

/* ========== MODE SELECTOR ========== */

.mode-btn {
  padding: 6px 12px; 
  font-size: 11px; 
  font-weight: bold; 
  border-radius: 8px;
  border: 1px solid var(--border-color-strong); 
  background: var(--bg-panel-2);
  color: var(--text-secondary); 
  cursor: pointer; 
  transition: all .15s ease;

  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.mode-btn-active { 
  background: var(--accent); 
  color: #fff; 
  border-color: var(--accent); 
}

/* ========== VALIDATION HIGHLIGHTING ========== */

.invalid-course {
  border: 3px solid #ec082e !important;
  box-shadow: 0 0 0 3px rgba(244,63,94,0.15) !important;
}

/* ========== CONTEXT MENU ========== */

#context-menu {
  position: fixed; 
  z-index: 60; 
  min-width: 170px;
  background: var(--bg-panel); 
  border: 1px solid var(--border-color-strong);
  border-radius: 10px; 
  box-shadow: 0 8px 24px rgba(0,0,0,0.35); 
  overflow: hidden;
  color: var(--text-primary);
}

/* ========== PLAN CONTROLS ========== */

.icon-btn {
  width: 26px; 
  height: 26px; 
  display: flex; 
  align-items: center; 
  justify-content: center;
  border-radius: 6px; 
  border: 1px solid var(--border-color-strong); 
  background: var(--bg-panel-2);
  color: var(--text-primary); 
  cursor: pointer; 
  font-size: 12px; 
  transition: opacity .15s ease;
}

.icon-btn:disabled { 
  cursor: not-allowed; 
}

/* ========== EXPORT MODE ========== */

#chart-capture-area.export-mode .theme-toggle,
#chart-capture-area.export-mode input[type="checkbox"],
#chart-capture-area.export-mode .no-export {
  display: none !important;
}

#chart-capture-area select {
  font-family: 'Vazirmatn', sans-serif !important;
  text-align-last: center;
}

#chart-capture-area.export-mode select {
  appearance: none !important;
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  padding: 2px 10px !important;
  background-color: var(--bg-panel-2) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: 6px !important;
  display: inline-block !important;
  line-height: normal !important;
}

/* ========== COURSE CARD STYLING ========== */

.course-card {
  --card-tint: var(--accent);

  border-radius: 12px;
  padding: 8px 8px;
  font-size: 12px;
  line-height: 1.4;
  font-weight: 500;
  user-select: none;
  min-height: 74px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  outline: none;
  position: relative;
  color: #ffffff;
  background: var(--card-tint);

  box-shadow:
    0 3px 6px rgba(0,0,0,0.30),
    0 1px 2px rgba(0,0,0,0.22),
    inset 0 1px 0 rgba(255,255,255,0.40),
    inset 0 -3px 4px rgba(0,0,0,0.22);

  transition: box-shadow 0.15s ease, transform 0.15s ease;

  cursor: pointer;
}

/* ---- Interactive state (normal mode) ---- */
.course-card:not(.course-card-locked):not(.course-card-passed) {
  cursor: pointer;
}

.course-card:hover:not(.course-card-locked):not(.course-card-passed) {
  transform: translateY(-2px);
  box-shadow:
    0 6px 12px rgba(0,0,0,0.32),
    0 2px 4px rgba(0,0,0,0.22),
    inset 0 1px 0 rgba(255,255,255,0.45),
    inset 0 -3px 4px rgba(0,0,0,0.2);
}

.course-card:active:not(.course-card-locked):not(.course-card-passed) {
  transform: translateY(0);
  box-shadow:
    0 1px 2px rgba(0,0,0,0.3),
    inset 0 2px 4px rgba(0,0,0,0.35),
    inset 0 -1px 0 rgba(255,255,255,0.15);
}

/* ---- Edit mode (draggable) ---- */
.course-card[draggable="true"] {
  cursor: grab;
}

.course-card[draggable="true"]:active {
  cursor: grabbing;
  transform: scale(0.97);
  box-shadow:
    inset 0 2px 5px rgba(0,0,0,0.4),
    inset 0 -1px 0 rgba(255,255,255,0.1);
}

/* ---- Passed courses (with checkmark ring) ---- */
.course-card.course-card-passed {
  box-shadow:
    0 3px 6px rgba(0,0,0,0.30),
    0 1px 2px rgba(0,0,0,0.22),
    0 0 0 2px var(--card-ring-color),
    inset 0 1px 0 rgba(255,255,255,0.40),
    inset 0 -3px 4px rgba(0,0,0,0.22);
}

.course-card.course-card-passed:hover {
  box-shadow:
    0 6px 12px rgba(0,0,0,0.32),
    0 2px 4px rgba(0,0,0,0.22),
    0 0 0 2px var(--card-ring-color-hover),
    inset 0 1px 0 rgba(255,255,255,0.45),
    inset 0 -3px 4px rgba(0,0,0,0.2);
}

/* ---- Locked courses ---- */
.course-card.course-card-locked {
  opacity: 0.5;
  filter: grayscale(0.25);
  cursor: not-allowed;
}

.course-card.course-card-locked:hover {
  transform: none;
  box-shadow:
    0 3px 6px rgba(0,0,0,0.30),
    0 1px 2px rgba(0,0,0,0.22),
    inset 0 1px 0 rgba(255,255,255,0.40),
    inset 0 -3px 4px rgba(0,0,0,0.22);
}

/* ---- Invalid course validation ---- */
.course-card.invalid-course {
  border: 2.5px solid #ec082e;
  box-shadow:
    0 3px 6px rgba(0,0,0,0.30),
    0 0 0 3px rgba(236,8,46,0.28),
    inset 0 1px 0 rgba(255,255,255,0.35),
    inset 0 -3px 4px rgba(0,0,0,0.22);
}

.course-card.invalid-course:hover:not(.course-card-locked) {
  transform: translateY(-2px);
  box-shadow:
    0 6px 12px rgba(0,0,0,0.32),
    0 0 0 3px rgba(236,8,46,0.36),
    inset 0 1px 0 rgba(255,255,255,0.4),
    inset 0 -3px 4px rgba(0,0,0,0.2);
}

/* ---- Typography ---- */
.course-title {
  width: 100%;
  text-align: center;
  word-wrap: break-word;
}

.course-credits {
  font-size: 10px;
  opacity: 0.8;
  margin-top: 2px;
}

/* ---- Icon buttons on card ---- */
.course-card button,
.course-card span {
  position: absolute;
  font-size: 11px;
}

.course-edit-btn {
  top: 4px;
  left: 4px;
  opacity: 0.6;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s ease;
}

.course-edit-btn:hover {
  opacity: 1;
}

.course-lock-icon {
  top: 4px;
  left: 4px;
  opacity: 0.9;
}

.course-check-icon {
  top: 4px;
  right: 4px;
  font-size: 12px;
}

.course-warn-icon {
  bottom: 4px;
  left: 4px;
  font-size: 11px;
  cursor: help;
}

/* ---- Focus-visible (keyboard navigation) ---- */
.course-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow:
    0 3px 6px rgba(0,0,0,0.30),
    0 0 0 4px rgba(16,185,129,0.25),
    inset 0 1px 0 rgba(255,255,255,0.40),
    inset 0 -3px 4px rgba(0,0,0,0.22);
}

.inline-icon {
  vertical-align: middle;
  flex-shrink: 0;
}

/* ==========================================================================
   Mobile Optimization - CE Chart Header
   ========================================================================== */
@media (max-width: 768px) {
  header.panel {
    padding: 16px 14px !important;
    gap: 16px !important;
    align-items: stretch !important;
  }

  header.panel > div:first-child {
    width: 100%;
  }
  header.panel h1 {
    font-size: 1.15rem !important;
    line-height: 1.4 !important;
  }
  header.panel p.text-xs.text-secondary {
    display: none !important;
  }
  
  header.panel > div:first-child > div:first-child > svg {
    width: 36px !important;
    height: 36px !important;
  }

  header.panel > div:last-child {
    width: 100%;
    align-items: stretch !important;
    gap: 12px !important;
  }

  header.panel > div:last-child > div:nth-child(1) {
    justify-content: space-between !important;
    width: 100%;
  }

  header.panel > div:last-child > div:nth-child(2) {
    width: 100%;
    background: var(--bg-panel-alt);
    padding: 6px !important;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    justify-content: space-between !important;
  }
  
  #plan-select {
    flex: 1;
    max-width: none !important;
    margin-inline-end: 8px;
  }
  
  .icon-btn {
    width: 32px !important;
    height: 32px !important;
  }

  header.panel > div:last-child > div:nth-child(3) {
    width: 100%;
    justify-content: space-between !important;
    gap: 6px !important;
  }
  
  .mode-btn {
    flex: 1;
    justify-content: center;
    padding: 10px 4px !important;
  }
}