/* ==========================================================================
   Design system for the PM Agent.
   Brand tokens live in :root — swap them for your organisation's official
   values and the whole application follows.
   ========================================================================== */

:root {
  --navy:        #00263E;
  --navy-2:      #003A5D;
  --blue:        #0672CB;
  --blue-dark:   #00447C;
  --blue-wash:   #EAF3FC;

  --green:       #6EA204;
  --amber:       #F2A900;
  --red:         #CE2029;

  --ink:         #1B1B1B;
  --ink-2:       #4A4A4A;
  --muted:       #6E7B85;
  --line:        #D7DDE2;
  --line-soft:   #EAEEF1;
  --surface:     #F4F6F8;
  --white:       #FFFFFF;

  --masthead-h:  56px;
  --sidebar-w:   248px;
  --radius:      3px;
  --shadow:      0 1px 3px rgba(0,38,62,.10), 0 1px 2px rgba(0,38,62,.06);
  --shadow-lg:   0 12px 32px rgba(0,38,62,.18);
}

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

html, body {
  margin: 0;
  padding: 0;
  font-family: Roboto, "Segoe UI", -apple-system, Arial, sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 400; color: var(--navy); }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Masthead ─────────────────────────────────────────────────────────── */
.masthead {
  position: fixed; inset: 0 0 auto 0; height: var(--masthead-h); z-index: 40;
  display: flex; align-items: center; gap: 18px; padding: 0 22px;
  background: var(--navy); border-bottom: 3px solid var(--blue);
}
.wordmark {
  color: var(--white); font-weight: 700; font-size: 18px; letter-spacing: .24em;
}
.masthead .rule { width: 1px; height: 24px; background: rgba(255,255,255,.25); }
.masthead .app-name { color: rgba(255,255,255,.95); font-size: 15px; }
.masthead .spacer { flex: 1; }
.masthead .context {
  color: rgba(255,255,255,.62); font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .1em;
}

/* ── Sidebar ──────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: var(--masthead-h); bottom: 0; left: 0;
  width: var(--sidebar-w); background: var(--white);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; overflow-y: auto; z-index: 30;
}
.project-switch { padding: 16px 16px 14px; border-bottom: 1px solid var(--line-soft); }
.project-switch label {
  display: block; font-size: 10.5px; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 7px;
}
.project-switch select {
  width: 100%; padding: 8px 10px; font: inherit; font-size: 13px;
  color: var(--ink); background: var(--white);
  border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer;
}
.project-switch select:hover { border-color: var(--blue); }
.project-switch .client { margin-top: 8px; font-size: 12px; color: var(--muted); }

.nav-section {
  padding: 16px 16px 6px; font-size: 10.5px; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase; color: var(--muted);
}
.nav { padding: 0 8px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; margin-bottom: 1px; border-radius: var(--radius);
  color: var(--ink-2); font-size: 13.5px; border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--surface); color: var(--ink); text-decoration: none; }
.nav-item.active {
  background: var(--blue-wash); color: var(--blue-dark);
  font-weight: 500; border-left-color: var(--blue);
}
.nav-item svg { width: 17px; height: 17px; flex: none; stroke-width: 1.7; }
.nav-item .count {
  margin-left: auto; font-size: 11px; color: var(--muted);
  background: var(--surface); padding: 1px 7px; border-radius: 10px;
}
.nav-item.active .count { background: var(--white); color: var(--blue-dark); }

.sidebar-foot {
  margin-top: auto; padding: 14px 16px; border-top: 1px solid var(--line-soft);
  font-size: 11.5px; color: var(--muted); line-height: 1.6;
}
.sidebar-foot .dot-on  { color: var(--green); }
.sidebar-foot .dot-off { color: var(--muted); }

/* ── Layout ───────────────────────────────────────────────────────────── */
.main {
  margin: var(--masthead-h) 0 0 var(--sidebar-w);
  padding: 24px 28px 60px;
  max-width: 1500px;
}
.page-head {
  display: flex; align-items: flex-end; gap: 16px; margin-bottom: 18px;
}
.page-head h1 { font-size: 25px; font-weight: 300; letter-spacing: -.01em; }
.page-head .sub { color: var(--muted); font-size: 13px; padding-bottom: 3px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; }

/* ── Flash ────────────────────────────────────────────────────────────── */
.flash {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; margin-bottom: 16px; border-radius: var(--radius);
  border-left: 3px solid; background: var(--white); box-shadow: var(--shadow);
  font-size: 13.5px;
}
.flash.success { border-color: var(--green); }
.flash.error   { border-color: var(--red); }
.flash.info    { border-color: var(--blue); }

