*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:             #f1f5f9;
  --surface:        #ffffff;
  --border:         #e2e8f0;
  --border-focus:   #3b82f6;
  --text-primary:   #0f172a;
  --text-secondary: #475569;
  --text-muted:     #94a3b8;
  --brand:          #1e40af;
  --accent:         #2563eb;
  --accent-hover:   #1d4ed8;
  --dirty:          #d97706;
  --dirty-hover:    #b45309;
  --danger:         #dc2626;
  --danger-light:   #fff5f5;
  --danger-border:  #fca5a5;
  --radius:         8px;
  --shadow-sm:      0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:      0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
}

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
header {
  background: #0f172a;
  border-bottom: 3px solid var(--accent);
  padding: 0 32px;
  height: 56px;
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  align-items: baseline;
  gap: 14px;
}
header h1 {
  color: #f8fafc;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.header-badge {
  background: rgba(37,99,235,.25);
  color: #93c5fd;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: uppercase;
}

/* ── Layout ─────────────────────────────────────────────────────────────── */
main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 24px 64px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ── Section cards ──────────────────────────────────────────────────────── */
section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 24px 28px;
}

.section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-secondary);
  padding-bottom: 14px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

/* ── Utility ────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Task estimates section ─────────────────────────────────────────────── */
.task-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.task-section-head .section-title {
  padding-bottom: 0;
  margin-bottom: 0;
  border-bottom: none;
}

.section-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.unit-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}
.unit-selector label { font-weight: 500; }
.unit-selector select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 28px 5px 10px;
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text-primary);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2394a3b8' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}
.unit-selector select:focus { outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }

/* Project start date picker */
.start-date-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}
.start-date-wrap label { font-weight: 500; }
.start-date-wrap input[type="date"] {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text-primary);
  cursor: pointer;
}
.start-date-wrap input[type="date"]:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

/* Project name field */
.project-name-wrap {
  margin-bottom: 20px;
}
.project-name-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.project-name-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.project-name-input::placeholder {
  color: var(--text-primary);
}
.project-name-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

/* Task table */
.table-wrapper { overflow-x: auto; margin-bottom: 14px; }

table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 10px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
thead th:first-child  { padding-left: 0; width: 36px; }
thead th:last-child   { padding-right: 0; text-align: right; }

tbody tr { border-bottom: 1px solid var(--bg); }
tbody tr:last-child   { border-bottom: none; }

tbody td { padding: 5px 10px; vertical-align: middle; }
tbody td:first-child  { padding-left: 0; color: var(--text-muted); font-size: 13px; font-variant-numeric: tabular-nums; font-weight: 500; width: 36px; }
tbody td:last-child   { padding-right: 0; text-align: right; color: var(--text-secondary); font-size: 13px; font-variant-numeric: tabular-nums; }

