:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --border: #e3e2de;
  --grid: #ecebe7;
  --axis: #c9c8c2;
  --hover: rgba(42, 120, 214, 0.08);
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --good: #11804a;
  --good-bg: #e3f4ea;
  --warning: #9a5b00;
  --warning-bg: #fdf0d6;
  --critical: #c0322f;
  --critical-bg: #fbe5e4;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 2px 8px rgba(0, 0, 0, 0.04);
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

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

h1,
h2 {
  margin: 0;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

.muted {
  color: var(--text-muted);
}
.small {
  font-size: 12px;
}
.strong {
  font-weight: 600;
}
.text-critical {
  color: var(--critical);
  font-weight: 600;
}

/* ---------- Buttons & fields ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
}
.btn:hover:not(:disabled) {
  border-color: var(--axis);
}
.btn:disabled {
  opacity: 0.6;
  cursor: default;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn.primary:hover:not(:disabled) {
  filter: brightness(1.08);
}
.btn.ghost {
  background: transparent;
}
.btn.block {
  width: 100%;
  padding: 11px 14px;
}
.link-btn {
  border: 0;
  background: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0 4px;
  font-weight: 500;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}
.field > span {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}
.field input,
.field select,
.table-search {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 9px 11px;
  min-width: 0;
}
.field input:focus,
.field select:focus,
.table-search:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
.field.inline {
  margin-bottom: 0;
}

.alert {
  background: var(--critical-bg);
  color: var(--critical);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 16px;
  font-weight: 500;
}

/* ---------- Login ---------- */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.login-card h1 {
  font-size: 20px;
}
.login-card .brand {
  margin-bottom: 28px;
}
.login-card p.small {
  margin: 20px 0 0;
  text-align: center;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand p {
  margin: 2px 0 0;
}
.password-row {
  position: relative;
  display: flex;
}
.password-row input {
  flex: 1;
  padding-right: 60px;
}
.password-row .link-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
}

/* ---------- App shell ---------- */
.shell {
  display: flex;
  min-height: 100vh;
}
.shell-main {
  flex: 1;
  min-width: 0;
}
.sidebar {
  width: 248px;
  flex: none;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  overflow-y: auto;
}
.side-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 20px;
}
.side-brand strong {
  font-size: 15px;
}
.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}
.side-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 16px 10px 6px;
}
.side-label:first-child {
  padding-top: 0;
}
.side-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
}
.side-link:hover {
  background: var(--hover);
  color: var(--text-primary);
}
.side-link.active {
  background: var(--hover);
  color: var(--accent);
  font-weight: 600;
}
.side-icon {
  flex: none;
}
.side-user {
  display: flex;
  align-items: center;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding: 14px 6px 0;
  margin-top: 12px;
}
.side-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  font-weight: 600;
  flex: none;
}
.side-user-name {
  flex: 1;
  min-width: 0;
}
.side-user-name > div {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.icon-btn {
  border: 0;
  background: none;
  color: var(--text-secondary);
  padding: 6px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
}
.icon-btn:hover {
  background: var(--hover);
  color: var(--text-primary);
}
.side-close,
.mobile-bar,
.side-scrim {
  display: none;
}
.content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 24px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.filters .grow {
  flex: 1 1 200px;
}
.status-line {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: -4px;
}
.loading-note {
  color: var(--accent);
}

/* ---------- KPIs ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.kpi-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}
.kpi-value {
  font-size: 28px;
  font-weight: 650;
  letter-spacing: -0.02em;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.kpi-unit {
  font-size: 14px;
  color: var(--text-muted);
  margin-left: 2px;
}
.kpi-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.kpi-hint.critical {
  color: var(--critical);
  font-weight: 600;
}
.kpi-hint.warning {
  color: var(--warning);
}

/* ---------- Cards & charts ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  min-width: 0;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.card-header h2 {
  font-size: 15px;
  font-weight: 600;
}
.card-header p {
  margin: 2px 0 0;
}
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.legend {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--text-secondary);
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
  flex: none;
}

.chart-tooltip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  font-size: 12px;
  min-width: 160px;
}
.chart-tooltip-title {
  font-weight: 600;
  margin-bottom: 4px;
}
.chart-tooltip-row {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 8px;
  align-items: center;
  color: var(--text-secondary);
}
.chart-tooltip-row strong {
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.chart-tooltip-row.total {
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 4px;
}
.recharts-wrapper svg {
  overflow: visible;
}

/* ---------- Tables ---------- */
.table-search {
  width: 100%;
  max-width: 260px;
  margin-bottom: 10px;
}
.table-wrap {
  overflow-x: auto;
  max-height: 520px;
  overflow-y: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
th {
  position: sticky;
  top: 0;
  background: var(--surface);
  text-align: left;
  border-bottom: 1px solid var(--border);
  padding: 0;
  white-space: nowrap;
}
th button {
  border: 0;
  background: none;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  width: 100%;
  text-align: inherit;
}
th.num {
  text-align: right;
}
td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--grid);
  vertical-align: middle;
}
td.num {
  text-align: right;
  white-space: nowrap;
}
tbody tr:hover {
  background: var(--hover);
}
.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 24px;
}

