/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-1); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h3 { font-size: 14px; }
.card-head .sub { font-size: 12px; color: var(--text-muted); font-weight: 400; }
.card-body { padding: 16px; }
.card-body.flush { padding: 0; }
.card-foot { padding: 10px 16px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }

/* KPI tiles */
.kpi { padding: 14px 16px; }
.kpi .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
.kpi .value { font-size: 24px; font-weight: 700; color: var(--navy-900); margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .hint { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.kpi.accent { border-top: 3px solid var(--teal-600); }
.kpi.warn { border-top: 3px solid var(--amber-700); }
.kpi.danger { border-top: 3px solid var(--red-700); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 13px; border-radius: var(--r-md); border: 1px solid var(--border-strong); background: #fff; color: var(--grey-900); font: inherit; font-size: 13px; font-weight: 550; cursor: pointer; white-space: nowrap; user-select: none; }
.btn:hover { background: var(--grey-50); border-color: var(--grey-400); text-decoration: none; }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn svg { width: 15px; height: 15px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.teal { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.teal:hover { background: var(--teal-700); }
.btn.danger { color: var(--red-700); border-color: #e9b8bb; }
.btn.danger:hover { background: var(--red-100); }
.btn.danger.solid { background: var(--red-700); color: #fff; border-color: var(--red-700); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--grey-100); }
.btn.sm { height: 26px; padding: 0 9px; font-size: 12px; }
.btn.xs { height: 22px; padding: 0 7px; font-size: 11.5px; border-radius: 4px; }
.btn[disabled], .btn.disabled { opacity: .45; cursor: not-allowed; pointer-events: auto; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--r-md) 0 0 var(--r-md); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--r-md) var(--r-md) 0; }

/* Badges / statuses */
.badge { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 8px; border-radius: 10px; font-size: 11px; font-weight: 600; background: var(--grey-150); color: var(--grey-700); white-space: nowrap; letter-spacing: .01em; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.plain::before { display: none; }
.badge.s-draft { background: var(--grey-150); color: var(--grey-700); }
.badge.s-in_review { background: var(--blue-100); color: var(--blue-700); }
.badge.s-returned { background: var(--amber-100); color: var(--amber-700); }
.badge.s-reviewed { background: var(--violet-100); color: var(--violet-700); }
.badge.s-approved { background: var(--green-100); color: var(--green-700); }
.badge.s-final { background: var(--navy-900); color: #fff; }
.badge.ok { background: var(--green-100); color: var(--green-700); }
.badge.warn { background: var(--amber-100); color: var(--amber-700); }
.badge.danger { background: var(--red-100); color: var(--red-700); }
.badge.info { background: var(--blue-100); color: var(--blue-700); }
.badge.teal { background: var(--teal-100); color: var(--teal-700); }
.badge.navy { background: var(--navy-100); color: var(--navy-800); }
.tag { display: inline-block; padding: 1px 6px; border-radius: 4px; background: var(--navy-50); border: 1px solid var(--navy-100); color: var(--navy-800); font-size: 11px; margin: 1px 2px 1px 0; white-space: nowrap; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 12.8px; }
.tbl th { text-align: left; font-weight: 600; color: var(--grey-700); background: var(--surface-2); border-bottom: 1px solid var(--border); padding: 8px 10px; font-size: 11.8px; white-space: nowrap; position: sticky; top: 0; z-index: 1; }
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--navy-800); }
.tbl th .arrow { font-size: 9px; margin-left: 3px; color: var(--teal-600); }
.tbl td { padding: 7px 10px; border-bottom: 1px solid var(--grey-150); vertical-align: top; }
.tbl tbody tr:hover td { background: #fafcfe; }
.tbl tr.clickable { cursor: pointer; }
.tbl tfoot td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--border-strong); }
.tbl td.num, .tbl th.num { text-align: right; }
.tbl tr.total td { font-weight: 700; border-top: 1px solid var(--grey-400); }
.tbl tr.subtotal td { font-weight: 600; background: var(--grey-50); }
.tbl tr.group td { font-weight: 700; color: var(--navy-800); background: var(--navy-50); text-transform: uppercase; font-size: 11px; letter-spacing: .05em; }
.tbl tr.flag td { background: #fff8ec; }
.tbl tr.err td { background: #fff2f2; }
.tbl input, .tbl select { height: 28px; font-size: 12.5px; }
.tbl.compact td, .tbl.compact th { padding: 5px 8px; }
.dt-toolbar { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.dt-toolbar input[type=search] { width: 240px; }
.dt-foot { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; font-size: 12px; color: var(--text-muted); gap: 8px; flex-wrap: wrap; }
.empty { padding: 34px 16px; text-align: center; color: var(--text-muted); }
.empty svg { width: 34px; height: 34px; color: var(--grey-400); display: block; margin: 0 auto 8px; }

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 9px 14px; font: inherit; font-size: 13px; color: var(--grey-600); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 550; }
.tabs button:hover { color: var(--navy-800); }
.tabs button.active { color: var(--navy-900); border-bottom-color: var(--teal-600); }
.tabs button .count { margin-left: 6px; font-size: 10.5px; background: var(--grey-150); padding: 1px 6px; border-radius: 8px; }

/* Collapsible */
details.section { background: #fff; border: 1px solid var(--border); border-radius: var(--r-lg); margin-bottom: 12px; }
details.section > summary { list-style: none; cursor: pointer; padding: 11px 16px; font-weight: 650; color: var(--navy-900); display: flex; align-items: center; gap: 8px; }
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::before { content: "▸"; color: var(--teal-600); transition: transform .15s; font-size: 12px; }
details.section[open] > summary::before { transform: rotate(90deg); }
details.section > summary .sec-meta { margin-left: auto; font-weight: 400; font-size: 12px; color: var(--text-muted); }
details.section > .sec-body { padding: 4px 16px 16px; border-top: 1px solid var(--grey-150); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(8, 23, 43, .48); display: grid; place-items: center; z-index: 1000; padding: 20px; animation: fade .12s ease-out; }
.modal { background: #fff; border-radius: 12px; box-shadow: var(--shadow-3); width: min(640px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column; }
.modal.lg { width: min(940px, 100%); } .modal.xl { width: min(1200px, 100%); } .modal.sm { width: min(440px, 100%); }
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { font-size: 15.5px; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; background: var(--surface-2); border-radius: 0 0 12px 12px; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* Toasts */
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 1100; }
.toast { min-width: 280px; max-width: 420px; background: var(--navy-900); color: #fff; padding: 11px 14px; border-radius: 8px; box-shadow: var(--shadow-2); font-size: 13px; border-left: 4px solid var(--teal-500); animation: slidein .18s ease-out; }
.toast.error { border-left-color: #ff6b70; } .toast.warn { border-left-color: #f2b84b; } .toast.success { border-left-color: #43c47a; }
.toast b { display: block; margin-bottom: 2px; }
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Alerts / callouts */
.alert { padding: 10px 14px; border-radius: 8px; border: 1px solid; font-size: 12.8px; margin-bottom: 12px; }
.alert.info { background: var(--blue-100); border-color: #bcd0f3; color: #183d80; }
.alert.warn { background: var(--amber-100); border-color: #efd396; color: #6b4600; }
.alert.danger { background: var(--red-100); border-color: #efb9bc; color: #7e1b21; }
.alert.ok { background: var(--green-100); border-color: #b2dfc2; color: #17532f; }
.alert.draft { background: #fff7e6; border: 1px dashed #e0b44f; color: #6b4600; }
.alert ul { margin: 6px 0 0 18px; padding: 0; }

/* Progress */
.progress { height: 7px; background: var(--grey-150); border-radius: 4px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--teal-600), var(--teal-500)); border-radius: 4px; }
.stages { display: grid; grid-template-columns: repeat(11, minmax(0, 1fr)); gap: 4px; }
.stage { padding: 8px 6px; border-radius: 6px; background: var(--grey-100); border: 1px solid var(--grey-200); text-align: center; font-size: 11px; color: var(--grey-600); cursor: pointer; min-height: 58px; }
.stage .n { font-weight: 700; font-size: 12px; display: block; }
.stage.done { background: var(--teal-50); border-color: var(--teal-100); color: var(--teal-700); }
.stage.current { background: var(--navy-800); border-color: var(--navy-800); color: #fff; }
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { display: flex; gap: 8px; padding: 5px 0; font-size: 12.8px; border-bottom: 1px dashed var(--grey-150); align-items: flex-start; }
.checklist li .ic { flex: none; width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center; font-size: 10px; margin-top: 1px; }
.checklist li.ok .ic { background: var(--green-100); color: var(--green-700); }
.checklist li.no .ic { background: var(--red-100); color: var(--red-700); }
.checklist li.warn .ic { background: var(--amber-100); color: var(--amber-700); }

/* Bars (analytics) */
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 160px 1fr 70px; gap: 8px; align-items: center; font-size: 12px; }
.bar-row .track { height: 14px; background: var(--grey-100); border-radius: 3px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--navy-700); border-radius: 3px; }
.bar-row .fill.teal { background: var(--teal-600); }
.bar-row .fill.amber { background: #d29a2c; }

/* Timeline / log */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 7px 0 7px 16px; border-left: 2px solid var(--grey-200); position: relative; font-size: 12.5px; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 12px; width: 8px; height: 8px; border-radius: 50%; background: var(--teal-600); }
.timeline li .when { color: var(--text-muted); font-size: 11.5px; }

/* Notes */
.note { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; background: #fff; }
.note.open { border-left: 3px solid var(--amber-700); }
.note.responded { border-left: 3px solid var(--blue-700); }
.note.cleared { border-left: 3px solid var(--green-700); opacity: .85; }
.note .meta { font-size: 11.5px; color: var(--text-muted); }
.note .reply { margin: 6px 0 0 10px; padding: 6px 10px; background: var(--grey-50); border-radius: 6px; font-size: 12.5px; }

/* Dropdown menu */
.menu { position: absolute; background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-2); padding: 4px; min-width: 200px; z-index: 900; }
.menu button, .menu a { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 7px 10px; font: inherit; font-size: 13px; border-radius: 5px; cursor: pointer; color: var(--text); }
.menu button:hover, .menu a:hover { background: var(--navy-50); text-decoration: none; }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

/* Key-value list */
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 6px 12px; font-size: 12.8px; }
.kv dt { color: var(--text-muted); } .kv dd { margin: 0; font-weight: 500; }
.ai-label { display: inline-block; font-size: 10.5px; font-weight: 700; color: var(--amber-700); background: var(--amber-100); padding: 1px 6px; border-radius: 3px; letter-spacing: .03em; }
.lock-banner { background: var(--navy-900); color: #fff; padding: 8px 24px; font-size: 12.5px; }
.doc-preview { background: #fff; border: 1px solid var(--border); padding: 36px 44px; max-width: 820px; margin: 0 auto; font-family: Georgia, "Times New Roman", serif; font-size: 13.5px; line-height: 1.6; box-shadow: var(--shadow-1); }
.doc-preview h1, .doc-preview h2, .doc-preview h3 { font-family: var(--font); }
.doc-preview p { margin: 0 0 10px; text-align: justify; }
.lock-banner svg, .alert svg, .ribbon svg, .crumbs svg { width: 16px; height: 16px; vertical-align: -3px; margin-right: 4px; flex: none; }

/* ---------- Field-level "?" reference help ---------- */
.help-q { display: inline-grid; place-items: center; width: 16px; height: 16px; margin-left: 6px; padding: 0; border-radius: 50%; border: 1px solid var(--teal-600); background: var(--teal-50); color: var(--teal-700); font: 700 10.5px/1 var(--font); cursor: pointer; vertical-align: 1px; flex: none; }
.help-q:hover, .help-q:focus-visible { background: var(--teal-600); color: #fff; outline: none; box-shadow: var(--focus); }
.q-text .help-q { margin-left: 6px; }
.help-pop { position: fixed; z-index: 1200; background: #fff; border: 1px solid var(--border-strong); border-top: 3px solid var(--teal-600); border-radius: 8px; box-shadow: var(--shadow-3); padding: 10px 14px 12px; font-size: 12.8px; color: var(--text); max-height: min(520px, calc(100vh - 16px)); overflow: auto; animation: fade .1s ease-out; }
.help-pop-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.help-pop-head b { font-size: 13.5px; color: var(--navy-900); }
.help-pop-head .icon-btn { width: 24px; height: 24px; font-size: 17px; line-height: 1; }
.help-pop-sec { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--grey-500); font-weight: 650; margin: 8px 0 4px; }
.help-refs { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
.help-refs li { display: flex; gap: 8px; align-items: flex-start; line-height: 1.4; }
.help-pop p { margin: 0 0 6px; line-height: 1.5; }
.ref-badge { flex: none; font-size: 10px; font-weight: 650; padding: 2px 6px; border-radius: 10px; background: var(--grey-150); color: var(--grey-700); white-space: nowrap; margin-top: 1px; }
.ref-badge.c-law { background: var(--red-100); color: var(--red-700); }
.ref-badge.c-regulation { background: var(--amber-100); color: var(--amber-700); }
.ref-badge.c-standard { background: var(--blue-100); color: var(--blue-700); }
.ref-badge.c-ethics { background: var(--violet-100); color: var(--violet-700); }
.ref-badge.c-icap { background: var(--teal-100); color: var(--teal-700); }
.ref-badge.c-firm { background: var(--grey-150); color: var(--grey-700); }
.help-pop em.verify { font-style: normal; font-size: 10px; font-weight: 650; color: var(--amber-700); background: var(--amber-100); border-radius: 8px; padding: 0 5px; }
.help-pop-foot { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); font-size: 11.3px; color: var(--grey-600); line-height: 1.45; }
@media print { .help-q, .help-pop { display: none !important; } }
