/* ============================================================================
   DKU Course Dependency Graph — Material Design 2 theme (green)
   Builds on the design-system tokens in colors_and_type.css / md-components.css.
   ============================================================================ */

/* ---- Green Material theme: override the baseline purple/teal roles ---- */
:root {
  --md-primary: #388E3C;          /* green 700 */
  --md-primary-variant: #1B5E20;  /* green 900 */
  --md-secondary: #FFB300;        /* amber 600 — accent */
  --md-secondary-variant: #FF8F00;
  --md-on-primary: #FFFFFF;
  --md-on-secondary: #000000;

  --brand: var(--md-primary);     /* alias used by graph highlight rules */
  --primary-12: rgba(56,142,60,.12);
  --primary-50: rgba(56,142,60,.50);

  /* edge palette */
  --edge-and: #9aa7bd;            /* neutral required line */
  --edge-or: #F0A33B;             /* amber "one of" line */

  --canvas-bg: #F4F6F4;           /* flat surface-ish canvas */
  --canvas-dot: #E2E8E2;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--md-font);
  color: var(--md-on-surface-high);
  background: var(--md-background);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ============================ App bar ============================ */
#appbar { gap: 16px; flex: none; z-index: 40; }
.appbar__logo { font-size: 28px; color: var(--md-on-primary); }
.appbar__titles { display: flex; flex-direction: column; line-height: 1.1; }
.mdc-appbar__title { line-height: 1.2; }
.appbar__sub { color: rgba(255,255,255,0.82); letter-spacing: .3px; }
.appbar__spacer { flex: 1; }
.appbar__stat {
  color: var(--md-on-primary);
  background: rgba(255,255,255,0.16);
  padding: 6px 14px; border-radius: var(--md-shape-pill);
  white-space: nowrap;
}

/* ============================ Filter toolbar ============================ */
#toolbar {
  flex: none; z-index: 30;
  display: flex; align-items: flex-end; flex-wrap: wrap; gap: 14px 16px;
  padding: 12px 16px;
  background: var(--md-surface);
  box-shadow: var(--md-elev-02);
}
.toolbar__spacer { flex: 1 1 0; min-width: 0; }

/* Filter toggle (app bar) — mobile only */
#filter-toggle { display: none; color: var(--md-on-primary); flex: none; }
#filter-toggle .mi { transition: opacity var(--md-dur-short) var(--md-ease-standard); }
#filter-toggle.is-collapsed { opacity: .72; }

/* Outlined field wrapper with persistent overline label */
.mfield { display: flex; flex-direction: column; gap: 5px; }
.mfield__label { color: var(--md-on-surface-medium); }
.mfield__control {
  position: relative; display: flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 10px;
  border: 1px solid var(--md-outline); border-radius: var(--md-shape-small);
  background: var(--md-surface);
  transition: border-color var(--md-dur-short) var(--md-ease-standard);
}
.mfield__control:focus-within { border-color: var(--md-primary); box-shadow: inset 0 0 0 1px var(--md-primary); }
.mfield select, .mfield input {
  appearance: none; -webkit-appearance: none;
  border: none; outline: none; background: transparent;
  font-family: var(--md-font); font-size: 14px; letter-spacing: .25px;
  color: var(--md-on-surface-high); height: 100%; width: 100%;
  cursor: pointer;
}
.mfield input { cursor: text; }
.mfield select:disabled { color: var(--md-on-surface-disabled); cursor: default; }
.mfield__caret { font-size: 22px; color: var(--md-on-surface-medium); pointer-events: none; }
.mfield__lead { font-size: 20px; color: var(--md-on-surface-medium); }
.mfield select { min-width: 150px; max-width: 280px; }
.mfield--search .mfield__control { min-width: 230px; }
.mfield--lang select { min-width: 96px; }

/* Switch row */
.switchrow { display: inline-flex; align-items: center; gap: 10px; padding-bottom: 8px; color: var(--md-on-surface-high); flex: none; white-space: nowrap; }
.mdc-switch input:checked ~ .mdc-switch__track { background: var(--primary-50); }
.mdc-switch input:checked ~ .mdc-switch__thumb { background: var(--md-primary); }
.mdc-switch:hover .mdc-switch__ripple::before { background: var(--md-primary); }