.progress-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 120px;
}
.progress {
  height: 6px;
  background: var(--grid);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--series-1);
  border-radius: 3px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.pill.good {
  color: var(--good);
  background: var(--good-bg);
}
.pill.warning {
  color: var(--warning);
  background: var(--warning-bg);
}
.pill.critical {
  color: var(--critical);
  background: var(--critical-bg);
}
.pill.neutral {
  color: var(--text-muted);
  background: var(--grid);
}

/* ---------- Portfolio tracker ---------- */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}
.page-head h1 {
  font-size: 22px;
  letter-spacing: -0.01em;
}
.page-head p {
  margin: 4px 0 0;
}
.page-head a,
.content a {
  color: var(--accent);
}
.notice {
  background: var(--warning-bg);
  color: var(--warning);
  border-radius: 8px;
  padding: 10px 12px;
  font-weight: 500;
}
th .th {
  display: block;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}
.heat-cell {
  display: inline-block;
  min-width: 56px;
  padding: 4px 8px;
  border-radius: 6px;
  text-align: center;
  font-weight: 600;
}
.heat-cell.good {
  color: var(--good);
  background: var(--good-bg);
}
.heat-cell.warning {
  color: var(--warning);
  background: var(--warning-bg);
}
.heat-cell.critical {
  color: var(--critical);
  background: var(--critical-bg);
}
.heat-cell.neutral {
  color: var(--text-muted);
  background: var(--grid);
}
.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  padding-bottom: 9px;
  cursor: pointer;
}
.pill-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}
.deliverable {
  min-width: 260px;
  max-width: 480px;
}
.deliverable details {
  margin-top: 4px;
}
.deliverable summary {
  color: var(--accent);
  cursor: pointer;
  width: fit-content;
}
.deliverable details p {
  margin: 6px 0 0;
  white-space: pre-line;
}
.inline-filters {
  border: 0;
  padding: 0;
  margin-bottom: 12px;
}

@media (max-width: 900px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  }
  .sidebar.open {
    transform: none;
  }
  .side-close {
    display: inline-grid;
    margin-left: auto;
  }
  .side-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(0, 0, 0, 0.35);
  }
  .mobile-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
  }
}
@media (max-width: 600px) {
  .content {
    padding-left: 16px;
    padding-right: 16px;
  }
  .filters .field.inline {
    flex: 1 1 140px;
  }
}

