/* 
    Document   : main_style
    Created on : Apr 18, 2013, 6:03:48 PM
    Author     : rayedchan
    Description:
        Purpose of the stylesheet follows.
*/

/* Particle System Canvas*/
body {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
}

html,
body {
  height: 100%;
  margin: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#container {
  position: relative;
  width: 100%;
  /* use CSS var that JS will set to the header height */
  height: calc(100vh - var(--app-header-height, 64px));
  min-height: 0; /* important for flex children to be able to shrink */
  display: flex;
  flex-direction: row;
  align-items: stretch;
  box-sizing: border-box;
}

/* canvas should occupy the full container area */
#viewport {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  display: block;
  background: transparent;
}

/* Ensure container is positioned for absolutely-positioned legend */
#container {
  position: relative;
  /* existing container rules kept */
}

#viewport {
  flex: 1 1 0;
  min-width: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Header: single-row layout, left brand, right controls */
#appHeader {
  position: relative;
  z-index: 1400; /* Higher than legend (1200) and side panel (10) */

  /* adjusted header background for a clearer, techy look */
  background: linear-gradient(180deg, #f0f6ff 0%, #e8f0ff 60%, #eef4ff 100%);
  backdrop-filter: blur(6px);

  /* visible divider and soft shadow */
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
  box-shadow: 0 2px 10px rgba(8, 15, 30, 0.04);

  width: 100%;
  padding: 12px 20px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

/* Brand / title */
#appHeader .brand {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

#appHeader h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.2px;
  /* subtle tech gradient */
  background: linear-gradient(90deg, #2dd4bf, #60a5fa 60%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.03);
}

/* small accent label */
#appHeader .brand-sub {
  font-size: 0.78rem;
  color: #6b7280;
  text-transform: lowercase;
  font-weight: 600;
  opacity: 0.95;
}

/* controls on the right */
#appHeader .controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* modern control buttons */
.control-btn {
  background: rgba(37, 99, 235, 0.06);
  border: 1px solid rgba(37, 99, 235, 0.12);
  color: var(--text-primary);
  padding: 0.625rem 1.25rem;
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.9375rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 160ms ease;
  white-space: nowrap;
}

.control-icon-btn {
  padding: 0.625rem;
  min-width: 42px;
  min-height: 42px;
  position: relative;
}

.control-icon-btn svg {
  display: block;
}

/* Tooltip styling for icon buttons */
.control-icon-btn::after {
  content: attr(title);
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(-4px);
  background: rgba(15, 23, 42, 0.95);
  color: #ffffff;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 180ms ease, transform 180ms ease, visibility 180ms;
  z-index: 1300;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Small arrow pointing up (to the button) */
.control-icon-btn::before {
  content: "";
  position: absolute;
  top: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 6px solid rgba(15, 23, 42, 0.95);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 180ms ease, visibility 180ms;
  z-index: 1300;
}

/* Show tooltip on hover */
.control-icon-btn:hover::after,
.control-icon-btn:hover::before {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

/* Ensure tooltip doesn't trigger on touch devices */
@media (hover: none) {
  .control-icon-btn::after,
  .control-icon-btn::before {
    display: none;
  }
}

.control-btn:hover {
  background: rgba(37, 99, 235, 0.1);
  border-color: rgba(37, 99, 235, 0.2);
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.08);
}

/* Prevent tooltip transform from affecting button hover transform */
.control-icon-btn:hover {
  background: rgba(37, 99, 235, 0.1);
  border-color: rgba(37, 99, 235, 0.2);
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.08);
  /* Remove translateY so it doesn't interfere with tooltip */
}

.control-btn:active {
  transform: translateY(0);
}

/* compact select styling */
.control-select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding: 8px 38px 8px 12px;
  border-radius: 10px;
  border: 1px solid #e6e9ef;
  background: linear-gradient(180deg, #fff, #fbfdff);
  font-size: 0.94rem;
  color: #0f172a;
  cursor: pointer;
  position: relative;
  height: 38px;
  min-width: 180px;
  box-shadow: 0 1px 2px rgba(2, 6, 23, 0.03);
}

/* dropdown arrow using background SVG - keeps markup clean */
.control-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%236b7280' fill-rule='evenodd' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 10px 6px;
}

/* visually hidden utility for accessibility */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Side Panel */
#sidePanel {
  width: 0;
  min-width: 0;
  overflow: hidden;
  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1),
    padding 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  background: #f8f9fa;
  box-shadow: -2px 0 12px rgba(0, 0, 0, 0.08);
  padding: 24px 0;
  box-sizing: border-box;
  z-index: 10;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