/* ── Phase pipeline ───────────────────────────────────────────────────── */
.pipeline { display: flex; gap: 4px; margin-bottom: 18px; }
.pstep {
  flex: 1; min-width: 0; padding: 11px 14px;
  background: var(--white); border: 1px solid var(--line);
  border-top: 3px solid var(--line); border-radius: var(--radius);
}
.pstep .pname {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; margin-bottom: 2px;
}
.pstep .pcount { font-size: 20px; font-weight: 300; color: var(--navy); }
.pstep.done { border-top-color: var(--green); background: var(--surface); }
.pstep.done .pcount { color: var(--ink-2); }
.pstep.current { border-top-color: var(--blue); box-shadow: var(--shadow); }
.pstep.current .pname { color: var(--blue); font-weight: 700; }
.pstep.todo .pcount { color: var(--muted); }

/* ── KPI tiles ────────────────────────────────────────────────────────── */
.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 22px; }
.kpi {
  background: var(--white); border: 1px solid var(--line);
  border-top: 3px solid var(--blue); border-radius: var(--radius);
  padding: 13px 16px;
}
.kpi .k-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--muted);
}
.kpi .k-value { font-size: 27px; font-weight: 300; color: var(--navy); line-height: 1.35; }
.kpi .k-sub { font-size: 12px; color: var(--muted); }

/* ── Panels ───────────────────────────────────────────────────────────── */
.cols { display: grid; grid-template-columns: 3fr 2fr; gap: 20px; align-items: start; }
.panel {
  background: var(--white); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 20px; overflow: hidden;
}
.panel > header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--line-soft);
  background: var(--white);
}
.panel > header h2 {
  font-size: 11.5px; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--navy);
}
.panel > header .right { margin-left: auto; }
.panel .body { padding: 14px 16px; }
.panel .body.flush { padding: 0; }

.item-row {
  display: flex; align-items: baseline; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--line-soft); font-size: 13.5px;
}
.item-row:last-child { border-bottom: none; }
.item-row .meta { color: var(--muted); font-size: 12.5px; }
.item-row .meta-right { margin-left: auto; color: var(--muted); font-size: 12.5px; }
.reason {
  padding: 10px 16px; border-left: 3px solid var(--amber);
  border-bottom: 1px solid var(--line-soft); font-size: 13.5px;
}
.reason.red   { border-left-color: var(--red); }
.reason.green { border-left-color: var(--green); }
.empty { padding: 14px 16px; color: var(--muted); font-size: 13px; }