/* ---------- Server-rendered charts ---------- */
.chart-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}
.chart-svg text {
  fill: var(--text-muted);
  font-size: 12px;
}
.chart-svg .hit {
  fill: transparent;
}
.chart-svg .hit:hover {
  fill: var(--hover);
}
.hbars {
  --label-w: 150px;
  position: relative;
  font-size: 12px;
}
.hbars-row {
  display: grid;
  grid-template-columns: var(--label-w) 1fr;
  align-items: center;
  min-height: 34px;
  border-radius: 4px;
  color: inherit;
  text-decoration: none;
}
a.hbars-row,
.hbars-row[data-tip] {
  cursor: pointer;
}
.hbars-row:hover {
  background: var(--hover);
}
.hbars-label {
  color: var(--text-secondary);
  padding-right: 10px;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hbars-track {
  position: relative;
  height: 100%;
  min-height: 34px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  border-left: 1px solid var(--axis);
  margin-right: 48px;
}
.hbars-grid {
  position: absolute;
  inset: 0 48px 0 var(--label-w);
  pointer-events: none;
}
.hbars-grid span {
  position: absolute;
  top: 0;
  bottom: 22px;
  border-left: 1px solid var(--grid);
}
.hbar {
  position: relative;
  height: 20px;
  border-radius: 0 4px 4px 0;
  min-width: 1px;
}
.hbars.paired .hbar {
  height: 13px;
}
.hbar-value {
  position: absolute;
  left: calc(100% + 6px);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  white-space: nowrap;
  font-size: 11px;
}
.hstack {
  display: flex;
  height: 20px;
}
.hstack span {
  height: 100%;
  border-right: 2px solid var(--surface);
}
.hstack span:last-child {
  border-radius: 0 4px 4px 0;
}
.hbars-axis {
  display: grid;
  grid-template-columns: var(--label-w) 1fr;
  height: 22px;
}
.hbars-axis div {
  position: relative;
  margin-right: 48px;
}
.hbars-axis > div > span {
  position: absolute;
  top: 4px;
  transform: translateX(-50%);
  color: var(--text-muted);
}
.chart-tooltip.floating {
  position: fixed;
  z-index: 50;
  pointer-events: none;
}
.flash {
  border-radius: 8px;
  padding: 10px 12px;
  font-weight: 500;
}
.flash.good {
  background: var(--good-bg);
  color: var(--good);
}
.flash.warning {
  background: var(--warning-bg);
  color: var(--warning);
}
.head-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.head-actions form {
  margin: 0;
}
.file-btn input {
  display: none;
}
.side-user form {
  margin: 0;
}
@media (max-width: 600px) {
  .hbars {
    --label-w: 100px;
  }
}
.side-scrim[hidden] {
  display: none !important;
}

/* ---------- Edited due dates ---------- */
.date-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.date-switch-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}
.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 2px;
}
.seg a {
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
}
.seg a:hover {
  color: var(--text-primary);
}
.seg a.active {
  background: var(--accent);
  color: var(--accent-ink);
}
.content .seg a {
  color: var(--text-secondary);
}
.content .seg a.active {
  color: var(--accent-ink);
}
.date-note {
  margin-top: 4px;
  color: var(--text-muted);
  white-space: nowrap;
}
.edited-tag {
  display: inline-block;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--hover);
  color: var(--accent);
  font-weight: 600;
}
.date-edit {
  margin-top: 4px;
}
.date-edit summary {
  color: var(--accent);
  cursor: pointer;
  width: fit-content;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 8px;
  font-weight: 600;
  white-space: nowrap;
}
.date-edit summary::-webkit-details-marker {
  display: none;
}
.date-edit summary:hover {
  border-color: var(--accent);
  background: var(--hover);
}
.date-edit[open] summary {
  background: var(--hover);
}
.date-edit-form {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  align-items: center;
}
.date-edit-form input[type='date'] {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 5px 8px;
}
.btn.compact {
  padding: 5px 10px;
  font-size: 12px;
}
.side-dates {
  padding: 0 6px 4px;
}
.side-dates .side-label {
  padding-left: 4px;
}
.side-dates .seg {
  display: flex;
}
.side-dates .seg a {
  flex: 1;
  text-align: center;
  color: var(--text-secondary);
}
.side-dates .seg a.active {
  color: var(--accent-ink);
}
.side-dates p {
  margin: 6px 4px 0;
}

/* ---------- Modal ---------- */
.modal {
  width: min(400px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
  text-align: center;
}
.modal::backdrop {
  background: rgba(17, 17, 16, 0.4);
}
.modal[open] {
  animation: modal-in 0.16s ease-out;
}
@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}
.modal-icon {
  width: 44px;
  height: 44px;
  margin: 0 auto 12px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--critical-bg);
  color: var(--critical);
}
.modal h2 {
  font-size: 17px;
  font-weight: 600;
}
.modal p {
  margin: 6px 0 20px;
}
.modal-actions {
  display: flex;
  gap: 8px;
}
.modal-actions .btn {
  flex: 1;
  padding: 10px 14px;
}
.btn.danger {
  background: var(--critical);
  border-color: var(--critical);
  color: #fff;
}
.btn.danger:hover:not(:disabled) {
  filter: brightness(1.08);
}
