/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: #1a2233;
  --bg-hover: #1e293b;
  --border: #2a3a52;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --critical: #ef4444;
  --warning: #f59e0b;
  --success: #10b981;
  --purple: #8b5cf6;
  --cascade: #f97316;
  --completed: #22c55e;
  --font-mono: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* === Header === */
header {
  background: linear-gradient(135deg, var(--bg-secondary) 0%, #0f172a 100%);
  border-bottom: 1px solid var(--border);
  padding: 1.5rem 2rem;
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.header-left h1 {
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 0.25rem;
  font-family: var(--font-mono);
}

.header-right {
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.author {
  font-weight: 600;
  color: var(--accent);
}

.role {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* === Main === */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem 2rem 3rem;
}

/* === Dashboard Cards === */
.dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  transition: border-color 0.2s;
}

.card:hover {
  border-color: var(--accent);
}

.card-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.card-value {
  font-size: 1.3rem;
  font-weight: 700;
  font-family: var(--font-mono);
}

.status-on-track { color: var(--success); }
.status-at-risk { color: var(--warning); }
.status-delayed { color: var(--critical); }
.variance-ok { color: var(--success); }
.variance-warn { color: var(--warning); }
.variance-bad { color: var(--critical); }

/* === Controls === */
.controls {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.btn {
  padding: 0.5rem 1.25rem;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font-sans);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

.btn-danger {
  background: var(--critical);
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
}

.instructions {
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.instructions .icon {
  font-size: 1.1rem;
  color: var(--accent);
}

/* === Gantt Chart === */
.gantt-section {
  margin-bottom: 2rem;
}

.gantt-section h2, .risk-section h2, .impact-section h2 {
  font-size: 1.1rem;
  margin-bottom: 1rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.gantt-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
}

.gantt-header {
  display: flex;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
  z-index: 2;
}

.gantt-label-col {
  min-width: 260px;
  max-width: 260px;
  padding: 0.6rem 1rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
  border-right: 1px solid var(--border);
}

.gantt-timeline {
  flex: 1;
  display: flex;
  min-width: 700px;
}

.gantt-week {
  flex: 1;
  text-align: center;
  padding: 0.6rem 0.25rem;
  font-size: 0.65rem;
  color: var(--text-muted);
  border-right: 1px solid rgba(42, 58, 82, 0.5);
  font-family: var(--font-mono);
}

.gantt-week.current {
  background: rgba(59, 130, 246, 0.08);
  color: var(--accent);
  font-weight: 600;
}

.gantt-body {
  position: relative;
}

.gantt-row {
  display: flex;
  border-bottom: 1px solid rgba(42, 58, 82, 0.4);
  transition: background 0.15s;
}

.gantt-row:hover {
  background: rgba(59, 130, 246, 0.04);
}

.gantt-row-label {
  min-width: 260px;
  max-width: 260px;
  padding: 0.55rem 1rem;
  font-size: 0.8rem;
  border-right: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.gantt-row-label .milestone-id {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  min-width: 28px;
}

.gantt-row-label .milestone-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gantt-row-label .phase-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.gantt-row-timeline {
  flex: 1;
  position: relative;
  min-width: 700px;
  min-height: 32px;
}

.gantt-bar-container {
  position: absolute;
  top: 6px;
  height: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.gantt-bar {
  width: 100%;
  height: 100%;
  border-radius: 3px;
  position: relative;
  transition: all 0.3s ease;
}

.gantt-bar.critical {
  background: linear-gradient(90deg, var(--critical), #b91c1c);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.3);
}

.gantt-bar.non-critical {
  background: linear-gradient(90deg, var(--accent), #1d4ed8);
  opacity: 0.7;
}

.gantt-bar.completed {
  background: linear-gradient(90deg, var(--completed), #16a34a);
  opacity: 0.6;
}

.gantt-bar.delayed {
  background: linear-gradient(90deg, var(--warning), #d97706);
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.4);
  animation: pulse-warn 2s infinite;
}

.gantt-bar.cascade {
  background: linear-gradient(90deg, var(--cascade), #ea580c);
  box-shadow: 0 0 10px rgba(249, 115, 22, 0.3);
  animation: pulse-cascade 2s infinite;
}

.gantt-bar-container:hover .gantt-bar {
  filter: brightness(1.2);
  transform: scaleY(1.3);
}

.gantt-bar-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  font-size: 0.75rem;
  white-space: nowrap;
  z-index: 10;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.gantt-bar-container:hover .gantt-bar-tooltip {
  display: block;
}

.gantt-bar-tooltip .tt-name {
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.gantt-bar-tooltip .tt-detail {
  color: var(--text-secondary);
}

/* Dependency arrows (drawn via SVG overlay) */
.gantt-svg-overlay {
  position: absolute;
  top: 0;
  left: 260px;
  pointer-events: none;
  z-index: 1;
}

/* Today marker — single overlay on gantt body */
.today-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent);
  z-index: 3;
  opacity: 0.6;
  pointer-events: none;
}

.today-marker::before {
  content: "TODAY";
  position: absolute;
  top: 4px;
  left: -16px;
  font-size: 0.55rem;
  font-family: var(--font-mono);
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.05em;
  writing-mode: vertical-rl;
  text-orientation: mixed;
}

@keyframes pulse-warn {
  0%, 100% { box-shadow: 0 0 8px rgba(245, 158, 11, 0.3); }
  50% { box-shadow: 0 0 16px rgba(245, 158, 11, 0.6); }
}

@keyframes pulse-cascade {
  0%, 100% { box-shadow: 0 0 8px rgba(249, 115, 22, 0.2); }
  50% { box-shadow: 0 0 14px rgba(249, 115, 22, 0.5); }
}

/* Legend */
.legend {
  display: flex;
  gap: 1.5rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.legend-color {
  width: 14px;
  height: 8px;
  border-radius: 2px;
}

.legend-color.critical { background: var(--critical); }
.legend-color.non-critical { background: var(--accent); opacity: 0.7; }
.legend-color.completed { background: var(--completed); opacity: 0.6; }
.legend-color.delayed { background: var(--warning); }
.legend-color.cascade { background: var(--cascade); }

/* === Risk Register Table === */
.risk-section {
  margin-bottom: 2rem;
}

.risk-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  font-size: 0.8rem;
}

.risk-table thead {
  background: var(--bg-secondary);
}

.risk-table th {
  padding: 0.65rem 0.75rem;
  text-align: left;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

.risk-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid rgba(42, 58, 82, 0.4);
  vertical-align: top;
}

.risk-table tbody tr {
  transition: background 0.15s;
}

.risk-table tbody tr:hover {
  background: var(--bg-hover);
}

.risk-table tbody tr.risk-highlighted {
  background: rgba(249, 115, 22, 0.1);
  border-left: 3px solid var(--cascade);
}

.risk-id {
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-size: 0.75rem;
}

.risk-score {
  font-weight: 700;
  font-family: var(--font-mono);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  display: inline-block;
  font-size: 0.8rem;
}

.risk-score.high {
  background: rgba(239, 68, 68, 0.15);
  color: var(--critical);
}

.risk-score.medium {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
}

.risk-score.low {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.risk-status {
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  border-radius: 10px;
  font-weight: 600;
}

.risk-status.open {
  background: rgba(239, 68, 68, 0.12);
  color: var(--critical);
}

.risk-status.mitigated {
  background: rgba(34, 197, 94, 0.12);
  color: var(--success);
}

.risk-category {
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: rgba(59, 130, 246, 0.1);
  color: var(--accent);
  white-space: nowrap;
}

/* Likelihood/Impact bars */
.rating-bar {
  display: flex;
  gap: 2px;
}

.rating-pip {
  width: 8px;
  height: 14px;
  border-radius: 2px;
  background: var(--border);
}

.rating-pip.filled { background: var(--warning); }
.rating-pip.filled.high-fill { background: var(--critical); }

/* === Modal === */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.modal.hidden { display: none; }

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem 2rem;
  min-width: 360px;
  max-width: 460px;
}

.modal-content h3 {
  margin-bottom: 0.75rem;
  font-size: 1.1rem;
}

.modal-content p {
  color: var(--text-secondary);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.modal-field {
  margin-bottom: 1rem;
}

.modal-field label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.modal-field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.modal-field select {
  width: 100%;
  padding: 0.4rem 0.6rem;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
}

.modal-field span {
  font-family: var(--font-mono);
  color: var(--accent);
  font-weight: 600;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

/* === Impact Section === */
.impact-section {
  margin-bottom: 2rem;
}

.impact-section.hidden { display: none; }

.impact-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 0.75rem;
}

.impact-card h4 {
  font-size: 0.85rem;
  color: var(--warning);
  margin-bottom: 0.5rem;
}

.impact-card ul {
  list-style: none;
  padding: 0;
}

.impact-card li {
  padding: 0.3rem 0;
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.impact-card li .impact-arrow {
  color: var(--cascade);
  font-weight: bold;
}

.impact-summary {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-top: 1rem;
}

.impact-summary p {
  font-size: 0.85rem;
  margin-bottom: 0.4rem;
}

.impact-summary .impact-big {
  font-size: 1.4rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--critical);
}

/* === Footer === */
footer {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}

footer a {
  color: var(--accent);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* === Responsive === */
@media (max-width: 768px) {
  header { padding: 1rem; }
  main { padding: 1rem; }
  .dashboard { grid-template-columns: repeat(2, 1fr); }
  .gantt-label-col, .gantt-row-label {
    min-width: 180px;
    max-width: 180px;
  }
  .header-content { flex-direction: column; align-items: flex-start; }
  .header-right { text-align: left; }
}