/* ── Tables ───────────────────────────────────────────────────────────── */
table.grid { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.grid thead th {
  position: sticky; top: 0; z-index: 1;
  text-align: left; padding: 10px 14px; background: var(--surface);
  border-bottom: 1px solid var(--line);
  font-size: 10.5px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted); white-space: nowrap;
}
table.grid thead th.sortable { cursor: pointer; user-select: none; }
table.grid thead th.sortable:hover { color: var(--blue); }
table.grid thead th .arrow { opacity: .35; margin-left: 4px; }
table.grid tbody td {
  padding: 10px 14px; border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
table.grid tbody tr:hover { background: var(--blue-wash); }
table.grid tbody tr.blocked td:first-child { color: var(--muted); }
table.grid .num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid .nowrap { white-space: nowrap; }
.table-scroll { overflow-x: auto; max-height: 70vh; overflow-y: auto; }

/* ── Badges & dots ────────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 10px;
  font-size: 11px; font-weight: 500; letter-spacing: .02em; white-space: nowrap;
  border: 1px solid transparent;
}
.badge.not_started { background: var(--surface); color: var(--muted); border-color: var(--line); }
.badge.in_progress { background: var(--blue-wash); color: var(--blue-dark); border-color: #BBD9F5; }
.badge.submitted   { background: #FDF3DC; color: #8A6100; border-color: #F2DFAE; }
.badge.accepted    { background: #EEF5DC; color: #4A6B03; border-color: #D6E5AE; }
.badge.blocked     { background: #FBEAEB; color: var(--red); border-color: #F0C4C6; }
.badge.open        { background: var(--blue-wash); color: var(--blue-dark); }
.badge.closed      { background: var(--surface); color: var(--muted); }
.badge.high        { background: #FBEAEB; color: var(--red); border-color: #F0C4C6; }
.badge.medium      { background: #FDF3DC; color: #8A6100; }
.badge.low         { background: var(--surface); color: var(--muted); }

.rag { display: inline-flex; align-items: center; gap: 9px; }
.rag .dot { width: 13px; height: 13px; border-radius: 50%; }
.rag.GREEN .dot { background: var(--green); }
.rag.AMBER .dot { background: var(--amber); }
.rag.RED   .dot { background: var(--red); }

.dot-sm { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; }

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 16px; font: inherit; font-size: 13px; font-weight: 500;
  border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--white); color: var(--ink); cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--blue); color: var(--blue-dark); text-decoration: none; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: var(--white); }
.btn.primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); color: var(--white); }
.btn.danger { color: var(--red); border-color: #F0C4C6; }
.btn.danger:hover { background: var(--red); border-color: var(--red); color: var(--white); }
.btn.small { padding: 5px 11px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ── Forms ────────────────────────────────────────────────────────────── */
.field { margin-bottom: 14px; }
.field label {
  display: block; font-size: 11.5px; font-weight: 600; color: var(--ink-2);
  margin-bottom: 5px;
}
.field input, .field select, .field textarea {
  width: 100%; padding: 8px 11px; font: inherit; font-size: 13.5px;
  color: var(--ink); background: var(--white);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(6,114,203,.14);
}
.field textarea { min-height: 74px; resize: vertical; }
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row.three { grid-template-columns: 1fr 1fr 1fr; }

/* ── Modal (native <dialog> — no library) ─────────────────────────────── */
dialog.modal {
  width: min(560px, calc(100vw - 40px)); padding: 0;
  border: none; border-radius: var(--radius); box-shadow: var(--shadow-lg);
  color: var(--ink);
}
dialog.modal::backdrop { background: rgba(0,38,62,.45); }
dialog.modal header {
  display: flex; align-items: center; padding: 15px 20px;
  border-bottom: 1px solid var(--line-soft);
}
dialog.modal header h3 { font-size: 16px; font-weight: 500; }
dialog.modal header .close {
  margin-left: auto; background: none; border: none; cursor: pointer;
  font-size: 22px; line-height: 1; color: var(--muted); padding: 0 4px;
}
dialog.modal header .close:hover { color: var(--ink); }
dialog.modal .modal-body { padding: 20px; max-height: 66vh; overflow-y: auto; }
dialog.modal footer {
  display: flex; justify-content: flex-end; gap: 9px;
  padding: 14px 20px; border-top: 1px solid var(--line-soft); background: var(--surface);
}
.modal-note {
  background: var(--surface); border-left: 3px solid var(--line);
  padding: 9px 12px; font-size: 12.5px; color: var(--ink-2); margin-bottom: 15px;
}
.modal-note.warn { border-left-color: var(--red); background: #FBEAEB; color: #7A1318; }

/* ── Report & chat ────────────────────────────────────────────────────── */
.report { background: var(--white); border: 1px solid var(--line); padding: 30px 36px; }
.report h1 { font-size: 22px; margin-bottom: 6px; }
.report h2 { font-size: 15px; margin: 22px 0 8px; padding-bottom: 5px;
             border-bottom: 1px solid var(--line-soft); }
.report ul { padding-left: 20px; line-height: 1.75; }
.report hr { border: none; border-top: 1px solid var(--line-soft); margin: 22px 0; }
.report em { color: var(--muted); font-size: 12.5px; }

.chat-log { display: flex; flex-direction: column; gap: 12px; margin-bottom: 18px; }
.msg { max-width: 76%; padding: 11px 15px; border-radius: var(--radius); font-size: 13.5px;
       line-height: 1.6; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--blue); color: var(--white); }
.msg.bot  { align-self: flex-start; background: var(--white); border: 1px solid var(--line); }
.chat-form { display: flex; gap: 9px; }
.chat-form input { flex: 1; padding: 10px 13px; font: inherit; font-size: 13.5px;
                   border: 1px solid var(--line); border-radius: var(--radius); }
.chat-form input:focus { outline: none; border-color: var(--blue); }

details.facts { margin-top: 20px; }
details.facts summary { cursor: pointer; color: var(--blue); font-size: 13px; }
details.facts pre {
  background: var(--navy); color: #D7E6F2; padding: 16px; border-radius: var(--radius);
  overflow-x: auto; font-size: 11.5px; line-height: 1.6; margin-top: 10px;
}

@media (max-width: 1200px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .cols { grid-template-columns: 1fr; }
}

/* ── Sign in ─────────────────────────────────────────────────────────────── */
.signin-page { background: var(--surface); }
.signin {
  min-height: calc(100vh - var(--masthead-h));
  display: flex; align-items: center; justify-content: center; padding: 32px 20px;
}
.signin-card { width: 100%; max-width: 400px; }
.signin-card .flash code {
  background: var(--white); padding: 1px 5px; border-radius: 2px;
  font-size: 12.5px; word-break: break-all;
}
.signin-card button[type="submit"] { width: 100%; justify-content: center; }
.signin-note {
  margin: 18px 0 0; padding-top: 14px; border-top: 1px solid var(--line-soft);
  font-size: 11.5px; line-height: 1.6; color: var(--muted);
}

/* ── Signed-in identity in the sidebar footer ────────────────────────────── */
.whoami {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(255,255,255,.12);
}
.whoami span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.whoami em { display: block; font-style: normal; opacity: .65; font-size: 10.5px;
             text-transform: uppercase; letter-spacing: .04em; }
.whoami button {
  flex: none; font: inherit; font-size: 11px; cursor: pointer; color: inherit;
  background: transparent; border: 1px solid rgba(255,255,255,.28);
  border-radius: var(--radius); padding: 4px 9px;
}
.whoami button:hover { border-color: var(--blue); color: var(--white); }

.inline-input { width: 128px; padding: 4px 8px; font: inherit; font-size: 12px;
                border: 1px solid var(--line); border-radius: var(--radius); }
.read-only-note {
  margin: 0 0 18px; padding: 9px 13px; font-size: 12.5px; color: var(--ink-2);
  background: var(--blue-wash); border-left: 3px solid var(--blue);
  border-radius: var(--radius);
}
fieldset.bare { border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset.bare[disabled] { opacity: .72; }

/* ── Generated documents ─────────────────────────────────────────────────── */
.panel.documents { margin-bottom: 20px; }
.doc-row {
  display: flex; align-items: center; gap: 14px; padding: 12px 18px;
  border-bottom: 1px solid var(--line-soft); color: inherit; text-decoration: none;
}
.doc-row:last-child { border-bottom: 0; }
.doc-row:hover { background: var(--blue-wash); text-decoration: none; }
.doc-ext {
  flex: none; width: 44px; padding: 5px 0; text-align: center; border-radius: var(--radius);
  font-size: 10px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--white); background: var(--muted);
}
.doc-ext.docx { background: #2B579A; }
.doc-ext.pptx { background: #C43E1C; }
.doc-ext.xlsx { background: #217346; }
.doc-text { flex: 1; min-width: 0; }
.doc-text strong { display: block; color: var(--navy); font-weight: 500; }
.doc-text em { font-style: normal; font-size: 12px; color: var(--muted); }
.doc-go { flex: none; font-size: 12px; color: var(--blue); font-weight: 500; }

/* Action column stays reachable when the grid is wider than the panel —
   without this the rightmost button scrolls out of sight and looks missing. */
.grid th:last-child, .grid td:last-child {
  position: sticky; right: 0; z-index: 1;
  background: var(--white); border-left: 1px solid var(--line-soft);
  white-space: nowrap; text-align: right;
}
.grid tbody tr:hover td:last-child { background: var(--blue-wash); }
.grid td:last-child .btn + .btn { margin-left: 6px; }

/* ── Milestone Completion Form on the phase gate ─────────────────────────── */
.panel .body.mcf { border-top: 1px solid var(--line-soft); background: var(--surface); }
.mcf-state { font-size: 13px; color: var(--ink-2); }
.mcf-state strong { color: var(--navy); font-weight: 500; }
.mcf-state .meta { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.mcf-state.ok strong { color: var(--green); }
.mcf-state.waiting strong { color: var(--blue-dark); }
.mcf-form { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.mcf-form input {
  padding: 5px 9px; font: inherit; font-size: 12.5px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--white);
}
.mcf-form input[type="text"] { flex: 1; min-width: 140px; }

label.choice { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 10px;
               font-weight: 400; text-transform: none; letter-spacing: 0; font-size: 13px; }
label.choice input { width: auto; margin-top: 3px; flex: none; }
label.choice strong { color: var(--navy); font-weight: 500; }
.chat-provider { font-size: 10.5px; opacity: .55; margin-top: -4px; }
.doc-row .doc-go.client { color: var(--muted); }
.doc-row .doc-go.client:hover { color: var(--blue); }
.doc-row:hover { background: var(--blue-wash); }
.doc-row .doc-go { padding: 2px 0 2px 14px; text-decoration: none; }
.doc-row .doc-go:hover { text-decoration: underline; }
.grid td .meta { display: inline-block; margin-left: 6px; font-size: 10.5px;
                 color: var(--muted); font-style: italic; }

/* Inline client-facing control on the RACI table */
.inline-set { display: inline-block; margin: 0; }
.cf-select {
  font: inherit; font-size: 12px; padding: 3px 6px; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--white); color: var(--ink-2); max-width: 172px;
}
.cf-select:hover { border-color: var(--blue); }
.cf-select.is-set {
  border-color: var(--blue); color: var(--blue-dark); font-weight: 500;
  background: var(--blue-wash);
}

/* SOW narrative sections on the ingest review screen */
.sow-section { border-bottom: 1px solid var(--line-soft); padding: 8px 0; }
.sow-section:last-of-type { border-bottom: 0; }
.sow-section summary { cursor: pointer; font-size: 13px; }
.sow-section summary .muted { margin-left: 8px; font-size: 11.5px; }
.sow-section ul { margin: 8px 0 4px; padding-left: 22px; font-size: 12.5px;
                  line-height: 1.65; color: var(--ink-2); }
.sow-section li { margin-bottom: 4px; }