/* Reset button */
#reset-btn { margin-bottom: 2px; gap: 6px; }
#reset-btn .mi { font-size: 18px; }

/* ============================ Viewport / world ============================ */
#viewport {
  position: relative; flex: 1; overflow: hidden; cursor: grab;
  touch-action: none;   /* custom pan/pinch — block native gestures on the canvas */
  background:
    radial-gradient(circle at 1px 1px, var(--canvas-dot) 1px, transparent 0) 0 0 / 28px 28px,
    var(--canvas-bg);
}
.legend-body, #detail-body { touch-action: pan-y; }   /* but panels scroll natively */
#viewport.grabbing { cursor: grabbing; }
#world { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; }
#edges { position: absolute; top: 0; left: 0; overflow: visible; pointer-events: none; }
#nodes { position: absolute; top: 0; left: 0; }
#columns { position: absolute; top: 0; left: 0; }

.col-header {
  position: absolute; top: 16px; text-align: center;
  font-family: var(--md-font); font-weight: 500; font-size: 11px;
  letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--md-on-surface-medium);
}
.col-header::after {
  content: ""; display: block; height: 2px; margin-top: 8px; border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--md-divider), transparent);
}

/* ============================ Edges ============================ */
.edge { fill: none; stroke-width: 1.5; }
.edge-and { stroke: var(--edge-and); }
.edge-or { stroke: var(--edge-or); stroke-dasharray: 5 4; }
.arrow.edge-and { fill: var(--edge-and); stroke: none; }
.arrow.edge-or { fill: var(--edge-or); stroke: none; }
#edges path.edge-and { marker-end: url(#arrow-and); }
#edges path.edge-or { marker-end: url(#arrow-or); }

#world.filtering .edge.fade { opacity: .06; }
#world.filtering .edge.active { opacity: .9; stroke-width: 2; }
.edge.neighbor { stroke-width: 2.6 !important; opacity: 1 !important; }
.edge.neighbor.edge-and { stroke: var(--md-primary); }

/* ============================ Nodes (Material cards) ============================ */
.node {
  position: absolute; text-align: left; cursor: pointer;
  border: none; border-left: 4px solid var(--accent);
  background: var(--md-surface); border-radius: var(--md-shape-medium);
  box-shadow: var(--md-elev-01); overflow: hidden;
  display: flex; flex-direction: column; gap: 3px; padding: 8px 11px;
  /* position is driven by `transform`; only animate paint props so bulk fades
     don't trigger layout/opacity-transition storms. */
  transition: box-shadow var(--md-dur-short) var(--md-ease-standard);
  font-family: var(--md-font);
}
.node:hover { box-shadow: var(--md-elev-08); z-index: 5; }
.n-top { display: flex; align-items: baseline; gap: 6px; }
.n-code { font-size: 13px; font-weight: 500; letter-spacing: .1px; color: var(--md-on-surface-high); }
.cross { font-size: 10px; color: var(--md-on-surface-medium); }
.n-title {
  font-size: 11.5px; line-height: 1.3; letter-spacing: .2px; color: var(--md-on-surface-medium);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.n-tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }
.tag {
  font-size: 9px; font-weight: 500; padding: 2px 7px; border-radius: var(--md-shape-pill);
  letter-spacing: .4px; white-space: nowrap;
}
.tag-sub { background: var(--accent-bg); color: var(--md-on-surface-medium); }
.tag-foundation { background: var(--green-50); color: var(--green-800); }
.tag-interdisciplinary { background: var(--blue-50); color: var(--blue-800); }
.tag-disciplinary { background: var(--deep-purple-50); color: var(--deep-purple-800); }
.tag-elective { background: var(--grey-200); color: var(--grey-700); }

/* filtering states */
#world.filtering .node.dim { opacity: .22; }
#world.isolating .node.hide { display: none; }
#world.filtering .node.hl { opacity: 1; }
.node.member { box-shadow: 0 0 0 2px var(--accent), var(--md-elev-02); }
.node.selected { box-shadow: 0 0 0 3px var(--md-primary), var(--md-elev-12) !important; z-index: 8; opacity: 1 !important; }
.node.neighbor { box-shadow: 0 0 0 2px var(--md-primary) !important; opacity: 1 !important; }
.node.match { animation: pulse 1.1s var(--md-ease-standard) infinite; z-index: 7; opacity: 1 !important; }