/* side panel: column layout with a sticky header and scrollable content */
#sidePanel {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  /* ensure the panel clips overflow; inner content will scroll */
  overflow: hidden;
  /* existing rules (width, background, transition) remain */
}

#sidePanel.visible {
  width: 340px;
  min-width: 340px;
  padding: 24px 18px;
  overflow-y: auto;
}

#sidePanelToggle {
  position: static;
  align-self: stretch;
  margin: 0;
  background: #fff;
  border: none;
  border-radius: 0 20px 20px 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  width: 48px;
  min-width: 48px;
  height: 100%;
  cursor: pointer;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

#sidePanelToggle:hover {
  background: #f0f0f0;
}

/* Courses Section */
#courseButtons {
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: 100%;
}

.course-item {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  padding: 18px 18px 12px 18px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  position: relative;
  transition: box-shadow 0.2s;
}

.course-item:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.course-btn {
  border: none;
  background: #1976d2;
  color: #fff;
  font: 600 1.05em "Segoe UI", Arial, sans-serif;
  border-radius: 999px;
  padding: 10px 28px;
  margin-bottom: 6px;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(25, 118, 210, 0.08);
  transition: background 0.18s, box-shadow 0.18s;
  outline: none;
}

.course-btn.activeState {
  background: #388e3c;
}
.course-btn.readyState {
  background: #1976d2;
}
.course-btn.inactiveState {
  background: #bdbdbd;
  color: #fff;
}

.course-btn:hover:not(:disabled) {
  background: #1565c0;
  box-shadow: 0 2px 8px rgba(25, 118, 210, 0.13);
}

.course-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.prerequisites {
  font-size: 0.93em;
  color: #888da8;
  margin-top: 2px;
  margin-left: 2px;
  font-style: italic;
  letter-spacing: 0.1px;
}

/*Appearance of input button*/
#courses input {
  border: 1px solid #777777;
  color: white;
  font: bold 11px "Trebuchet MS";
  padding: 1px;
  cursor: pointer;
  -moz-border-radius: 4px;
  -webkit-border-radius: 4px;
}

#courses input:hover {
  background: #6e9e2d;
}

/*Possible States of course input button*/
.activeState {
  background: #6e9e2d;
}

.readyState {
  background: #0000ff;
}

.inactiveState {
  background: #585858;
}

/* Legend for Graph */
#legend {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  padding: 20px 28px;
  max-width: 260px;
  margin: 32px auto 0 auto;
  font-family: "Segoe UI", Arial, sans-serif;
}

/* Legend overlay positioned bottom-left of the canvas (scoped to #container) */
#container > #legend {
  position: absolute;
  left: 16px;
  bottom: 16px;
  width: 240px;
  max-width: calc(100% - 32px);
  background: #ffffff;
  border-radius: 12px;
  padding: 12px 14px 14px 14px;
  box-shadow: 0 6px 24px rgba(12, 18, 30, 0.1);
  box-sizing: border-box;
  z-index: 1200;
  transition: transform 220ms ease, opacity 220ms ease, visibility 220ms;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
  /* start visible by default */
  transform: translateY(0);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* visible / hidden states */
#container > #legend.legend-visible {
  transform: translateY(0);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
#container > #legend.legend-hidden {
  transform: translateY(8px) scale(0.98);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* toggle button in legend corner (show when legend visible) */
#container > #legend .legend-toggle {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: #f3f4f6;
  color: #0f172a;
  font-weight: 700;
  display: inline-flex; /* ensure it's visible by default */
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(2, 6, 23, 0.06);
  transition: background 140ms ease, transform 140ms ease;
}
#container > #legend.legend-hidden .legend-toggle {
  display: none; /* hide close button when legend is hidden */
}
#container > #legend .legend-toggle:hover {
  background: #e8eefc;
  transform: translateY(-1px);
}

/* small help/open button shown only when legend is hidden */
#container > .legend-open {
  position: absolute;
  left: 16px;
  bottom: 16px;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: #111827;
  color: #ffffff;
  font-weight: 700;
  display: none; /* default hidden */
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(2, 6, 23, 0.15);
  z-index: 1210;
}

/* show open button when legend is hidden (legend comes before the button in DOM) */
#container > #legend.legend-hidden + .legend-open {
  display: inline-flex;
}

/* legend inner layout */
#container > #legend h3 {
  margin: 0 0 4px 0;
  font-size: 0.95rem;
  color: #0b1220;
  font-weight: 700;
}
#container > #legend ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#container > #legend li {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #475569;
  font-size: 0.92rem;
}

