:root {
  --bg: #0b0e14;
  --panel: #11151f;
  --panel-2: #161b27;
  --line: #232a39;
  --text: #d7dce5;
  --muted: #8a93a6;
  --accent: #4f9dff;
  --accent-2: #7c5cff;
  --ok: #3fb950;
  --warn: #d29922;
  --err: #f85149;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

html.light {
  --bg: #f0f2f5;
  --panel: #ffffff;
  --panel-2: #f4f5f7;
  --line: #dfe1e6;
  --text: #172b4d;
  --muted: #5e6c84;
  --accent: #0052cc;
  --accent-2: #5243aa;
  --ok: #006644;
  --warn: #ff8b00;
  --err: #bf2600;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
}

body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 24px;
  height: 48px; padding: 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.theme-btn {
  background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 10px; cursor: pointer; font-size: 11px; font-weight: 600;
  letter-spacing: 0.5px; white-space: nowrap;
}
.theme-btn:hover { color: var(--text); border-color: var(--accent); }
.brand { display: flex; align-items: baseline; gap: 10px; }
.logo {
  font-weight: 800; letter-spacing: 1px; font-size: 16px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-sub { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }
.status-pills { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; }
.pill {
  font-family: var(--mono); font-size: 11px;
  padding: 3px 9px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  display: inline-flex; gap: 6px; align-items: center;
}
.pill b { color: #fff; font-weight: 700; }
.pill-muted { color: var(--muted); }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.pill.err .dot { background: var(--err); }
.principal { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; }
.principal select {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; font-size: 12px;
}

/* Layout */
.layout { display: grid; grid-template-columns: 200px 1fr 340px; flex: 1; min-height: 0; }

/* Nav */
.nav { background: var(--panel); border-right: 1px solid var(--line); padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  text-align: left; background: transparent; border: 0; color: var(--muted);
  padding: 8px 12px; border-radius: 7px; cursor: pointer; font-size: 13px;
  text-decoration: none; display: block;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: rgba(79,157,255,0.12); color: var(--accent); font-weight: 600; }
.nav-spacer { flex: 1; }
.nav-link { color: var(--muted); font-size: 12px; }

/* Workspace */
.workspace { padding: 20px 24px; overflow-y: auto; min-width: 0; }
.workspace h1 { font-size: 18px; margin: 0 0 4px; }
.workspace .sub { color: var(--muted); margin: 0 0 18px; font-size: 12px; }
.loading { color: var(--muted); padding: 40px; text-align: center; }

.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 24px; }
.metric { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.metric .n { font-size: 26px; font-weight: 700; font-family: var(--mono); }
.metric .l { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; margin-top: 2px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-bottom: 20px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.panel-head h2 { font-size: 13px; margin: 0; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { text-align: left; padding: 8px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; position: sticky; top: 0; background: var(--panel); }
tbody tr:hover { background: var(--panel-2); }
td.mono, td .id { font-family: var(--mono); color: var(--muted); font-size: 11px; }
.tag { font-family: var(--mono); font-size: 10px; padding: 2px 7px; border-radius: 5px; background: var(--panel-2); border: 1px solid var(--line); }
.empty { color: var(--muted); padding: 20px 14px; font-size: 12px; }

/* Forms */
.form-row { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 14px; align-items: center; }
.form-row input, .form-row textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 7px 10px; font-size: 12px; font-family: inherit;
}
.form-row input { flex: 1; min-width: 120px; }
button.btn {
  background: var(--accent); color: #06203f; border: 0; border-radius: 6px;
  padding: 7px 14px; font-weight: 600; cursor: pointer; font-size: 12px;
}
button.btn:hover { filter: brightness(1.1); }
button.btn.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }

.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 8px; font-size: 12px; z-index: 10; }
.toast.err { border-color: var(--err); color: #ffb4ad; }

/* Chat */
.chat { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.chat-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.chat-badge { font-family: var(--mono); font-size: 10px; color: var(--warn); border: 1px solid var(--warn); border-radius: 5px; padding: 1px 6px; }
.chat-log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { padding: 9px 12px; border-radius: 10px; max-width: 90%; font-size: 12px; line-height: 1.45; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: rgba(79,157,255,0.14); border: 1px solid rgba(79,157,255,0.3); }
.msg.bot { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--line); }
.chat-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.chat-input input { flex: 1; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 7px; padding: 9px 11px; font-size: 12px; }
.chat-input button { background: var(--accent-2); color: #fff; border: 0; border-radius: 7px; padding: 9px 14px; cursor: pointer; font-weight: 600; }

/* Launcher (Odoo-style app grid) */
.launcher { padding: 40px 32px; }
.launcher-heading { margin-bottom: 32px; }
.launcher-heading h1 { font-size: 22px; margin: 0 0 4px; }

.launcher-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 16px;
  max-width: 800px;
}

.launcher-tile {
  display: flex; flex-direction: column; align-items: center;
  gap: 10px; padding: 20px 12px 16px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: center;
}
.launcher-tile:hover { background: var(--panel-2); border-color: var(--accent); }
.launcher-tile.launcher-tile-stub { opacity: 0.45; cursor: default; }
.launcher-tile.launcher-tile-stub:hover { background: var(--panel); border-color: var(--line); }

.launcher-icon {
  width: 56px; height: 56px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 800; letter-spacing: -0.5px;
}

.launcher-tile-name { font-size: 12px; font-weight: 600; color: var(--text); line-height: 1.3; }
.launcher-tile-ver  { font-size: 10px; color: var(--muted); font-family: var(--mono); }

.launcher-login {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 60vh; gap: 12px; text-align: center;
}
.launcher-brand { font-size: 48px; font-weight: 800; letter-spacing: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.launcher-tagline { color: var(--muted); font-size: 14px; margin: 0; }
.launcher-hint { color: var(--muted); font-size: 12px; margin: 0; }

/* Module nav */
.nav-back { color: var(--accent); font-weight: 600; }
.nav-divider { height: 1px; background: var(--line); margin: 6px 4px; }
.nav-module-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--muted); padding: 4px 12px 2px;
}

/* Timeline / Gantt (FEAT-M1) */
.gantt { padding: 4px 0; }
.gantt-row { display: grid; grid-template-columns: 240px 1fr; align-items: center; gap: 12px; padding: 6px 14px; border-bottom: 1px solid var(--line); }
.gantt-row:hover { background: var(--panel-2); }
.gantt-label { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gantt-track { position: relative; height: 22px; background: var(--bg); border-radius: 5px; }
.gantt-bar { position: absolute; top: 2px; height: 18px; border-radius: 4px; font-size: 10px; line-height: 18px; padding: 0 6px; color: #06203f; font-weight: 600; overflow: hidden; white-space: nowrap; box-shadow: 0 1px 2px rgba(0,0,0,0.3); }
.gantt-bar.todo { background: #8a93a6; }
.gantt-bar.in_progress { background: var(--accent); }
.gantt-bar.done { background: var(--ok); color: #04210a; }
.gantt-unscheduled { color: var(--muted); font-size: 11px; line-height: 22px; padding-left: 8px; }
.pill.todo { color: #c7ced9; }
.pill.in_progress { color: var(--accent); border-color: rgba(79,157,255,0.4); }
.pill.done { color: var(--ok); border-color: rgba(63,185,80,0.4); }

/* Board (kanban, FEAT-M1) */
.board { display: flex; gap: 12px; overflow-x: auto; padding: 4px 0; }
.board-col { flex: 0 0 220px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; display: flex; flex-direction: column; max-height: 72vh; }
.board-col-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.board-count { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.board-cards { padding: 8px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.board-card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.bc-title { font-size: 12px; }
.bc-meta { font-size: 10px; color: var(--muted); margin-top: 4px; }

/* Roadmap (FEAT-M1) */
.roadmap-lane { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 14px; }

/* Project module (FEAT-M6) */
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px; margin-bottom: 4px;
}
.project-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 16px 18px; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.project-card:hover { background: var(--panel-2); border-color: var(--accent); }
.project-card-name { font-size: 14px; font-weight: 700; margin-bottom: 4px; }
.project-card-meta { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.project-card-desc { font-size: 11px; color: var(--muted); margin-top: 4px; }

.gantt-row { grid-template-columns: 220px 1fr 32px; }
.gantt-actions { display: flex; align-items: center; justify-content: flex-end; }
.btn-xs { font-size: 11px; padding: 3px 8px; }
.schedule-form { padding: 4px 14px 8px; background: var(--panel-2); }

.bc-transitions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }

.board-card .btn-xs { font-size: 10px; padding: 2px 6px; }

/* Project Overview */
.overview-header { margin-bottom: 20px; }
.overview-header h1 { margin: 0 0 6px; }
.overview-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.overview-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px; margin-bottom: 20px;
}
.stat-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.stat-n { font-size: 28px; font-weight: 700; font-family: var(--mono); line-height: 1; }
.stat-l { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; margin-top: 4px; }
.overview-section { margin-bottom: 12px; }
.quick-nav { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 14px; }

/* Scope / WBS view */
.workspace--split { padding: 0; overflow: hidden; display: grid; grid-template-columns: 1fr 360px; }
.scope-pane { overflow-y: auto; }
.scope-pane-left { border-right: 1px solid var(--line); }
.scope-pane-right { padding: 20px; background: var(--panel-2); }
.scope-pane-right .detail-placeholder { color: var(--muted); font-size: 12px; padding-top: 8px; }

.scope-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.scope-header h1 { font-size: 16px; margin: 0; }

.scope-tree-head {
  display: grid; grid-template-columns: 1fr 90px 80px 80px 90px;
  padding: 6px 14px; border-bottom: 1px solid var(--line);
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); font-weight: 600;
}
.scope-row {
  display: grid; grid-template-columns: 1fr 90px 80px 80px 90px;
  align-items: center; gap: 4px;
  padding: 7px 14px; border-bottom: 1px solid var(--line);
  cursor: pointer; font-size: 12px;
}
.scope-row:hover { background: var(--panel-2); }
.scope-row.selected { background: rgba(79,157,255,0.08); border-left: 3px solid var(--accent); padding-left: 11px; }
html.light .scope-row.selected { background: rgba(0,82,204,0.06); border-left-color: var(--accent); }
.scope-title-cell { display: flex; align-items: center; gap: 6px; overflow: hidden; }
.scope-indent { flex: 0 0 auto; }
.scope-title-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scope-cell-muted { color: var(--muted); font-size: 11px; }
.scope-cell-mono { font-family: var(--mono); font-size: 11px; color: var(--muted); }

/* Scope detail panel */
.detail-title { font-size: 14px; font-weight: 700; margin: 0 0 14px; word-break: break-word; }
.detail-section { margin-bottom: 16px; }
.detail-section-head { font-size: 10px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.detail-grid { display: grid; grid-template-columns: 100px 1fr; gap: 6px 12px; font-size: 12px; }
.detail-label { color: var(--muted); font-weight: 600; font-size: 11px; }
.detail-val { word-break: break-all; }

/* Project card: level badge */
.project-card-level { font-size: 10px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.project-status-badge { display: inline-flex; gap: 6px; align-items: center; }

/* Level / risk badges (FEAT-M6/M7/M8) */
.level-badge {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.7px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px; border: 1px solid;
  display: inline-block; vertical-align: middle;
}

/* Project hierarchy tree (BigPicture-style box list) */
.ptree-head {
  display: grid; grid-template-columns: 1fr 110px 70px 60px 60px 80px;
  padding: 8px 14px; border-bottom: 1px solid var(--line);
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--muted); font-weight: 600;
}
.ptree-row {
  display: grid; grid-template-columns: 1fr 110px 70px 60px 60px 80px;
  align-items: center; gap: 4px;
  padding: 9px 14px; border-bottom: 1px solid var(--line);
  cursor: pointer; font-size: 12px;
}
.ptree-row:hover { background: var(--panel-2); }
.ptree-name-cell { display: flex; align-items: center; gap: 8px; overflow: hidden; }
.ptree-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-chevron { color: var(--muted); font-size: 9px; flex: 0 0 auto; }
.tree-chevron-spacer { width: 9px; flex: 0 0 9px; display: inline-block; }

/* Breadcrumbs (project ancestors) */
.crumbs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; font-size: 12px; }
.crumb-link { color: var(--accent); cursor: pointer; }
.crumb-link:hover { text-decoration: underline; }
.crumb-sep { color: var(--muted); }
.crumb-current { color: var(--muted); }

/* Chips (linked products / dependencies) */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 14px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 6px 4px 12px; font-size: 12px;
}
.chip-x {
  background: transparent; border: 0; color: var(--muted); cursor: pointer;
  font-size: 10px; padding: 2px 6px; border-radius: 999px; line-height: 1;
}
.chip-x:hover { background: var(--err); color: #fff; }

/* Risk matrix (FEAT-M8, 5×5 likelihood × consequence) */
.risk-layout { display: grid; grid-template-columns: minmax(320px, 460px) 1fr; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .risk-layout { grid-template-columns: 1fr; } }
.risk-matrix-wrap { display: flex; gap: 8px; padding: 14px 14px 4px; align-items: stretch; }
.risk-y-title {
  writing-mode: vertical-rl; transform: rotate(180deg);
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.7px;
  color: var(--muted); font-weight: 600; text-align: center;
}
.risk-matrix {
  display: grid; grid-template-columns: 22px repeat(5, 1fr);
  gap: 4px; flex: 1;
}
.risk-cell {
  aspect-ratio: 1.6; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-weight: 700; font-size: 14px; color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.45);
}
.risk-axis-label {
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 10px; color: var(--muted);
}
.risk-x-title {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.7px;
  color: var(--muted); font-weight: 600; text-align: center; padding: 2px 0 6px 30px;
}
.risk-legend { display: flex; gap: 14px; justify-content: center; padding: 4px 14px 12px; }
.risk-legend-item { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); }
.risk-legend-dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }

/* Stacked form (risk create) */
.form-col { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; }
.form-col input, .form-col select {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 7px 10px; font-size: 12px; font-family: inherit;
}
.form-col .form-row input, .form-col .form-row select { flex: 1; }
.form-col .btn { align-self: flex-start; }

/* Selects in inline forms (match inputs) */
.form-row select {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 7px 10px; font-size: 12px; font-family: inherit;
}

/* Risk register row selection (mitigation panel) */
.risk-row { cursor: pointer; }
.risk-row:hover td { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.risk-row-selected td { background: color-mix(in srgb, var(--accent) 14%, transparent); }

/* Risk side panel (edit / new form, sits next to the matrix) */
.risk-side-panel {
  overflow-y: auto;
  max-height: 520px;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.risk-side-panel .form-col { gap: 8px; }
.risk-side-panel textarea { font-family: inherit; font-size: 13px; }
