:root {
  --bg: #091012;
  --panel: #0d171a;
  --panel-raised: #122024;
  --line: #203237;
  --line-strong: #345159;
  --text: #edf7f5;
  --muted: #8ba3a5;
  --cyan: #58e0d1;
  --cyan-deep: #174842;
  --amber: #ffc45a;
  --red: #ff7e72;
  --green: #84e695;
  --radius: 10px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--bg); }
button { font: inherit; }

.auth-gate { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 20px; background: rgba(5, 10, 11, .96); }
.auth-gate[hidden] { display: none; }
.login-card { width: min(420px, 100%); padding: 28px; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--panel-raised); box-shadow: 0 30px 100px #000; }
.login-card h1 { margin: 8px 0; font-size: 1.45rem; }
.login-card p { color: var(--muted); font-size: .86rem; line-height: 1.45; }
.login-card label { display: block; margin: 14px 0; color: var(--muted); font-size: .76rem; }
.login-card input { display: block; width: 100%; margin-top: 6px; padding: 10px; border: 1px solid var(--line-strong); border-radius: 6px; color: var(--text); background: var(--bg); font: inherit; font-size: 1rem; }
.login-card output { display: block; min-height: 1.3em; margin-top: 12px; color: var(--red); font-size: .78rem; }

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(9, 16, 18, .96);
}
.identity { display: flex; align-items: center; gap: 12px; }
.identity strong { display: block; font: 700 1rem/1.1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .12em; }
.identity span:not(.signal) { display: block; color: var(--muted); font-size: .75rem; margin-top: 3px; }
.signal { width: 11px; height: 32px; border-radius: 3px; background: var(--cyan); box-shadow: 0 0 22px rgba(88,224,209,.42); }
.health { color: var(--muted); font-size: .82rem; display: flex; align-items: center; gap: 8px; }
.health span { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }
.health.ok span { background: var(--green); box-shadow: 0 0 12px rgba(132,230,149,.6); }
.health.error span { background: var(--red); }