/* color chips */
#container > #legend .legend-box {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  display: inline-block;
  flex: 0 0 18px;
  box-shadow: 0 1px 3px rgba(2, 6, 23, 0.06);
  border: 1px solid rgba(2, 6, 23, 0.04);
}
#container > #legend .legend-box.grey {
  background: #bdbdbd;
}
#container > #legend .legend-box.blue {
  background: #2563eb;
}
#container > #legend .legend-box.green {
  background: #16a34a;
}
#container > #legend .legend-box.undo {
  background: transparent;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#container > #legend img {
  width: 16px;
  height: 16px;
  display: block;
}

/* safety: ensure legend never forces horizontal scroll */
#container,
#container * {
  box-sizing: border-box;
  max-width: 100%;
  word-break: break-word;
}

/* Hide element from Page*/
.hidden {
  display: none;
}

/* ensure side panel can position the close button */
#sidePanel {
  position: relative; /* added so absolute close button is positioned inside */
  /* ...existing side panel rules... */
}

/* hide the header show-courses button when panel is open */
body.panel-open #sidePanelToggle {
  display: none !important;
}

/* close button inside the panel (top-right) */
.sidepanel-close {
  position: absolute;
  right: 12px;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: none;
  background: #fff;
  color: #0f172a;
  display: none; /* shown only when panel visible */
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(2, 6, 23, 0.08);
  font-size: 16px;
  line-height: 1;
  transition: background 0.12s ease, transform 0.08s ease;
}

/* header inside side panel that stays visible while scrolling */
#sidePanel .sidepanel-header {
  position: sticky;
  top: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: inherit; /* matches panel background */
  border-bottom: 1px solid rgba(2, 6, 23, 0.04);
  box-sizing: border-box;
}

/* title styling inside panel header */
#sidePanel .sidepanel-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: #0b1220;
  line-height: 1;
}

/* scrollable content area */
#sidePanel .sidepanel-content {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px;
  flex: 1 1 auto;
  box-sizing: border-box;
}

#sidePanel.visible .sidepanel-close {
  display: inline-flex;
}

/* keep previous hover behavior */
.sidepanel-close:hover {
  background: #f3f4f6;
  transform: translateY(-1px);
}

/* ensure panel content items don't cause horizontal overflow */
#sidePanel,
#sidePanel * {
  box-sizing: border-box;
  max-width: 100%;
  word-break: break-word;
}

/* course card button styling */
.course-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 10px 12px;
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(2, 6, 23, 0.04);
  margin-bottom: 10px;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
  text-align: left;
  font-family: inherit;
  font-size: 0.95rem;
  color: #0b1220;
  font-weight: 400;
}

.course-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 18px rgba(2, 6, 23, 0.06);
}

.course-card:active {
  transform: translateY(-2px);
}

.course-card:focus {
  outline: 2px solid rgba(59, 130, 246, 0.5);
  outline-offset: 2px;
}

/* title text inside card (no longer a button) */
.course-card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: white;
}

/* prerequisite text */
.course-card-prereq {
  font-size: 0.88rem;
  color: white;
  line-height: 1.3;
}

/* visual states for cards */
.course-card.readyState {
  border: 1px solid rgba(37, 99, 235, 0.12);
  background: #2563eb;
}

.course-card.inactiveState {
  opacity: 0.65;
  background: #bdbdbd;
  color: #94a3b8;
  cursor: not-allowed;
}

.course-card.inactiveState .course-card-title {
  color: white;
}

.course-card.completedState {
  background: #eef2ff;
  border: 1px solid rgba(99, 102, 241, 0.12);
}

/* completed item button */
.completed-item {
  display: inline-block;
  padding: 8px 10px;
  border-radius: 8px;
  background: #16a34a;
  color: white;
  border: 1px solid rgba(37, 99, 235, 0.15);
  font-weight: 700;
  margin-bottom: 8px;
  margin-right: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.88rem;
  transition: background 120ms ease, transform 120ms ease;
}

.completed-item:hover {
  background: #00be46;
  transform: translateY(-2px);
}

.completed-item:focus {
  outline: 2px solid rgba(59, 130, 246, 0.5);
  outline-offset: 2px;
}

/* Completed and Remaining sections layout */
#completedCourses {
  margin-bottom: 16px;
}

#remainingCourses {
  flex: 1 1 auto;
  overflow-y: auto;
}

.panel-subtitle {
  margin: 0 0 10px 0;
  font-size: 0.92rem;
  color: #0b1220;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.85;
}

#completedList {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ============================================
   MOBILE RESPONSIVE STYLES
   ============================================ */

