@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --ink: #17212B;
  --ink-soft: #4B5A6A;
  --line: #DCE2E8;
  --line-strong: #B9C3CD;
  --surface: #FFFFFF;
  --canvas: #F3F5F7;
  --header: #17212B;
  --header-2: #223142;
  --accent: #2F6FED;
  --accent-soft: #E8EFFE;
  --pass: #1E8E5A;
  --pass-soft: #E4F5EC;
  --fail: #C6423E;
  --fail-soft: #FBE6E5;
  --warn: #B9791B;
  --warn-soft: #FBF0DD;
  --neutral: #6B7887;
  --neutral-soft: #EBEEF1;
  --radius: 6px;
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', 'SFMono-Regular', Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--canvas);
  font-size: 13.5px;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

/* ---------- App shell ---------- */
.app-shell { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  background: var(--header);
  color: #fff;
  display: flex;
  align-items: center;
  height: 52px;
  padding: 0 20px;
  flex-shrink: 0;
  border-bottom: 1px solid #0E151C;
}
.topbar .brand {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.2px;
  margin-right: 6px;
}
.topbar .brand .accent-dot {
  display: inline-block;
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
  margin-right: 8px;
}
.topbar .sub { color: #93A2B3; font-size: 12px; margin-right: 32px; }

.topnav { display: flex; gap: 4px; flex: 1; }
.topnav a {
  text-decoration: none;
  color: #C7D1DC;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: var(--radius);
  transition: background .12s, color .12s;
}
.topnav a:hover { background: var(--header-2); color: #fff; }
.topnav a.active { background: var(--accent); color: #fff; }

.topbar .env-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  color: #93A2B3;
  border: 1px solid #35455A;
  padding: 3px 8px;
  border-radius: 4px;
}
.project-switcher {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 14px;
  padding-left: 14px;
  border-left: 1px solid #35455A;
}
.project-switcher select {
  font-family: var(--font-ui);
  font-size: 12px;
  background: #1F2C39;
  color: #E7ECF1;
  border: 1px solid #3A4B5F;
  border-radius: 4px;
  padding: 4px 8px;
  max-width: 200px;
}
.project-switcher button {
  border: none;
  background: transparent;
  color: #93A2B3;
  font-size: 13px;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 4px;
}
.project-switcher button:hover { background: #2B394A; color: #fff; }
.user-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 14px;
  padding-left: 14px;
  border-left: 1px solid #35455A;
}
.user-bar-name { font-size: 12.5px; color: #E7ECF1; font-weight: 600; }
.user-bar-role {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .3px;
  color: #93A2B3;
  border: 1px solid #35455A;
  padding: 2px 6px;
  border-radius: 4px;
}
.user-bar-logout {
  border: none;
  background: transparent;
  color: #93A2B3;
  font-size: 14px;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 4px;
}
.user-bar-logout:hover { background: #2B394A; color: #fff; }

.page {
  flex: 1;
  overflow: auto;
  padding: 18px 22px 32px;
}

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 10px;
}
.page-head h1 {
  font-size: 19px;
  margin: 0;
  font-weight: 700;
}
.page-head .desc { color: var(--ink-soft); font-size: 12.5px; margin-top: 2px; }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  padding: 7px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background .12s, border-color .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--canvas); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #2760D6; }
.btn.danger { color: var(--fail); border-color: #EBC3C1; background: var(--fail-soft); }
.btn.danger:hover { background: #F6D3D1; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--neutral-soft); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.icon { font-size: 13px; line-height: 1; }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 12px;
}
.toolbar .spacer { flex: 1; }
.toolbar input[type=text], .toolbar select {
  font-family: var(--font-ui);
  font-size: 12.5px;
  padding: 6px 9px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}
.toolbar .search-box { position: relative; }
.toolbar .search-box input { width: 220px; padding-left: 26px; }
.toolbar .search-box::before {
  content: '⌕';
  position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  color: var(--neutral); font-size: 14px;
}
.chip {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--neutral-soft);
  color: var(--ink-soft);
  padding: 3px 8px;
  border-radius: 20px;
}

/* ---------- Grid / Table ---------- */
.grid-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: auto;
  max-height: calc(100vh - 230px);
}
table.grid { border-collapse: collapse; width: 100%; min-width: 1750px; }
table.grid thead th {
  position: sticky; top: 0; z-index: 3;
  background: var(--header);
  color: #E7ECF1;
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .3px;
  text-transform: uppercase;
  padding: 0;
  border-right: 1px solid #2B394A;
  user-select: none;
  white-space: nowrap;
}
table.grid thead th .th-inner {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 10px;
  cursor: grab;
}
table.grid thead th .th-inner:active { cursor: grabbing; }
table.grid thead th.dragging { opacity: .4; }
table.grid thead th .sort-arrow { font-size: 10px; opacity: .85; }
.group-header-toggle {
  border: none; background: #2B394A; color: #C7D3E0;
  width: 18px; height: 18px; border-radius: 4px; font-size: 9px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.group-header-toggle:hover { background: #3A4B5F; color: #fff; }
table.grid thead th .filter-row-cell { padding: 6px 8px; border-top: 1px solid #2B394A; }
table.grid thead th .filter-row-cell input, table.grid thead th .filter-row-cell select {
  width: 100%; font-family: var(--font-ui); font-size: 11.5px;
  padding: 4px 6px; border-radius: 4px; border: 1px solid #3A4B5F;
  background: #1F2C39; color: #E7ECF1;
}
table.grid thead th .filter-row-cell input::placeholder { color: #7E8FA1; }

table.grid tbody td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid #EEF1F4;
  vertical-align: middle;
  white-space: nowrap;
}
table.grid tbody tr:hover { background: #FAFBFC; }
table.grid tbody tr.meeting-row { background: #F5F8FF; }
table.grid tbody tr.meeting-row:hover { background: #EFF4FF; }
table.grid tbody tr.group-summary-row { background: #F0F4F8; font-weight: 600; }
table.grid tbody tr.group-summary-row:hover { background: #E7EDF3; }
table.grid tbody td.editable { cursor: text; }
table.grid tbody td.editable:hover { outline: 1px solid var(--accent); outline-offset: -1px; }
/* The editable class is applied to the inline span inside the cell. Give it a
   real click target — including when it's empty — so blank fields (e.g. a
   Planned Date left empty on creation) can still be clicked to edit. */
table.grid tbody span.editable { cursor: text; display: inline-block; min-width: 2.5em; min-height: 1.2em; border-radius: 3px; }
table.grid tbody span.editable:hover { outline: 1px solid var(--accent); outline-offset: 1px; background: #FBFCFE; }
table.grid tbody span.editable.cell-empty { color: var(--neutral); }
.date-past { color: var(--fail); font-weight: 700; }
.date-today { color: var(--warn); font-weight: 700; }
.col-toggle-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; max-height: 340px; overflow-y: auto; }
.col-toggle-row { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 3px 0; cursor: pointer; }
.col-toggle-row input { cursor: pointer; }
table.grid tbody tr.nested-group-header td { background: #EEF2F6; border-top: 1px solid #D4DEE7; font-size: 13px; padding: 5px 8px; }
table.grid tbody tr.nested-group-header.depth-0 td { background: #E4EBF1; font-weight: 700; }
table.grid tbody tr.nested-group-header.depth-1 td { background: #EBF0F5; font-weight: 600; }
table.grid tbody tr.nested-group-header.depth-2 td { background: #F1F5F8; }
.nested-group-header .group-toggle { background: none; border: none; cursor: pointer; font-size: 11px; color: var(--ink-soft); margin-right: 6px; }
.nested-group-dim { color: var(--ink-soft); font-weight: 500; }
.nested-group-value { margin-left: 4px; }
.nested-group-count { color: var(--ink-soft); font-weight: 400; margin-left: 8px; font-size: 12px; }
.two-col-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .two-col-cards { grid-template-columns: 1fr; } }
.chart-holder { width: 100%; overflow-x: auto; }
.field-inline { display: inline-flex; align-items: center; gap: 6px; margin-right: 12px; font-size: 13px; color: var(--ink-soft); }
.field-inline input { margin-left: 4px; }
table.grid tbody tr.audit-unknown td { color: var(--fail); font-style: italic; }
.filter-input { width: 100%; box-sizing: border-box; font-size: 11px; padding: 2px 4px; }
table.grid tbody td input, table.grid tbody td select {
  width: 100%; font-family: var(--font-ui); font-size: 12.5px;
  border: 1px solid var(--accent); border-radius: 4px; padding: 4px 6px;
}

.badge { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 20px; display: inline-block; }
.badge.pass { background: var(--pass-soft); color: var(--pass); }
.badge.fail { background: var(--fail-soft); color: var(--fail); }
.badge.notstarted { background: var(--neutral-soft); color: var(--neutral); }
.badge.inprogress { background: var(--warn-soft); color: var(--warn); }
.badge.scheduled { background: var(--accent-soft); color: var(--accent); }
.badge.open { background: var(--warn-soft); color: var(--warn); }
.badge.closed { background: var(--pass-soft); color: var(--pass); }

.mono { font-family: var(--font-mono); font-size: 12px; color: var(--ink-soft); }
.row-actions { display: flex; gap: 4px; }
.icon-btn {
  border: none; background: transparent; cursor: pointer;
  color: var(--neutral); font-size: 13px; padding: 3px 5px; border-radius: 4px;
}
.icon-btn:hover { background: var(--neutral-soft); color: var(--ink); }
.icon-btn.danger:hover { background: var(--fail-soft); color: var(--fail); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.icon-btn.active-toggle { color: var(--accent); background: var(--accent-soft); }

/* ---------- KPI boxes as clickable filters ---------- */
.kpi-stat { cursor: pointer; transition: box-shadow .12s, border-color .12s; }
.kpi-stat:hover { border-color: var(--accent); }
.kpi-stat.kpi-active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

/* ---------- Grouped rows: indent + highlight, no separate banner row ---------- */
.group-toggle-cell { display: flex; align-items: center; gap: 6px; }
.group-toggle {
  border: none; background: var(--accent-soft); color: var(--accent);
  width: 18px; height: 18px; border-radius: 4px; font-size: 9px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.group-toggle:hover { background: #DCE7FD; }
.group-toggle-name { font-weight: 700; color: #1A4FBF; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

table.grid tbody tr.group-first-row { background: #F7FAFF; }
table.grid tbody tr.grouped-child-row { background: #F7FAFF; box-shadow: inset 3px 0 0 0 var(--accent); }
table.grid tbody tr.grouped-child-row:hover { background: #EFF4FF; }
table.grid tbody tr.grouped-child-row td:first-child { padding-left: 26px; position: relative; }
table.grid tbody tr.grouped-child-row td:first-child::before {
  content: ''; position: absolute; left: 12px; top: 50%; width: 8px; height: 1px; background: #A9C4F5;
}

/* ---------- Cards / sub-pages ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.card h2 { font-size: 14px; margin: 0 0 12px; display: flex; align-items: center; justify-content: space-between; }
.field-label { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .3px; color: var(--ink-soft); margin-bottom: 5px; display: block; }
.field { margin-bottom: 14px; }
.field input[type=text], .field input[type=date], .field textarea, .field select {
  width: 100%; font-family: var(--font-ui); font-size: 13px;
  padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
}
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.three-col { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

.list-editor .list-item { display: flex; gap: 6px; margin-bottom: 6px; align-items: center; }
.list-editor .list-item input { flex: 1; }

.simple-table { width: 100%; border-collapse: collapse; }
.simple-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .3px;
  color: var(--ink-soft); padding: 8px 8px; border-bottom: 2px solid var(--line);
}
.simple-table td { padding: 7px 8px; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.simple-table tr.new-group-row td { background: #F7FAFF; border-top: 2px solid var(--accent-soft); }
.simple-table td input, .simple-table td select { width: 100%; font-size: 12.5px; padding: 4px 6px; border: 1px solid var(--line-strong); border-radius: 4px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,22,30,.45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: var(--surface); border-radius: 10px; width: 520px; max-width: 92vw;
  max-height: 86vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-head { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-body { padding: 16px 18px; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

.toast-stack { position: fixed; bottom: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 8px;
  font-size: 12.5px; box-shadow: 0 8px 24px rgba(0,0,0,.2); min-width: 220px;
}
.toast.error { background: var(--fail); }
.toast.success { background: var(--pass); }

.empty-state { padding: 40px; text-align: center; color: var(--neutral); }
.hidden { display: none !important; }
.stat-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 16px; min-width: 120px;
}
.stat .num { font-size: 22px; font-weight: 700; font-family: var(--font-mono); }
.stat .label { font-size: 11px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .3px; }

/* ---------- Reusable multi-select dropdown (status/stage/stakeholder filters) ---------- */
.multi-select-wrap { position: relative; display: inline-block; }
.multi-select-panel {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 20;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 8px; min-width: 200px; max-height: 260px; overflow-y: auto;
}
.multi-select-panel.hidden { display: none; }
.multi-select-panel label {
  display: flex; align-items: center; gap: 6px; padding: 5px 6px; font-size: 12.5px; border-radius: 4px; cursor: pointer;
}
.multi-select-panel label:hover { background: var(--canvas); }
.multi-select-panel label.all-option { font-weight: 600; border-bottom: 1px solid var(--line); margin-bottom: 4px; padding-bottom: 8px; }

.bulk-bar {
  display: flex; align-items: center; gap: 10px;
  background: #14202E; color: #fff; border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 12px; font-size: 12.5px;
}
.bulk-bar.hidden { display: none; }
.bulk-bar #bulkCount { font-weight: 600; margin-right: 4px; }
.bulk-bar .btn.ghost { color: #C7D1DC; }
.bulk-bar .btn.ghost:hover { background: rgba(255,255,255,.1); }
