:root {
  --brand: #23586a;
  --brand-ink: #173e4b;
  --brand-soft: #e6eff2;
  --ok: #34704c;
  --ok-soft: #e4f1e8;
  --danger: #ab3636;
  --danger-soft: #f8e5e5;
  --warn: #8a5a00;
  --warn-soft: #fdf3dc;
  --ink: #1d2730;
  --ink-2: #46525d;
  --ink-3: #6b7782;
  --line: #d9e0e5;
  --line-2: #e9eef1;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --new-trial: #e3f1f7;
  --new-trial-edge: #8cc3d9;
  --modification: #ebf5e4;
  --modification-edge: #9cc98a;
  --commercial: #f3eaf4;
  --commercial-edge: #a77aa9;
  --noncommercial: #fbede0;
  --noncommercial-edge: #d99a63;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 32, 48, .06), 0 4px 16px rgba(16, 32, 48, .06);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.4; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.boot { padding: 48px; color: var(--ink-3); }
.muted { color: var(--ink-3); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.grow { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.hidden { display: none !important; }

/* ---------- Shell ---------- */
.env-banner { background: #b45309; color: #fff; text-align: center; font-weight: 600; padding: 3px; font-size: 12px; letter-spacing: .06em; }
.topbar { background: var(--brand-ink); color: #fff; display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 52px; position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 700; letter-spacing: .01em; white-space: nowrap; }
.brand small { font-weight: 400; opacity: .7; margin-left: 6px; }
.nav { display: flex; gap: 2px; height: 100%; overflow-x: auto; flex: 1 1 auto; min-width: 0; scrollbar-width: thin; }
.nav a { color: #d6e5ea; text-decoration: none; padding: 0 12px; display: flex; align-items: center; border-bottom: 3px solid transparent; white-space: nowrap; }
.nav a:hover { color: #fff; }
.nav a.active { color: #fff; border-bottom-color: #8cc3d9; font-weight: 600; }
.nav .group { color: #8fb2bd; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; padding: 0 6px 0 14px; display: flex; align-items: center; }
.userbox { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; color: #d6e5ea; white-space: nowrap; }
.userbox .role { background: rgba(255,255,255,.12); padding: 2px 8px; border-radius: 99px; font-size: 11.5px; }
.userbox button { background: transparent; border: 1px solid rgba(255,255,255,.3); color: #fff; border-radius: 6px; padding: 4px 10px; cursor: pointer; }
main { padding: 20px; max-width: 1680px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--ink-3); }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.notice { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; border: 1px solid; }
.notice.info { background: var(--brand-soft); border-color: #c4d8df; }
.notice.warn { background: var(--warn-soft); border-color: #efd7a1; color: #5c3d00; }
.notice.error { background: var(--danger-soft); border-color: #e9b9b9; color: #6d1f1f; }

/* ---------- Controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-radius: 6px; border: 1px solid var(--line); background: #fff; padding: 6px 12px; cursor: pointer; white-space: nowrap; line-height: 1.2; min-height: 32px; }
.btn:hover:not(:disabled) { border-color: #b7c4cc; background: #f8fafb; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--brand-ink); }
.btn.authorise { background: var(--ok); border-color: var(--ok); color: #fff; border-radius: 999px; }
.btn.objection { background: var(--danger); border-color: var(--danger); color: #fff; border-radius: 999px; }
.btn.authorise:hover:not(:disabled), .btn.objection:hover:not(:disabled) { filter: brightness(.92); background-color: inherit; }
.btn.authorise:hover:not(:disabled) { background: var(--ok); }
.btn.objection:hover:not(:disabled) { background: var(--danger); }
.btn.fea { border-radius: 999px; color: #fff; border: 0; font-size: 12.5px; min-height: 28px; padding: 4px 12px; }
.btn.fea.setup { background: #23586a; }
.btn.fea.review { background: #495f3d; }
.btn.small { min-height: 26px; padding: 3px 9px; font-size: 12.5px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--line-2); }
.btn.danger-text { color: var(--danger); }
.icon-btn { border: 0; background: transparent; cursor: pointer; padding: 4px 6px; border-radius: 5px; color: var(--ink-2); }
.icon-btn:hover { background: var(--line-2); }

label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); font-weight: 600; }
label.field > span.hint { font-weight: 400; color: var(--ink-3); font-size: 12px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  border: 1px solid #c6d0d6; border-radius: 6px; padding: 6px 9px; background: #fff; min-height: 34px; font-weight: 400; color: var(--ink); width: 100%;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid #7fb2c4; outline-offset: 1px; }
input:disabled, select:disabled, textarea:disabled { background: #e8eaec; color: var(--ink-3); }
input.invalid, select.invalid, textarea.invalid { border-color: var(--danger); background: #fff8f8; }
.check { display: inline-flex; align-items: center; gap: 7px; font-weight: 400; color: var(--ink); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }
.radio-group { display: flex; gap: 6px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid #c6d0d6; border-radius: 6px; overflow: hidden; }
.seg label { padding: 6px 14px; cursor: pointer; font-weight: 400; color: var(--ink); border-right: 1px solid #c6d0d6; }
.seg label:last-child { border-right: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--brand); color: #fff; }
.seg label:has(input:focus-visible) { outline: 2px solid #7fb2c4; outline-offset: -2px; }
.seg.disabled { opacity: .6; pointer-events: none; }

.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }

/* ---------- Tables ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-pad { padding: 16px; }
.table-wrap { overflow-x: auto; }
table.data { border-collapse: separate; border-spacing: 0; width: 100%; }
table.data th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); font-weight: 600; padding: 9px 10px; border-bottom: 1px solid var(--line); background: #fafbfc; position: sticky; top: 0; white-space: nowrap; }
table.data td { padding: 8px 10px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tr.type-new td { background: var(--new-trial); }
table.data tr.type-new td:first-child { box-shadow: inset 4px 0 0 var(--new-trial-edge); }
table.data tr.type-mod td { background: var(--modification); }
table.data tr.type-mod td:first-child { box-shadow: inset 4px 0 0 var(--modification-edge); }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { filter: brightness(.97); }
table.data .desc { max-width: 280px; }
.empty { padding: 36px; text-align: center; color: var(--ink-3); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; border: 1px solid transparent; white-space: nowrap; }
.badge.draft { background: var(--warn-soft); color: var(--warn); border-color: #efd7a1; }
.badge.complete { background: var(--ok-soft); color: var(--ok); border-color: #b9dbc4; }
.badge.neutral { background: var(--line-2); color: var(--ink-2); }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: #e9b9b9; }
.badge.brand { background: var(--brand-soft); color: var(--brand); border-color: #c4d8df; }
.toolbar { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.toolbar input[type=search] { max-width: 280px; }
.toolbar select, .actions select, .actions input[type=search] { width: auto; }
.actions input[type=search] { min-width: 220px; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 32, 40, .45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 50; }
.modal { background: #fff; border-radius: 10px; box-shadow: 0 12px 48px rgba(0,0,0,.25); width: 100%; max-width: 560px; display: flex; flex-direction: column; max-height: calc(100vh - 80px); }
.modal.wide { max-width: 860px; }
.modal.xwide { max-width: 1100px; }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { flex: 1; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; align-items: center; padding: 12px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; background: #fafbfc; border-radius: 0 0 10px 10px; }
.modal-foot .left { margin-right: auto; }
.form-error { color: var(--danger); background: var(--danger-soft); border: 1px solid #e9b9b9; border-radius: 6px; padding: 8px 12px; margin-bottom: 12px; }
.summary-list { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
.summary-list dt { color: var(--ink-3); }
.summary-list dd { margin: 0; font-weight: 600; }

#toasts { position: fixed; right: 16px; top: 64px; display: flex; flex-direction: column; gap: 8px; z-index: 80; max-width: 420px; }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); animation: toast-in .18s ease-out; }
.toast.ok { background: var(--ok); }
.toast.error { background: var(--danger); }
@keyframes toast-in { from { transform: translateY(6px); opacity: 0; } }

/* ---------- Sign in ---------- */
.signin { max-width: 400px; margin: 10vh auto; }
.signin h1 { margin-bottom: 4px; }

/* ---------- Assessment ---------- */
.fea-head { display: grid; grid-template-columns: auto 1fr; gap: 22px; align-items: center; padding: 18px; }
.fea-head img { height: 190px; width: auto; aspect-ratio: 1448 / 1086; border-radius: 8px; object-fit: contain; background: #f2efe9; }
.fea-head h1 { font-size: 22px; color: var(--brand-ink); }
.fea-meta { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px 18px; margin-top: 12px; }
.fea-meta div span { display: block; font-size: 11.5px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; }
.fea-meta div strong { font-weight: 600; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); padding: 0 12px; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 11px 14px; cursor: pointer; border-bottom: 3px solid transparent; color: var(--ink-2); white-space: nowrap; }
.tabs button.active { color: var(--brand-ink); border-bottom-color: var(--brand); font-weight: 600; }
.tabs button .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--danger); margin-left: 6px; vertical-align: middle; }
.tab-body { padding: 20px; }
.fea-section + .fea-section { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line-2); }
.fea-section h3 { margin-bottom: 12px; color: var(--brand-ink); }
.fea-footer { display: flex; gap: 10px; align-items: center; padding: 12px 18px; border-top: 1px solid var(--line); background: #fafbfc; border-radius: 0 0 var(--radius) var(--radius); position: sticky; bottom: 0; flex-wrap: wrap; }
.fea-footer .status { margin-right: auto; color: var(--ink-2); }
.fea-footer .status.dirty { color: var(--warn); font-weight: 600; }
.med-layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.med-editor { background: #fafbfc; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.med-editor.editing { border-color: #e2b85c; background: #fffbf1; }
table.data tr.selected td { background: #fff4d6 !important; }
.yn-detail { display: grid; grid-template-columns: 260px 1fr; gap: 10px 16px; align-items: start; }
.yn-detail > .label { font-weight: 600; color: var(--ink-2); padding-top: 6px; }
.risk-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 18px; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline > * { flex: 0 0 auto; }
.inline input[type=number] { width: 100px; }
.inline select { width: auto; min-width: 120px; }
.revision-list td { white-space: nowrap; }
.readonly-banner { background: var(--warn-soft); color: #5c3d00; padding: 8px 18px; border-bottom: 1px solid #efd7a1; }

/* ---------- Email composer ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 36px; padding: 5px; border: 1px solid #c6d0d6; border-radius: 6px; background: #fff; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--brand-soft); border: 1px solid #c4d8df; border-radius: 99px; padding: 2px 4px 2px 10px; font-size: 12.5px; }
.chip button { border: 0; background: transparent; cursor: pointer; padding: 0 5px; color: var(--ink-3); font-size: 15px; line-height: 1; }
.picker-list { max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; }
.picker-list label { display: flex; gap: 10px; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--line-2); cursor: pointer; font-weight: 400; }
.picker-list label:hover { background: #f6f9fa; }
.picker-list .cat { margin-left: auto; font-size: 11.5px; color: var(--ink-3); }
.email-steps { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.option-cards { display: grid; gap: 8px; }
.option-card { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; cursor: pointer; font-weight: 400; color: var(--ink); }
.option-card:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.option-card input { margin-top: 3px; accent-color: var(--brand); }
.option-card small { display: block; color: var(--ink-3); }
.task-picker { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 10px; }
.task-picker fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.task-picker legend { font-weight: 600; color: var(--ink-2); padding: 0 4px; }

/* ---------- PACT set-up ---------- */
.setup-list { display: flex; flex-direction: column; gap: 14px; }
.setup-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.setup-card.commercial { border-left: 5px solid var(--commercial-edge); }
.setup-card.noncommercial { border-left: 5px solid var(--noncommercial-edge); }
.setup-card-head { display: flex; gap: 16px; align-items: center; padding: 12px 16px; flex-wrap: wrap; }
.setup-card.commercial .setup-card-head { background: var(--commercial); }
.setup-card.noncommercial .setup-card-head { background: var(--noncommercial); }
.setup-card-head h3 { font-size: 16px; }
.setup-card-head .meta { color: var(--ink-2); font-size: 13px; }
.progress { width: 140px; height: 8px; background: #dfe5e9; border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--ok); }
.sections { display: grid; grid-template-columns: repeat(8, minmax(150px, 1fr)); gap: 0; overflow-x: auto; }
.section-tile { padding: 10px 12px; border-right: 1px solid var(--line-2); border-top: 1px solid var(--line-2); display: flex; flex-direction: column; gap: 6px; min-width: 150px; }
.section-tile:last-child { border-right: 0; }
.section-tile.done { background: #f2f8f4; }
.section-tile h4 { font-size: 13px; display: flex; align-items: center; gap: 6px; }
.section-tile h4 .tick { color: var(--ok); font-size: 16px; }
.section-tile label { font-size: 11.5px; color: var(--ink-3); display: flex; flex-direction: column; gap: 2px; }
.section-tile select { min-height: 30px; padding: 3px 6px; font-size: 13px; }
.section-tile .done-line { font-size: 11.5px; color: var(--ok); }
.kpi-btn { font-size: 12px; }
.kpi-btn.flagged { background: var(--warn-soft); border-color: #e2c27a; color: #5c3d00; }

@media (max-width: 1500px) {
  .brand small { display: none; }
}
@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fea-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .med-layout { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  main { padding: 12px; }
  .g2, .g3, .g4, .risk-grid, .task-picker { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .fea-head { grid-template-columns: 1fr; }
  .fea-head img { height: auto; width: 100%; max-width: 360px; }
  .yn-detail { grid-template-columns: 1fr; }
  .topbar { gap: 10px; padding: 0 10px; }
  .brand { font-size: 13px; }
  .userbox > span:first-child, .userbox .role { display: none; }
  .fea-meta { grid-template-columns: 1fr 1fr; }
  .fea-footer { position: static; }
  table.data td, table.data th { padding: 6px 8px; }
}
@media print {
  .topbar, .fea-footer, .tabs, #toasts { display: none !important; }
}