@media (max-width: 768px) {
  /* Header: stack vertically */
  #appHeader {
    flex-direction: column;
    align-items: stretch;
    padding: 1rem;
    gap: 1rem;
    height: auto;
    min-height: var(--header-height);
  }

  .brand {
    justify-content: center;
    text-align: center;
    flex-direction: column;
    gap: 0.25rem;
  }

  .brand h1 {
    font-size: 1.5rem;
  }

  .brand-accent {
    display: none;
  }

  .brand-sub {
    font-size: 0.75rem;
  }

  .controls {
    flex-direction: column;
    gap: 0.75rem;
    align-items: stretch;
  }

  .control-select,
  .control-btn {
    width: 100%;
    text-align: center;
    justify-content: center;
  }

  /* Container: stack canvas, legend, and side panel vertically */
  #container {
    position: relative;
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - var(--header-height));
  }

  /* Canvas section */
  #viewport {
    position: relative;
    width: 100%;
    height: 60vh;
    min-height: 400px;
  }

  /* Hide side panel toggle button on mobile */
  #sidePanelToggle {
    display: none;
  }

  /* Side panel: no longer fixed overlay, flows in document */
  #sidePanel {
    position: relative;
    top: 0;
    right: 0;
    width: 100% !important;
    min-width: 100% !important;
    height: auto;
    transform: none !important;
    box-shadow: none;
    border-left: none;
    border-top: 1px solid #e5e7eb;
    z-index: 1;
    padding: 0 !important;
    background: #f8f9fa;
    display: flex !important;
    flex-direction: column;
  }

  #sidePanel.closed {
    transform: none !important;
    display: block;
  }

  #sidePanel.visible {
    width: 100% !important;
    min-width: 100% !important;
    padding: 0 !important;
  }

  .sidepanel-header {
    padding: 1rem;
    position: relative;
    border-bottom: 1px solid rgba(2, 6, 23, 0.04);
  }

  /* Hide close button on mobile since panel is always visible */
  .sidepanel-close {
    display: none !important;
  }

  .sidepanel-content {
    padding: 1rem;
    max-height: none;
    overflow-y: visible !important;
    flex: 1;
  }

  /* Legend: no longer overlay, flows in document before side panel */
  #container > #legend {
    position: relative;
    bottom: auto;
    left: auto;
    width: 100%;
    max-width: none;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-left: none;
    border-right: none;
    border-radius: 0;
    padding: 1rem;
    box-shadow: none;
    transform: none !important;
    opacity: 1 !important;
    visibility: visible !important;
  }

  #container > #legend.legend-hidden {
    display: none !important;
  }

  #container > #legend.legend-visible {
    display: flex !important;
  }

  #container > #legend h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
  }

  #container > #legend ul {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  #container > #legend li {
    font-size: 0.875rem;
  }

  #container > #legend .legend-toggle {
    top: 0.5rem;
    right: 0.5rem;
    width: 2rem;
    height: 2rem;
    font-size: 1rem;
  }

  /* Hide legend open button on mobile (legend is always visible or toggled via close) */
  #container > .legend-open {
    display: none !important;
  }

  /* Course cards: adjust for mobile touch targets */
  .course-card {
    padding: 1rem;
    min-height: 80px;
  }

  .course-card-title {
    font-size: 0.9rem;
  }

  .course-card-prereq {
    font-size: 0.75rem;
  }

  .completed-item {
    padding: 0.5rem 0.875rem;
    font-size: 0.875rem;
  }

  /* Adjust panel subtitles */
  .panel-subtitle {
    font-size: 1rem;
    margin-bottom: 0.75rem;
  }

  /* Increase touch target sizes for better mobile UX */
  .control-btn,
  .control-select {
    padding: 0.875rem 1.25rem;
    font-size: 1rem;
    min-height: 48px;
  }

  .control-icon-btn {
    padding: 0.875rem;
    min-width: 48px;
    min-height: 48px;
  }

  /* Hide tooltips on mobile - rely on long press or accessibility labels */
  .control-icon-btn::after,
  .control-icon-btn::before {
    display: none;
  }

  /* Adjust completed and remaining lists */
  .completed-list,
  .remaining-list {
    margin-bottom: 1.5rem;
  }

  #completedList {
    gap: 0.5rem;
    padding: 0.75rem 0;
  }

  #courseButtons {
    gap: 0.75rem;
  }
}

/* Extra small devices (phones in portrait) */
@media (max-width: 480px) {
  .brand h1 {
    font-size: 1.25rem;
  }

  #viewport {
    height: 50vh;
    min-height: 350px;
  }

  .course-card-title {
    font-size: 0.85rem;
  }

  .course-card-prereq {
    font-size: 0.7rem;
  }

  .sidepanel-header {
    padding: 0.75rem 1rem;
  }

  .sidepanel-content {
    padding: 0.75rem 1rem;
  }

  #legend {
    padding: 0.75rem 1rem;
  }
}