.workspace { display: grid; grid-template-columns: 272px minmax(480px, 1fr) 330px; height: calc(100vh - 64px); }
.projects-panel, .journal-panel { overflow: auto; background: var(--panel); }
.projects-panel { border-right: 1px solid var(--line); }
.journal-panel { border-left: 1px solid var(--line); }
.project-panel { overflow: auto; padding: 28px 30px 50px; }
.panel-heading { min-height: 82px; padding: 18px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.panel-heading.compact { min-height: 82px; }
.panel-heading h1, .panel-heading h2, .section-heading h3 { margin: 3px 0 0; font-size: 1.15rem; }
.panel-actions { display: flex; align-items: center; gap: 6px; }
.eyebrow { color: var(--cyan); text-transform: uppercase; font: 700 .68rem/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .12em; }
.icon-button { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 7px; color: var(--text); background: transparent; cursor: pointer; font-size: 1.15rem; }
.icon-button:hover { border-color: var(--cyan); color: var(--cyan); }
.research-button { min-height: 34px; padding: 0 9px; border: 1px solid var(--cyan-deep); border-radius: 7px; color: var(--cyan); background: transparent; cursor: pointer; font-size: .78rem; }
.research-button:hover { border-color: var(--cyan); background: var(--cyan-deep); }

.project-list { padding: 10px; }
.project-card { width: 100%; text-align: left; border: 1px solid transparent; border-radius: 8px; color: var(--text); background: transparent; padding: 13px 12px; cursor: pointer; margin-bottom: 4px; }
.project-card:hover { background: #111d20; }
.project-card.selected { background: var(--panel-raised); border-color: var(--line-strong); }
.project-card strong { display: block; font-size: .9rem; line-height: 1.35; margin-bottom: 10px; }
.project-card footer { display: flex; justify-content: space-between; color: var(--muted); font: .72rem/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; }
.mini-stage { color: var(--cyan); }

.empty-state { min-height: 60vh; display: grid; place-content: center; text-align: center; color: var(--muted); }
.empty-state h2 { color: var(--text); margin: 18px 0 5px; }
.empty-state p { max-width: 360px; line-height: 1.55; }
.empty-mark { margin: auto; display: grid; place-items: center; width: 64px; height: 64px; border: 1px solid var(--line-strong); color: var(--cyan); font: 700 1.5rem ui-monospace, monospace; transform: rotate(45deg); }
.empty-mark::first-letter { transform: rotate(-45deg); }

.project-heading { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; margin-bottom: 22px; }
.project-heading h2 { margin: 7px 0 0; max-width: 820px; font-size: clamp(1.45rem, 2.6vw, 2.25rem); line-height: 1.1; letter-spacing: -.03em; }
.heading-meta { display: flex; gap: 12px; color: var(--muted); font: .73rem ui-monospace, SFMono-Regular, Menlo, monospace; text-transform: uppercase; }
.heading-actions { display: flex; align-items: center; gap: 10px; }
.stage { padding: 7px 9px; color: var(--cyan); border: 1px solid var(--cyan-deep); border-radius: 5px; font: 700 .72rem ui-monospace, SFMono-Regular, Menlo, monospace; }
.primary-button { border: 0; border-radius: 6px; padding: 9px 13px; color: #05201c; background: var(--cyan); font-weight: 750; cursor: pointer; }
.primary-button:disabled { opacity: .5; cursor: wait; }

.risk-banner { margin-bottom: 18px; padding: 14px 16px; border: 1px solid #6d5124; background: #241c10; border-radius: var(--radius); color: #ffe2a8; font-size: .88rem; line-height: 1.45; }
.risk-banner strong { color: var(--amber); }
.research-result { margin-bottom: 18px; padding: 16px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: linear-gradient(135deg, var(--panel-raised), var(--panel)); }
.research-result[hidden] { display: none; }
.research-result p { margin: 9px 0 14px; color: var(--muted); font-size: .9rem; line-height: 1.5; }
.research-details { display: grid; gap: 7px; }
.research-details article { padding: 10px 12px; border-left: 2px solid var(--cyan-deep); background: var(--bg); font-size: .78rem; line-height: 1.45; }
.research-details article strong { display: block; margin-bottom: 3px; color: var(--text); }
.research-details article span { color: var(--muted); overflow-wrap: anywhere; }
.research-link { color: var(--cyan); border: 0; padding: 0; background: transparent; cursor: pointer; text-decoration: underline; }
.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(130px, 1fr)); gap: 10px; margin-bottom: 28px; }
.metrics-grid article { min-height: 112px; padding: 15px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.metrics-grid span { display: block; color: var(--muted); font-size: .76rem; }
.metrics-grid strong { display: block; margin: 13px 0 10px; font: 650 1.35rem ui-monospace, SFMono-Regular, Menlo, monospace; }
.metrics-grid small { color: #627b7e; font-size: .68rem; }
.bar { height: 3px; background: #1b2a2e; overflow: hidden; }
.bar i { display: block; width: 0; height: 100%; background: var(--cyan); transition: width .25s ease; }

.section-heading { display: flex; justify-content: space-between; align-items: end; margin-bottom: 11px; }
.section-note { color: var(--muted); font-size: .78rem; }
.task-list { display: grid; gap: 7px; }
.task-card { width: 100%; display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 13px 14px; text-align: left; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); cursor: pointer; }
.task-card:hover { border-color: var(--line-strong); background: var(--panel-raised); }
.task-index { color: #587174; font: .76rem ui-monospace, SFMono-Regular, Menlo, monospace; }
.task-title { min-width: 0; }
.task-title strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.task-title span { color: var(--muted); font-size: .72rem; }
.task-state { font: 700 .7rem ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--cyan); }
.task-card.risk .task-state { color: var(--amber); }
.task-card.blocked .task-state { color: var(--red); }

.cursor { color: var(--muted); font: .72rem ui-monospace, monospace; }
.owner-questions { padding: 10px; }
.owner-card { padding: 13px; border: 1px solid #6d5124; background: #241c10; border-radius: 8px; margin-bottom: 7px; }
.owner-card small { color: var(--amber); text-transform: uppercase; font: .66rem ui-monospace, monospace; }
.owner-card p { font-size: .86rem; line-height: 1.4; }
.owner-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.owner-actions button { border: 1px solid #705b32; color: #ffe2a8; background: transparent; border-radius: 5px; padding: 6px 8px; cursor: pointer; }
.journal { list-style: none; margin: 0; padding: 8px 16px 30px; }
.journal li { position: relative; padding: 0 0 16px 17px; border-left: 1px solid var(--line); }
.journal li::before { content: ""; position: absolute; left: -4px; top: 4px; width: 7px; height: 7px; border-radius: 50%; background: var(--line-strong); }
.journal li:last-child { border-left-color: transparent; }
.journal time { color: #60797c; font: .67rem ui-monospace, monospace; }
.journal strong { display: block; margin: 3px 0; font-size: .78rem; font-weight: 650; }
.journal p { margin: 0; color: var(--muted); font-size: .74rem; line-height: 1.42; overflow-wrap: anywhere; }

dialog { width: min(720px, calc(100vw - 30px)); max-height: 88vh; color: var(--text); background: var(--panel-raised); border: 1px solid var(--line-strong); border-radius: 12px; padding: 25px; box-shadow: 0 30px 100px #000; }
dialog::backdrop { background: rgba(0, 5, 6, .78); backdrop-filter: blur(3px); }
.dialog-close { position: absolute; right: 14px; top: 12px; color: var(--muted); background: transparent; border: 0; font-size: 1.7rem; cursor: pointer; }
.detail-kicker { color: var(--cyan); font: .7rem ui-monospace, monospace; }
.detail-title { margin: 8px 35px 22px 0; font-size: 1.45rem; line-height: 1.2; }
.detail-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 20px; }
.detail-grid div { padding: 11px; background: var(--bg); border-radius: 6px; }
.detail-grid span { display: block; color: var(--muted); font-size: .67rem; margin-bottom: 5px; }
.detail-grid strong { font: .78rem ui-monospace, monospace; overflow-wrap: anywhere; }
.detail-section { margin-top: 20px; }
.detail-section h4 { margin: 0 0 9px; font-size: .85rem; }
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { padding: 9px 0; border-top: 1px solid var(--line); font-size: .78rem; line-height: 1.4; }
.checklist b { color: var(--cyan); margin-right: 6px; }
.mono { color: var(--muted); font: .72rem/1.5 ui-monospace, monospace; overflow-wrap: anywhere; }
.research-form { display: grid; gap: 10px; }
.research-form .detail-title { margin-bottom: 8px; }
.research-form label { color: var(--muted); font-size: .82rem; }
.research-form textarea, .research-form select { width: 100%; padding: 11px; border: 1px solid var(--line-strong); border-radius: 7px; color: var(--text); background: var(--bg); font: inherit; font-size: 1rem; }
.research-form textarea { resize: vertical; min-height: 120px; line-height: 1.45; }
.research-form textarea:focus, .research-form select:focus { outline: 2px solid var(--cyan); outline-offset: 1px; }
.research-form .check-row { display: flex; align-items: center; gap: 8px; color: var(--text); }
.research-form .check-row input { width: 18px; height: 18px; accent-color: var(--cyan); }
.form-note { margin: 0; color: var(--muted); font-size: .78rem; line-height: 1.45; }
.research-form output { min-height: 1.3em; color: var(--red); font-size: .78rem; }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 230px 1fr; }
  .journal-panel { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); max-height: 420px; }
  .workspace { overflow: auto; height: auto; min-height: calc(100vh - 64px); }
  .projects-panel, .project-panel { min-height: calc(100vh - 64px); }
}
@media (max-width: 720px) {
  .topbar { padding: 0 14px; }
  .health { font-size: 0; }
  .workspace { display: block; }
  .projects-panel, .project-panel { min-height: auto; }
  .projects-panel { border-right: 0; border-bottom: 1px solid var(--line); max-height: 260px; }
  .research-button { min-height: 40px; }
  .project-panel { padding: 22px 15px 38px; }
  .project-heading { display: block; }
  .heading-actions { margin-top: 14px; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .task-card { grid-template-columns: 30px minmax(0, 1fr); }
  .task-state { grid-column: 2; }
  .detail-grid { grid-template-columns: 1fr; }
}
