/* ═══════════════════════════════════════════════
   PUG Tracker — Design System v2

   Brand: Beletage teal #0BA49A
   Font: Inter — one family, weight hierarchy only
   Modes: light (warm stone) / dark (deep charcoal)
   ═══════════════════════════════════════════════ */

/* ─── Light Theme ─── */
:root, [data-theme="light"] {
  --bg-base: #faf8f5;
  --bg-elevated: #ffffff;
  --bg-surface: #f2efeb;
  --bg-surface-hover: #ebe7e2;
  --bg-overlay: rgba(255, 255, 255, 0.8);

  --text-primary: #1a1a1d;
  --text-secondary: #4a4a52;
  --text-tertiary: #8a8a95;
  --text-inverse: #ffffff;

  --border: rgba(0, 0, 0, 0.07);
  --border-strong: rgba(0, 0, 0, 0.12);

  --brand: #0BA49A;
  --brand-soft: rgba(11, 164, 154, 0.10);
  --brand-hover: #099e94;

  /* Status — refined, muted for light mode */
  --st-approved: #2d8a5e;
  --st-approved-bg: #e6f4ed;
  --st-conditional: #6aab3d;
  --st-conditional-bg: #f0f7e4;
  --st-action: #d44a2e;
  --st-action-bg: #fde8e4;
  --st-study: #7c5cbf;
  --st-study-bg: #f0ebfa;
  --st-waiting: #8a8a95;
  --st-waiting-bg: #f0f0f3;
  --st-rejected: #b52828;

  /* Swim bands */
  --band-0: rgba(212, 74, 46, 0.04);
  --band-1: rgba(124, 92, 191, 0.04);
  --band-2: rgba(196, 138, 26, 0.04);
  --band-3: rgba(45, 138, 94, 0.03);
  --band-border: rgba(0, 0, 0, 0.04);

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.06), 0 8px 24px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.08), 0 16px 40px rgba(0,0,0,0.10);
  --shadow-panel: -2px 0 16px rgba(0,0,0,0.06), -8px 0 40px rgba(0,0,0,0.08);

  --node-bg: #ffffff;
  --node-bg-opacity: 0.85;

  --minimap-bg: rgba(255, 255, 255, 0.85);
  --minimap-viewport-border: var(--brand);
  --minimap-viewport-bg: rgba(11, 164, 154, 0.06);
}

/* ─── Dark Theme ─── */
[data-theme="dark"] {
  --bg-base: #121214;
  --bg-elevated: #1c1c20;
  --bg-surface: #232328;
  --bg-surface-hover: #2c2c32;
  --bg-overlay: rgba(28, 28, 32, 0.85);

  --text-primary: #e8e8ec;
  --text-secondary: #a0a0aa;
  --text-tertiary: #6a6a75;
  --text-inverse: #121214;

  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.12);

  --brand: #1cc4b8;
  --brand-soft: rgba(28, 196, 184, 0.12);
  --brand-hover: #2ad4c8;

  --st-approved: #3dbd7a;
  --st-approved-bg: rgba(61, 189, 122, 0.12);
  --st-conditional: #8ecc44;
  --st-conditional-bg: rgba(142, 204, 68, 0.12);
  --st-action: #f06848;
  --st-action-bg: rgba(240, 104, 72, 0.12);
  --st-study: #a78bef;
  --st-study-bg: rgba(167, 139, 239, 0.12);
  --st-waiting: #6a6a75;
  --st-waiting-bg: rgba(106, 106, 117, 0.12);
  --st-rejected: #e04040;

  --band-0: rgba(240, 104, 72, 0.05);
  --band-1: rgba(167, 139, 239, 0.05);
  --band-2: rgba(224, 168, 50, 0.05);
  --band-3: rgba(61, 189, 122, 0.04);
  --band-border: rgba(255, 255, 255, 0.04);

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.2);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.3), 0 16px 40px rgba(0,0,0,0.25);
  --shadow-panel: -2px 0 16px rgba(0,0,0,0.3), -8px 0 40px rgba(0,0,0,0.25);

  --node-bg: #232328;
  --node-bg-opacity: 0.9;

  --minimap-bg: rgba(28, 28, 32, 0.85);
  --minimap-viewport-border: var(--brand);
  --minimap-viewport-bg: rgba(28, 196, 184, 0.08);
}

/* ─── Reset ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-base);
  transition: background 0.3s ease, color 0.3s ease;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── Header ─── */