/* hover-to-focus: opacity-only (no filter/transition) = one cheap repaint */
#world.hovering .node { opacity: .13 !important; }
#world.hovering .edge { opacity: .05 !important; }
#world.hovering .node.rel-hover { opacity: 1 !important; }
#world.hovering .node.hl-hover {
  opacity: 1 !important; z-index: 9;
  box-shadow: 0 0 0 3px var(--md-primary), var(--md-elev-12) !important;
}
/* highlighted lines must out-rank the `#world.hovering .edge` fade (which carries
   an id), so scope them under #world.hovering too */
#world.hovering .edge.edge-hover { opacity: 1 !important; stroke-width: 3; }
#world.hovering .edge.edge-hover.edge-and { stroke: var(--md-primary); }
#world.hovering .edge.edge-hover.edge-or { stroke: var(--md-secondary-variant); }
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 2px var(--md-secondary), var(--md-elev-01); }
  50% { box-shadow: 0 0 0 7px rgba(255,179,0,.25), var(--md-elev-01); }
}

/* ============================ Detail side sheet ============================ */
#detail {
  position: absolute; top: 0; right: 0; height: 100%; width: 372px;
  background: var(--md-surface); box-shadow: var(--md-elev-16);
  border-radius: var(--md-shape-large);
  transform: translateX(100%); transition: transform var(--md-dur-enter) var(--md-ease-standard);
  overflow: hidden; z-index: 25;
  display: flex; flex-direction: column;
}
#detail.open { transform: translateX(0); }
#detail-handle { flex: none; display: none; }   /* shown only as a bottom-sheet handle on mobile */
#detail-body { flex: 1 1 auto; overflow-y: auto; padding-bottom: 32px; }
#detail-close {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  color: var(--md-on-surface-medium);
}

/* Modal scrim — only used behind the mobile bottom sheet */
#scrim {
  position: absolute; inset: 0; background: var(--md-scrim);
  opacity: 0; visibility: hidden; z-index: 24;
  transition: opacity var(--md-dur-enter) var(--md-ease-standard), visibility var(--md-dur-enter);
}
#scrim.show { opacity: 1; visibility: visible; }
.d-head { padding: 24px 24px 18px; border-top: 4px solid var(--accent); border-bottom: 1px solid var(--md-divider); }
.d-code { font-size: 22px; font-weight: 500; letter-spacing: .15px; color: var(--md-on-surface-high); }
.d-title { font-size: 16px; line-height: 1.4; margin-top: 4px; color: var(--md-on-surface-high); }
.d-meta { font-size: 12px; letter-spacing: .4px; color: var(--md-on-surface-medium); margin-top: 10px; }
.d-section { padding: 16px 24px; border-bottom: 1px solid var(--md-divider); }
.d-section h4 {
  margin: 0 0 10px; font-size: 10px; font-weight: 400; text-transform: uppercase;
  letter-spacing: 1.5px; color: var(--md-on-surface-medium);
}
.d-section p { margin: 0; font-size: 14px; line-height: 1.55; letter-spacing: .25px; color: var(--md-on-surface-high); }
.d-pre {
  font-size: 13px; line-height: 1.5; letter-spacing: .25px;
  background: var(--amber-50); border: 1px solid var(--amber-200); color: var(--amber-900);
  padding: 10px 12px; border-radius: var(--md-shape-small);
}
.d-links { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.d-links a {
  font-size: 13px; color: var(--md-primary); text-decoration: none;
  padding: 7px 10px; background: var(--primary-12); border-radius: var(--md-shape-small);
  transition: background var(--md-dur-short) var(--md-ease-standard);
}
.d-links a:hover { background: var(--md-primary); color: var(--md-on-primary); }
.d-majors { margin: 0; padding-left: 18px; font-size: 13px; line-height: 1.9; color: var(--md-on-surface-high); }
.d-majors .tag { margin-left: 4px; }
.muted { color: var(--md-on-surface-disabled); }

/* ============================ Legend card ============================ */
#legend {
  position: absolute; left: 16px; bottom: 16px; width: 304px; max-height: 48%;
  box-shadow: var(--md-elev-08); display: flex; flex-direction: column; z-index: 20;
}
.legend-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--md-divider);
}
#legend-toggle { width: 36px; height: 36px; }
#legend-toggle .mi { font-size: 22px; transition: transform var(--md-dur-short) var(--md-ease-standard); }
.legend-body { padding: 12px 16px; overflow-y: auto; }
#legend.collapsed .legend-body { display: none; }
#legend.collapsed #legend-toggle .mi { transform: rotate(180deg); }
.lg-edges { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--md-divider); }
.lg-group { margin-bottom: 10px; }
.lg-title { font-size: 10px; font-weight: 500; letter-spacing: 1px; text-transform: uppercase; color: var(--md-on-surface-medium); margin-bottom: 6px; }
.lg-item { display: inline-flex; align-items: center; gap: 6px; color: var(--md-on-surface-medium); margin: 0 10px 6px 0; }
.lg-item i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.lg-edges .edge { stroke-width: 2; }

