:root {
  --navy: #0b2a4a;
  --navy-2: #123a66;
  --bg: #f3f5f8;
  --border: #d9dee6;
  --text: #1c2733;
  --muted: #5f6b7a;
  --green: #2e9e4f;
  --yellow: #f2b705;
  --red: #d93a32;
  --green-bg: #e3f4e8;
  --yellow-bg: #fff4cc;
  --red-bg: #fbe3e1;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; }

/* Top bar */
.topbar { background: var(--navy); color: #fff; display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 52px; }
.brand { font-weight: 600; font-size: 17px; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { padding: 8px 14px; border-radius: 4px; color: #c9d6e6; }
.topbar nav a:hover, .topbar nav a.active { background: var(--navy-2); color: #fff; }
.week { font-size: 13px; color: #c9d6e6; }

main { max-width: 1280px; margin: 0 auto; padding: 18px 24px 40px; }

/* Page header band */
.pagehead { background: var(--navy); color: #fff; border-radius: 6px; padding: 12px 18px; display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.pagehead h1 { font-size: 20px; font-weight: 600; flex: 1; }
.pagehead .meta { font-size: 13px; color: #c9d6e6; }
.pagehead .btn { margin-left: 4px; }

/* Buttons */
.btn { font: inherit; border: 1px solid var(--border); background: #fff; color: var(--text); padding: 7px 14px; border-radius: 4px; cursor: pointer; }
.btn:hover { background: #eef2f7; }
.btn.primary { background: var(--navy-2); border-color: var(--navy-2); color: #fff; }
.btn.primary:hover { background: var(--navy); }
.btn.ghost { background: transparent; border-color: rgba(255,255,255,.5); color: #fff; }
.btn.ghost:hover { background: rgba(255,255,255,.15); }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn.danger { color: var(--red); }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 18px; }
.kpi { background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 12px 16px; border-left: 5px solid var(--navy-2); }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 28px; font-weight: 600; }
.kpi.green { border-left-color: var(--green); } .kpi.green .value { color: var(--green); }
.kpi.yellow { border-left-color: var(--yellow); } .kpi.yellow .value { color: #b78700; }
.kpi.red { border-left-color: var(--red); } .kpi.red .value { color: var(--red); }

/* Panels */
.panel { background: #fff; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.panel > h2 { background: var(--navy); color: #fff; font-size: 15px; font-weight: 600; padding: 8px 14px; display: flex; justify-content: space-between; align-items: center; }
.panel > .body { padding: 12px 14px; }
.section-title { display: flex; justify-content: space-between; align-items: center; background: var(--navy); color: #fff; padding: 8px 14px; border-radius: 6px 6px 0 0; }
.section-title h2 { font-size: 16px; font-weight: 600; }

/* SU cards */
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; background: #fff; border: 1px solid var(--border); border-top: 0; border-radius: 0 0 6px 6px; padding: 14px; }
.card { border: 1px solid var(--border); border-radius: 6px; padding: 14px 16px; cursor: pointer; background: #fff; }
.card:hover { border-color: var(--navy-2); box-shadow: 0 0 0 1px var(--navy-2); }
.card h3 { font-size: 16px; color: var(--navy); margin-bottom: 4px; }
.card .counts { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.card .legend { display: flex; gap: 14px; font-size: 13px; margin-top: 8px; }

/* Distribution bar */
.dist { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: #e8ebf0; }
.dist span.g { background: var(--green); } .dist span.y { background: var(--yellow); } .dist span.r { background: var(--red); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; }
.dot.green { background: var(--green); } .dot.yellow { background: var(--yellow); } .dot.red { background: var(--red); }

/* Badges */
.badge { display: inline-block; padding: 2px 10px; border-radius: 4px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.green { background: var(--green); color: #fff; }
.badge.yellow { background: var(--yellow); color: #3a2c00; }
.badge.red { background: var(--red); color: #fff; }

/* Tables */
table { border-collapse: collapse; width: 100%; background: #fff; }
.tablewrap { border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: #fff; }
th { background: var(--navy); color: #fff; text-align: left; font-weight: 600; padding: 9px 12px; font-size: 13px; }
td { padding: 9px 12px; border-top: 1px solid var(--border); vertical-align: top; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f1f5fa; }
td.num, th.num { text-align: right; }
.progress { display: flex; align-items: center; gap: 8px; min-width: 110px; }
.progress .bar { flex: 1; height: 8px; background: #e8ebf0; border-radius: 4px; overflow: hidden; }
.progress .bar i { display: block; height: 100%; }
.progress .bar i.green { background: var(--green); } .progress .bar i.yellow { background: var(--yellow); } .progress .bar i.red { background: var(--red); }
.plist div { margin-bottom: 2px; white-space: nowrap; }
.stale { color: var(--red); font-weight: 600; }
.muted { color: var(--muted); }

/* Team report grid */
.report { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.report .full { grid-column: 1 / -1; }
.subhead { font-weight: 600; color: var(--navy); margin: 8px 0 3px; font-size: 13px; }
.subhead:first-child { margin-top: 0; }
ul.tick { list-style: none; margin: 0; padding: 0; }
ul.tick li { padding: 2px 0 2px 18px; position: relative; font-size: 13px; }
ul.tick li::before { content: ""; position: absolute; left: 3px; top: 8px; width: 6px; height: 6px; border-radius: 50%; background: var(--navy-2); }
ul.tick.done li::before { background: var(--green); }
ul.tick.risk li::before { background: var(--red); }
.empty { color: var(--muted); font-style: italic; font-size: 13px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* Status indicators */
.indicators { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ind { padding: 12px 8px; border-radius: 5px; text-align: center; font-weight: 600; font-size: 13px; opacity: .3; border: 2px solid transparent; }
.ind.green { background: var(--green); color: #fff; } .ind.yellow { background: var(--yellow); color: #3a2c00; } .ind.red { background: var(--red); color: #fff; }
.ind.active { opacity: 1; border-color: var(--navy); }
.statusnote { margin-top: 10px; font-size: 13px; background: #f7f9fc; border-left: 4px solid var(--navy-2); padding: 7px 10px; }

/* Chart */
.chart svg { width: 100%; height: auto; display: block; }
.chart-legend { display: flex; gap: 16px; justify-content: center; font-size: 12px; color: var(--muted); }
.sw { display: inline-block; width: 10px; height: 10px; margin-right: 5px; }

/* Team details */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.chip { background: #eef2f7; border: 1px solid var(--border); border-radius: 12px; padding: 2px 10px; font-size: 12px; }
.chip small { color: var(--muted); }
table.compact th, table.compact td { padding: 5px 10px; font-size: 13px; }

/* Modal / form */
.modal-bg { position: fixed; inset: 0; background: rgba(11,42,74,.55); display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; padding: 30px 16px; z-index: 50; }
.modal { background: #fff; border-radius: 6px; width: 100%; max-width: 920px; }
.modal.narrow { max-width: 460px; }
.modal-head { background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 6px 6px 0 0; display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 16px 18px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; background: #f7f9fc; border-radius: 0 0 6px 6px; position: sticky; bottom: 0; }
fieldset { border: 1px solid var(--border); border-radius: 6px; margin: 0 0 14px; padding: 10px 14px 12px; }
legend { font-weight: 600; color: var(--navy); padding: 0 6px; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
input[type=text], input[type=number], input[type=password], select, textarea { font: inherit; width: 100%; padding: 6px 8px; border: 1px solid #b9c2cf; border-radius: 4px; background: #fff; color: var(--text); }
textarea { resize: vertical; min-height: 66px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.row { display: grid; gap: 8px; align-items: end; margin-bottom: 6px; }
.row.proj { grid-template-columns: 2fr 1.2fr 1fr auto; }
.row.mem { grid-template-columns: 1fr 1fr auto; }
.row.asg { grid-template-columns: 1fr 1.4fr .6fr auto; }
.row.item { grid-template-columns: 1fr auto; align-items: center; }
.radios { display: flex; gap: 10px; flex-wrap: wrap; }
.radios label { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 4px; font-size: 13px; color: var(--text); cursor: pointer; margin: 0; border: 2px solid transparent; }
.radios label.green { background: var(--green-bg); } .radios label.yellow { background: var(--yellow-bg); } .radios label.red { background: var(--red-bg); }
.hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
.err { color: var(--red); font-size: 13px; margin-top: 6px; }

/* Summary page */
.summary-actions { display: flex; gap: 8px; margin-bottom: 14px; align-items: center; flex-wrap: wrap; }
.summary { background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 20px 24px; }
.summary h2 { font-size: 16px; color: var(--navy); border-bottom: 2px solid var(--navy); padding-bottom: 4px; margin: 20px 0 8px; }
.summary h2:first-of-type { margin-top: 0; }
.summary p { margin: 6px 0; line-height: 1.5; }
.summary .tablewrap { margin: 6px 0; }
.attn { border-left: 5px solid; padding: 8px 12px; margin: 8px 0; background: #fafbfc; }
.attn.red { border-color: var(--red); } .attn.yellow { border-color: var(--yellow); }
.attn .t { font-weight: 600; margin-bottom: 2px; }
.placeholder { text-align: center; padding: 50px 20px; color: var(--muted); background: #fff; border: 1px dashed var(--border); border-radius: 6px; }

/* ---------- One-screen layout: app fills the viewport; only inner panels scroll if needed ---------- */
html, body { height: 100%; }
body { display: flex; flex-direction: column; overflow: hidden; font-size: 13px; }
.topbar { flex: none; height: 44px; }
main { flex: 1; min-height: 0; width: 100%; max-width: 1600px; padding: 10px 16px 12px; }
.fit { height: 100%; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.fit > * { flex: none; }
.pagehead { margin-bottom: 0; padding: 8px 14px; }
.pagehead h1 { font-size: 18px; }
.kpis { margin-bottom: 0; gap: 10px; }
.kpi { padding: 6px 14px; }
.kpi .value { font-size: 22px; line-height: 1.2; }
.scroll { overflow: auto; flex: 1 1 auto; min-height: 0; }
.fit > .tablewrap.scroll { flex: 1 1 auto; }
.tablewrap.scroll thead th, .tablewrap.scroll tr:first-child th { position: sticky; top: 0; z-index: 1; }
td, th { padding: 7px 12px; }

/* Portfolio: cards left, latest updates right */
.split { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: 1.7fr 1fr; gap: 12px; }
.split .col { display: flex; flex-direction: column; min-height: 0; }
.split .cards { flex: 1 1 auto; min-height: 0; overflow: auto; grid-template-columns: repeat(3, 1fr); grid-auto-rows: min-content; align-content: start; gap: 10px; padding: 10px; }
.card { padding: 10px 12px; }
.card h3 { font-size: 14px; margin-bottom: 2px; }
.card .counts { margin-bottom: 6px; font-size: 12px; }
.card .legend { margin-top: 5px; font-size: 12px; }
.split .col > .tablewrap { border-top: 0; border-radius: 0 0 6px 6px; }

/* Team report: 2 columns x 3 rows, all visible */
.report { flex: 1 1 auto; min-height: 0; gap: 10px; grid-template-columns: 1fr 1fr 1fr; grid-template-rows: minmax(0, 1.3fr) minmax(0, 1fr); grid-template-areas: "a b c" "d e e"; }
.report .panel { display: flex; flex-direction: column; min-height: 0; }
.report .panel > .body { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 8px 12px; }
.report .panel > h2 { padding: 6px 12px; font-size: 14px; }
.pa { grid-area: a; } .pb { grid-area: b; } .pc { grid-area: c; } .pd { grid-area: d; } .pe { grid-area: e; }
.report .chart svg { max-height: 100%; }
.report .chart { display: flex; flex-direction: column; justify-content: center; }
.report .chart svg { flex: 1 1 auto; min-height: 0; }
.subhead { margin: 6px 0 2px; }
ul.tick li { padding: 1px 0 1px 16px; font-size: 12.5px; line-height: 1.35; }
ul.tick li::before { top: 7px; }
.pe .two { gap: 12px; }
.indicators { gap: 8px; }
.ind { padding: 8px 6px; font-size: 12px; }
table.compact th, table.compact td { padding: 3px 8px; font-size: 12px; }
.statusnote { margin-top: 6px; padding: 5px 8px; }

/* Summary page: generator bar fixed, report scrolls */
.genbar .body { padding: 8px 12px; }
.genrow { display: flex; gap: 14px; align-items: flex-end; }
.genrow textarea { min-height: 38px; height: 38px; }
.genrow .summary-actions { margin: 0; flex: none; }
.summarywrap { background: transparent; }

/* Update form tabs */
.modal-bg { align-items: center; padding: 16px; overflow: hidden; }
.modal { display: flex; flex-direction: column; max-height: 100%; }
.modal-head, .modal-foot { flex: none; }
.modal-body { flex: 1 1 auto; overflow: auto; min-height: 0; padding: 12px 18px; }
.modal.narrow { max-height: none; }
.tabs { flex: none; display: flex; gap: 2px; padding: 8px 18px 0; background: #eef2f7; border-bottom: 1px solid var(--border); }
.tab { font: inherit; border: 1px solid var(--border); border-bottom: 0; background: #e2e8f0; color: var(--muted); padding: 7px 14px; border-radius: 4px 4px 0 0; cursor: pointer; }
.tab:hover { background: #fff; }
.tab.active { background: #fff; color: var(--navy); font-weight: 600; margin-bottom: -1px; }
.tab:last-child { margin-left: auto; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.row.projw { grid-template-columns: 1fr 120px 80px; align-items: center; }
.row.projw .pname { font-size: 13px; overflow: hidden; text-overflow: ellipsis; }


/* Toast */
.toast { position: fixed; bottom: 22px; right: 22px; background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 4px; z-index: 100; }

/* Narrow windows / short screens: fall back to normal page scrolling */
@media (max-width: 1100px), (max-height: 600px) {
  body { overflow: auto; height: auto; display: block; }
  main { height: auto; }
  .fit { height: auto; }
  .split { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .split .cards { grid-template-columns: repeat(2, 1fr); }
  .report { grid-template-columns: 1fr; grid-template-rows: none; grid-template-areas: "a" "b" "d" "c" "e"; }
  .report .panel > .body { overflow: visible; }
  .two, .grid2, .grid3 { grid-template-columns: 1fr; }
}
@media print {
  .topbar, .summary-actions, .genbar, .btn { display: none !important; }
  html, body { height: auto; overflow: visible; background: #fff; display: block; }
  main, .fit, .scroll { height: auto; overflow: visible; }
}

/* Admin / AI insights */
.aibar { flex: none; }
.aibar .body { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 7px 12px; }
.aibar .spacer { flex: 1; }
.adminchip { background: #ede9fe; color: #5b3fc4; border-radius: 10px; padding: 1px 9px; font-size: 11px; font-weight: 600; }
.okchip { background: var(--green-bg); color: #1d6b36; border-radius: 10px; padding: 1px 9px; font-size: 12px; font-weight: 600; }
.warnchip { background: var(--yellow-bg); color: #7a5a00; border-radius: 10px; padding: 1px 9px; font-size: 12px; font-weight: 600; }
.aisummary { margin-bottom: 12px; border-left: 5px solid #7c5cd8; }
.aihead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.olist { margin: 4px 0 8px 20px; padding: 0; }
.olist li { padding: 2px 0; }
.reckey { font-family: Consolas, monospace; font-size: 18px; letter-spacing: 1px; background: #f3f5f8; border: 1px dashed var(--navy-2); border-radius: 4px; padding: 10px; text-align: center; user-select: all; margin: 8px 0; }
code { background: #eef2f7; border-radius: 3px; padding: 0 4px; font-size: 12px; }

/* AI settings: model picker + connection test */
.modelrow { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.airesult { margin-top: 10px; padding: 8px 10px; border-radius: 4px; font-size: 13px; border-left: 4px solid; line-height: 1.5; }
.airesult.ok { background: var(--green-bg); border-color: var(--green); }
.airesult.warn { background: var(--yellow-bg); border-color: var(--yellow); }
.airesult.bad { background: var(--red-bg); border-color: var(--red); }
.airesult.info { background: #eef2f7; border-color: var(--navy-2); }

/* Weekly PDF panel */
.aibar .pdfbody { display: block; }
.pdfhead { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pdfhead .spacer { flex: 1; }
.pdfbody .inl { display: inline-flex; align-items: center; gap: 5px; margin: 0; font-weight: 400; font-size: 12.5px; color: var(--muted); }
.pdfbody .inl input { width: auto; margin: 0; }
.pdfbody .tablewrap { max-height: 150px; overflow: auto; }
.pdfbody td.actions { white-space: nowrap; text-align: right; }
@media print { .pdfbody { display: none !important; } }

/* Team report: A-E fill one screen, F (history) sits below inside the scroll area */
.teamscroll { flex: 1 1 auto; min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.teamscroll > .report { flex: none; height: 100%; min-height: 430px; }
.teamscroll > .hist { flex: none; }
.hist .body { padding: 8px 12px; }
.hstrip { display: grid; grid-template-columns: repeat(52, 1fr); gap: 3px; margin-bottom: 6px; }
.hstrip i { display: block; height: 16px; border-radius: 2px; background: #e5e7eb; }
.hstrip i.green { background: var(--green); } .hstrip i.yellow { background: var(--yellow); } .hstrip i.red { background: var(--red); }
.hlegend { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.hlegend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; background: #e5e7eb; }
.hlegend i.green { background: var(--green); } .hlegend i.yellow { background: var(--yellow); } .hlegend i.red { background: var(--red); }
.histtable { max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: 4px; }
.histtable th { position: sticky; top: 0; z-index: 1; }
.codebox { display: inline-flex; align-items: center; gap: 6px; margin-right: auto; font-size: 12px; color: var(--muted); }
.codebox label { margin: 0; } .codebox input { width: 150px; margin: 0; }
@media (max-width: 1100px), (max-height: 600px) { .teamscroll { overflow: visible; } .teamscroll > .report { height: auto; } }
@media print { .teamscroll { overflow: visible; } .teamscroll > .report { height: auto; } .hist { display: none; } }
/* Summary page toolbar */
.tb { flex: none; background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; }
.tb:not(:has(.tbrow)) { flex-direction: row; align-items: center; gap: 10px; }
.tb .spacer { flex: 1; }
.tbrow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tb .inl { display: inline-flex; align-items: center; gap: 5px; margin: 0; font-size: 12.5px; color: var(--muted); }
.tb .inl input { width: auto; margin: 0; }
.tbhint { font-size: 12.5px; color: var(--muted); }
.tbhint.warn { color: #7a5a00; background: var(--yellow-bg); border-radius: 4px; padding: 5px 9px; }
.tb .airesult { margin: 0; }
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; display: inline-block; }
.menu > summary::-webkit-details-marker { display: none; }
.menupop { position: absolute; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--border); border-radius: 6px; min-width: 170px; z-index: 20; padding: 4px; box-shadow: 0 4px 14px rgba(0,0,0,.15); }
.menupop button { display: block; width: 100%; text-align: left; font: inherit; background: none; border: 0; padding: 7px 10px; border-radius: 4px; cursor: pointer; color: var(--text); }
.menupop button:hover { background: #eef2f7; }
.files > summary { cursor: pointer; font-size: 12.5px; color: var(--navy-2); }
.files .tablewrap { max-height: 150px; overflow: auto; margin-top: 6px; }
.files td.actions { white-space: nowrap; text-align: right; }
@media print { .tb { display: none !important; } }