#header {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  z-index: 100;
  position: relative;
  transition: background 0.3s ease;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.logo-img {
  height: 22px;
  width: auto;
  flex-shrink: 0;
}
.header-divider {
  width: 1px;
  height: 20px;
  background: var(--border-strong);
  flex-shrink: 0;
}
#project-selector {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 15px;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  padding-right: 18px;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%238a8a95' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right center;
}
.header-center {
  font-size: 12px;
  color: var(--text-tertiary);
  font-weight: 500;
}
.header-right {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* ─── Score Band ─── */
#score-band {
  height: 36px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 10px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  transition: background 0.3s ease;
}
.score-bar-container {
  flex: 1;
  display: flex;
  border-radius: 5px;
  overflow: hidden;
  height: 8px;
  background: var(--bg-surface);
}
.score-segment {
  transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
.score-segment:not(:last-child) {
  border-right: 1px solid var(--bg-elevated);
}
.score-pct {
  font-weight: 700;
  color: var(--brand);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.score-legend {
  display: flex;
  gap: 10px;
  font-size: 11px;
  color: var(--text-tertiary);
  font-weight: 500;
}
.score-legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: default;
}
.score-legend-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ─── Graph Container ─── */
#graph-container {
  position: relative;
  height: calc(100vh - 48px - 36px);
  overflow: hidden;
  cursor: grab;
  background: var(--bg-base);
  transition: background 0.3s ease;
}
#graph-container:active { cursor: grabbing; }
#flow-map {
  width: 100%;
  height: 100%;
  display: block;
}

/* ─── SVG Graph Elements ─── */
.swim-band { transition: fill 0.3s ease; }
.swim-band-border {
  stroke: var(--band-border);
  stroke-width: 1;
  stroke-dasharray: 6 4;
}
.swim-label {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  fill: var(--text-tertiary);
  opacity: 0.5;
  user-select: none;
}

/* Edges */
.edge-path {
  fill: none;
  stroke-linecap: round;
  transition: stroke 0.3s, stroke-width 0.3s, opacity 0.3s;
}
.edge-path.resolved {
  stroke: var(--text-tertiary);
  stroke-width: 0.8;
  opacity: 0.2;
}
.edge-path.active {
  stroke: var(--text-tertiary);
  stroke-width: 1.2;
  opacity: 0.35;
}

/* Arrowhead markers */
.arrowhead-resolved { fill: var(--text-tertiary); opacity: 0.2; }
.arrowhead-active { fill: var(--text-tertiary); opacity: 0.35; }

/* Nodes (pill shape) */
.permit-node { cursor: pointer; }
.permit-node:hover .node-ring { stroke-width: 2 !important; }
.node-bg { transition: fill 0.2s ease; }
.node-fill { transition: fill 0.2s ease; }
.node-ring { transition: all 0.2s ease; }
.node-label {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 9.5px;
  font-weight: 600;
  fill: var(--text-primary);
  text-anchor: middle;
  pointer-events: none;
  user-select: none;
}
.node-badge {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 7.5px;
  font-weight: 700;
  fill: var(--text-tertiary);
  pointer-events: none;
  user-select: none;
}
.node-days {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 8px;
  font-weight: 700;
  pointer-events: none;
  user-select: none;
  font-variant-numeric: tabular-nums;
}

/* Done nodes recede */
.permit-node.done { opacity: 0.4; }
.permit-node.done:hover { opacity: 0.65; }

/* Urgency pulse */
.permit-node.urgent .node-ring {
  animation: urgency-pulse 2.5s ease-in-out infinite;
}
.permit-node.very-urgent .node-ring {
  animation: urgency-pulse-intense 1.5s ease-in-out infinite;
}
@keyframes urgency-pulse {
  0%, 100% { stroke-opacity: 1; }
  50% { stroke-opacity: 0.35; }
}
@keyframes urgency-pulse-intense {
  0%, 100% { stroke-opacity: 1; }
  50% { stroke-opacity: 0.2; }
}

.permit-node.selected .node-ring {
  stroke-width: 2.5 !important;
}

/* Critical blocker — animated edges + glow on node */
.edge-path.critical {
  stroke: var(--brand);
  stroke-width: 2.5;
  opacity: 0.85;
  stroke-dasharray: 8 4;
  animation: critical-flow 1s linear infinite;
}
@keyframes critical-flow {
  to { stroke-dashoffset: -12; }
}
.permit-node.critical .node-ring {
  stroke-width: 2.5 !important;
  filter: drop-shadow(0 0 4px var(--brand));
  animation: critical-glow 2s ease-in-out infinite;
}
@keyframes critical-glow {
  0%, 100% { filter: drop-shadow(0 0 3px var(--brand)); }
  50% { filter: drop-shadow(0 0 8px var(--brand)); }
}