/* ============================ Hint (snackbar) ============================ */
#hint {
  position: absolute; right: 16px; bottom: 16px; z-index: 18;
  min-width: 0; min-height: 0; padding: 10px 16px;
}

/* ============================ Bottom-sheet handle ============================ */
#detail-handle { padding: 10px 0 6px; cursor: grab; touch-action: none; text-align: center; }
#detail-handle:active { cursor: grabbing; }
.detail-handle__bar {
  display: inline-block; width: 36px; height: 4px; border-radius: 2px;
  background: var(--md-on-surface-disabled);
}

/* ============================ Responsive / mobile ============================ */
@media (max-width: 1024px) {
  .mfield select { max-width: 200px; }
}

@media (max-width: 768px) {
  /* App bar — compact, drop the subtitle */
  #appbar { height: 56px; padding: 0 12px; gap: 10px; }
  .appbar__sub { display: none; }
  .mdc-appbar__title { font-size: 18px; }
  .appbar__stat { font-size: 11px; padding: 5px 10px; }

  /* Filter toggle becomes visible; toolbar can fold away */
  #filter-toggle { display: inline-flex; }
  #toolbar {
    overflow: hidden; max-height: 80vh;
    transition: max-height var(--md-dur-mobile) var(--md-ease-standard),
                padding var(--md-dur-mobile) var(--md-ease-standard);
  }
  #toolbar.collapsed { max-height: 0; padding-top: 0; padding-bottom: 0; box-shadow: none; }

  /* Toolbar — fields share rows, search spans full width */
  #toolbar { gap: 10px 10px; padding: 10px 12px; align-items: stretch; }
  .mfield { flex: 1 1 140px; }
  .mfield select { max-width: none; min-width: 0; width: 100%; }
  .mfield--search { flex: 1 1 100%; }
  .mfield--lang { flex: 1 1 120px; }
  .switchrow { flex: 1 1 auto; padding-bottom: 0; }
  .toolbar__spacer { display: none; }
  #reset-btn { flex: 0 0 auto; }

  /* Legend — narrower, sits clear of the sheet */
  #legend { width: auto; max-width: 64%; left: 12px; bottom: 12px; max-height: 40%; }
  #hint { display: none; }

  /* Detail → modal bottom sheet that slides up over everything (fixed so it
     escapes the #viewport overflow clip and the toolbar's stacking context). */
  #scrim { position: fixed; z-index: 45; }
  #detail {
    position: fixed; z-index: 46;
    top: auto; bottom: 0; left: 0; right: 0; width: 100%;
    height: var(--sheet-h, 60vh); max-height: 92vh;
    border-radius: 14px 14px 0 0;
    transform: translateY(100%);
    transition: transform var(--md-dur-enter) var(--md-ease-standard),
                height var(--md-dur-short) var(--md-ease-standard);
  }
  #detail.open { transform: translateY(0); }
  #detail-handle { display: block; }
  /* the subject colour lives on the grab handle here, so the header has no
     stray top stripe crowding the close button */
  .detail-handle__bar { background: var(--accent, var(--md-on-surface-disabled)); width: 44px; height: 5px; }
  .d-head { border-top: none; padding-top: 10px; }
  #detail-close { top: 4px; right: 6px; }
}

@media (max-width: 420px) {
  .mfield { flex: 1 1 100%; }            /* one field per row on small phones */
  .appbar__stat { display: none; }
}