tbody td input[type="number"],
tbody td input[type="text"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
tbody td input[type="number"] {
  min-width: 80px;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
tbody td input[type="text"] {
  min-width: 120px;
}
tbody td input[type="number"]::-webkit-outer-spin-button,
tbody td input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
tbody td input[type="number"]:focus,
tbody td input[type="text"]:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
tbody td input[type="number"].invalid {
  border-color: var(--danger);
  background: var(--danger-light);
}
tbody td input[type="number"].invalid:focus {
  box-shadow: 0 0 0 3px rgba(220,38,38,.1);
}

/* Table controls */
.table-controls { display: flex; gap: 8px; }
.btn-table {
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  user-select: none;
}
.btn-table:hover:not(:disabled) { background: var(--bg); border-color: #cbd5e1; }
.btn-table:disabled { opacity: 0.38; cursor: not-allowed; }

.btn-run {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 9px 28px;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background .15s, transform .1s, box-shadow .15s;
  box-shadow: 0 1px 3px rgba(37,99,235,.35);
}
.btn-run:hover  { background: var(--accent-hover); box-shadow: 0 2px 6px rgba(37,99,235,.4); }
.btn-run:active { transform: scale(.98); }
.btn-run.dirty  { background: var(--dirty); box-shadow: 0 1px 3px rgba(217,119,6,.35); }
.btn-run.dirty:hover { background: var(--dirty-hover); }

.validation-errors {
  margin-top: 14px;
  padding: 10px 14px;
  background: var(--danger-light);
  border: 1px solid var(--danger-border);
  border-radius: 6px;
  color: #b91c1c;
  font-size: 13px;
  line-height: 1.7;
}

/* ── Percentile cards ───────────────────────────────────────────────────── */
.metric-cards {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.metric-card {
  flex: 1 1 130px;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 110px;
}
.card-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.card-value {
  display: flex;
  align-items: baseline;
  gap: 5px;
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: -0.02em;
}
.card-value::after {
  content: attr(data-unit);
  font-size: 13px;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 0;
}
/* Unit sub-label always hidden — unit is always shown inline via ::after */
.unit-inline {
  display: none;
}
.card-date {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}
.gantt-card .card-date {
  color: var(--danger);
  font-weight: 500;
}

/* ── Calendar active mode (class added by app.js when start date is set) ──── */
/* Calendar date line: slightly more contrast than var(--text-muted) */
.cal-active .card-date {
  color: var(--text-secondary);
}
/* Gantt card date keeps its red colour (higher specificity overrides above) */
.cal-active .gantt-card .card-date {
  color: var(--danger);
  font-weight: 500;
}

.card-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 5px;
  font-variant-numeric: tabular-nums;
}

/* Gantt card — red warning (req 6.4.3: red border + red sub-label) */
.gantt-card {
  border: 2px solid var(--danger);
  background: var(--danger-light);
}
.gantt-card .card-label { color: #b91c1c; }
.gantt-card .card-sub   { color: var(--danger); font-weight: 600; }

/* Percentile card value colour coding (req 6.1.3) — ID selectors override
   .card-value default and .gantt-card .card-value for the Gantt entry */
#val-gantt { color: #E24B4A; }
#val-p50   { color: #1D9E75; }
#val-p80   { color: #534AB7; }
#val-p90   { color: #BA7517; }
#val-p95   { color: #A32D2D; }

/* ── Chart sections ─────────────────────────────────────────────────────── */
.chart-wrap {
  position: relative;
  width: 100%;
}
.chart-wrap.histogram-wrap { height: 340px; }

/* ── Chart placeholder (req 6.5.1) ─────────────────────────────────────── */
.chart-placeholder {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: var(--bg);
}

/* ── Analytical cross-check ─────────────────────────────────────────────── */
.cc-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.cc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 14px;
  background: var(--bg);
  border-radius: 6px;
}
.cc-label { font-size: 13px; color: var(--text-secondary); }
.cc-value { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text-primary); }
.cc-ok   { color: #16a34a; }
.cc-err  { color: var(--danger); }

/* ── Performance footer ─────────────────────────────────────────────────── */
.perf-line {
  text-align: right;
  font-size: 11px;
  color: var(--text-muted);
  padding: 4px 2px 0;
  font-variant-numeric: tabular-nums;
}

/* ── Hero (req 6.6) ─────────────────────────────────────────────────────── */
.hero {
  padding: 20px 0 8px;
  text-align: center;
}
.hero-headline {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin-bottom: 10px;
}
.hero-accent { color: #534AB7; }
.hero-subtitle {
  font-size: 15px;
  color: var(--text-secondary);
  font-weight: 400;
}

/* ── Feedback prompt card (req 6.7) ─────────────────────────────────────── */
.feedback-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 24px 20px;
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-left: 4px solid #534AB7;
  border-radius: var(--radius);
  opacity: 0;
  transition: opacity 0.5s ease;
}
.feedback-card--visible { opacity: 1; }
.feedback-text {
  flex: 1;
  font-size: 16px;
  color: var(--text-primary);
  font-weight: 500;
}
.feedback-btn {
  padding: 7px 18px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s;
}
.feedback-btn:hover { background: var(--accent-hover); }

/* ── Risk Assessment (V2) ───────────────────────────────────────────────── */
.risk-body {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}
.risk-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #fff;
  white-space: nowrap;
  flex-shrink: 0;
  margin-top: 3px;
}
.risk-badge--at-risk         { background: #E24B4A; }
.risk-badge--borderline      { background: #EEEDFE; color: #3C3489; }
.risk-badge--well-constructed { background: #1D9E75; }
.risk-narrative {
  font-size: 15px;
  line-height: 1.65;
  color: var(--text-primary);
}

/* ── Responsive tweaks ──────────────────────────────────────────────────── */
@media (max-width: 640px) {
  header { padding: 0 16px; }
  main   { padding: 20px 16px 48px; }
  section { padding: 18px 16px; }
  .metric-card .card-value { font-size: 22px; }
  .cc-grid { grid-template-columns: 1fr; }
  .task-section-head { flex-wrap: wrap; gap: 10px; }
  .section-controls  { gap: 10px; }
}