/* Dragging */
.permit-node.dragging {
  cursor: grabbing !important;
  opacity: 0.85;
}
.permit-node.dragging .node-ring {
  stroke-dasharray: 4 2;
}

/* Gate nodes */
.gate-label {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 10px;
  font-weight: 600;
  fill: var(--text-secondary);
  text-anchor: middle;
  user-select: none;
}

/* ─── Tooltip ─── */
.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 10px 14px;
  box-shadow: var(--shadow-md);
  z-index: 300;
  max-width: 280px;
  transition: opacity 0.12s ease;
}
.tooltip.hidden { opacity: 0; display: none; }
.tooltip-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 3px;
}
.tooltip-status {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 2px;
}
.tooltip-detail {
  font-size: 11px;
  color: var(--text-tertiary);
}

/* ─── Minimap ─── */
#minimap {
  position: absolute;
  bottom: 12px;
  right: 12px;
  width: 160px;
  height: 100px;
  background: var(--minimap-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  z-index: 50;
}
#minimap-svg { width: 100%; height: 100%; display: block; }
#minimap-viewport {
  position: absolute;
  border: 1.5px solid var(--minimap-viewport-border);
  border-radius: 2px;
  background: var(--minimap-viewport-bg);
  pointer-events: none;
}

/* ─── Detail Panel ─── */
#detail-panel {
  position: fixed;
  right: 0;
  top: 0;
  width: 380px;
  height: 100vh;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-panel);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), background 0.3s ease;
  z-index: 200;
  overflow-y: auto;
  overflow-x: hidden;
}
#detail-panel.open { transform: translateX(0); }
#detail-panel.hidden { display: none; }
#panel-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  border: none;
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
  color: var(--text-tertiary);
  z-index: 1;
  padding: 0;
}
#panel-close:hover { background: var(--bg-surface-hover); }

/* Panel layout */
.panel-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.panel-sort-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--brand);
  margin-bottom: 4px;
}
.panel-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.35;
}
.panel-section {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.panel-section:last-child { border-bottom: none; }
.panel-section-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 8px;
}
.panel-field {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 3px 0;
  font-size: 13px;
}
.panel-field-label { color: var(--text-tertiary); font-weight: 500; }
.panel-field-value { color: var(--text-primary); font-weight: 500; text-align: right; max-width: 55%; }
.panel-notes {
  background: var(--bg-surface);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-top: 6px;
}
.panel-study-card {
  background: var(--st-study-bg);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  margin-top: 6px;
  color: var(--text-secondary);
}
.panel-study-card strong { color: var(--st-study); }

/* Status badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
}
.status-badge .dot { width: 6px; height: 6px; border-radius: 50%; }
.status-badge.approved { background: var(--st-approved-bg); color: var(--st-approved); }
.status-badge.approved .dot { background: var(--st-approved); }
.status-badge.conditional { background: var(--st-conditional-bg); color: var(--st-conditional); }
.status-badge.conditional .dot { background: var(--st-conditional); }
.status-badge.action { background: var(--st-action-bg); color: var(--st-action); }
.status-badge.action .dot { background: var(--st-action); }
.status-badge.study { background: var(--st-study-bg); color: var(--st-study); }
.status-badge.study .dot { background: var(--st-study); }
.status-badge.waiting { background: var(--st-waiting-bg); color: var(--st-waiting); }
.status-badge.waiting .dot { background: var(--st-waiting); }

/* ─── Buttons ─── */
button {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  cursor: pointer;
  transition: all 0.12s ease;
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
button:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-strong);
}
button.primary {
  background: var(--brand);
  color: var(--text-inverse);
  border-color: transparent;
}
button.primary:hover { background: var(--brand-hover); }
.icon-btn {
  padding: 6px;
  border: 1px solid var(--border);
}

/* ─── Form controls for inline editing ─── */
.edit-select {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
  width: 100%;
}
.edit-select:focus { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.edit-textarea {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 12px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-primary);
  outline: none;
  width: 100%;
  resize: vertical;
  min-height: 60px;
  line-height: 1.5;
}
.edit-textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.edit-group {
  margin-bottom: 10px;
}
.edit-group label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* ─── Responsive ─── */
@media (max-width: 768px) {
  #detail-panel { width: 100%; }
  #minimap { display: none; }
  .header-center { display: none; }
  .score-legend { display: none; }
}
