/* CTC CRM — hand-written stylesheet, no build step required. */
:root {
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #18212f;
  --ink-2: #4a5567;
  --ink-3: #7b8597;
  --line: #e3e6eb;
  --line-2: #eef0f3;
  --side: #121a26;
  --side-ink: #c9d0db;
  --side-hover: #1d2736;
  --ok: #15803d; --ok-bg: #e8f6ed;
  --warn: #b45309; --warn-bg: #fdf3e2;
  --bad: #b91c1c; --bad-bg: #fdecec;
  --info: #1d4ed8; --info-bg: #e9effd;
  --field: #ffffff; --field-line: #d3d8e0; --hover: #fafbfc; --pop: #ffffff; --link: var(--brand);
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); font-size: 14px; line-height: 1.5; color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0 0 .75em; }
small, .muted { color: var(--ink-3); }
.mono { font-family: var(--mono); font-size: 12.5px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-weight: 700; font-size: 15px; }
.side .brand img { max-height: 30px; max-width: 150px; }
.side .brand .mark { width: 30px; height: 30px; border-radius: 7px; background: var(--brand); display: grid; place-items: center; font-size: 13px; color: var(--brand-ink); flex-shrink: 0; }
.side nav { padding: 6px 10px 20px; flex: 1; }
.side .group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #6b7686; padding: 16px 10px 6px; }
.side nav a { display: flex; align-items: center; gap: 10px; color: var(--side-ink); padding: 7px 10px; border-radius: 6px; font-size: 13.5px; }
.side nav a:hover { background: var(--side-hover); color: #fff; text-decoration: none; }
.side nav a.on { background: var(--side-hover); color: #fff; box-shadow: inset 3px 0 0 var(--brand); }
.side nav a svg { width: 17px; height: 17px; opacity: .8; flex-shrink: 0; }
.side .me { border-top: 1px solid #1f2a3a; padding: 12px 16px; font-size: 12.5px; display: flex; align-items: center; gap: 10px; }
.side .me form { margin-left: auto; }
.side .me button { background: none; border: 0; color: #8b96a8; cursor: pointer; font: inherit; padding: 0; white-space: nowrap; }
.side .me button:hover { color: #fff; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: #2a3546; color: #fff; display: grid; place-items: center; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 28px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar .search { flex: 1; max-width: 460px; position: relative; }
.topbar .search input { width: 100%; padding-left: 34px; background: var(--bg); border-color: transparent; }
.topbar .search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; color: var(--ink-3); }
.topbar .menu-btn { display: none; }
.content { padding: 24px 28px 48px; max-width: 1480px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .crumbs { font-size: 12.5px; color: var(--ink-3); margin-bottom: 4px; }
.page-head .crumbs a { color: var(--ink-3); }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Panels & cards ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel + .panel { margin-top: 16px; }
.grid > .panel + .panel { margin-top: 0; }
.stack > .panel + .panel { margin-top: 12px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 13px 18px; border-bottom: 1px solid var(--line-2); }
.panel-body { padding: 16px 18px; }
.panel-body.tight { padding: 0; }
.grid { display: grid; gap: 16px; }
.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)); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.stat { padding: 16px 18px; }
.stat .label { font-size: 12.5px; color: var(--ink-3); }
.stat .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }

/* ---------- Forms ---------- */
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
input[type=text], input[type=email], input[type=tel], input[type=url], input[type=password], input[type=number], input[type=date], input[type=datetime-local], input[type=search], input[type=color], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--field); border: 1px solid var(--field-line); border-radius: 6px; padding: 7px 10px; min-height: 36px;
}
input[type=color] { padding: 2px; width: 64px; }
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.field { margin-bottom: 14px; }
.field .hint { font-size: 12px; color: var(--ink-3); margin-top: 4px; }
.field .err, .err { color: var(--bad); font-size: 12.5px; margin-top: 4px; }
.req::after { content: " *"; color: var(--bad); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.form-grid .wide { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }
fieldset { border: 0; padding: 0; margin: 0 0 8px; }
legend { font-size: 13px; font-weight: 650; color: var(--ink); padding: 0 0 10px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--line-2); background: var(--hover); border-radius: 0 0 var(--radius) var(--radius); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 600; font-size: 13.5px; padding: 7px 14px; min-height: 36px; border-radius: 6px; border: 1px solid var(--field-line); background: var(--field); color: var(--ink); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--hover); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(.94); }
.btn.danger { color: var(--bad); border-color: #f0c4c4; }
.btn.danger:hover { background: var(--bad-bg); }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: 12.5px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn svg { width: 16px; height: 16px; }
.linkbtn { background: none; border: 0; color: var(--brand); font: inherit; cursor: pointer; padding: 0; }
.linkbtn.danger { color: var(--bad); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-3); padding: 9px 14px; border-bottom: 1px solid var(--line); background: var(--hover); white-space: nowrap; }
table.data th a { color: inherit; }
table.data td { padding: 10px 14px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: var(--hover); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .primary-cell a { font-weight: 600; color: var(--ink); }
.empty { padding: 36px 18px; text-align: center; color: var(--ink-3); }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }

/* ---------- Filters & pagination ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line-2); align-items: flex-end; }
.filters .f { min-width: 150px; flex: 0 1 180px; }
.filters .f.q { flex: 1 1 240px; }
.filters label { font-size: 11.5px; margin-bottom: 3px; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line-2); font-size: 13px; color: var(--ink-3); }
.pager nav { display: flex; gap: 4px; }
.pager a, .pager span.cur { padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink-2); }
.pager span.cur { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- Detail pages ---------- */
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 7px 14px; font-size: 13.5px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; word-break: break-word; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--ink-2); font-weight: 600; font-size: 13.5px; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.on { color: var(--ink); border-color: var(--brand); }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs .count { font-size: 11.5px; background: var(--line-2); border-radius: 999px; padding: 1px 7px; margin-left: 4px; color: var(--ink-3); }
.record-head { display: flex; gap: 14px; align-items: center; }
.record-head .avatar { width: 46px; height: 46px; font-size: 15px; background: var(--brand); }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 28px 1fr; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line-2); }
.timeline li:last-child { border-bottom: 0; }
.timeline .ico { width: 28px; height: 28px; border-radius: 50%; background: var(--line-2); display: grid; place-items: center; font-size: 12px; }
.timeline .meta { font-size: 12px; color: var(--ink-3); }
.timeline .body { white-space: pre-wrap; word-break: break-word; }

/* ---------- Pipeline board ---------- */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.col { flex: 0 0 262px; background: #eceef2; border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 190px); }
.col-head { padding: 10px 12px; font-weight: 650; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.col-head .n { margin-left: auto; color: var(--ink-3); font-weight: 600; font-size: 12px; }
.col-head .sw { width: 9px; height: 9px; border-radius: 50%; }
.col-body { padding: 0 8px 8px; overflow-y: auto; min-height: 60px; flex: 1; }
.col-body.over { background: color-mix(in srgb, var(--brand) 10%, transparent); border-radius: 6px; }
.card { background: var(--pop); border: 1px solid var(--line); border-radius: 7px; padding: 9px 11px; margin-bottom: 8px; cursor: grab; box-shadow: 0 1px 1px rgba(0,0,0,.03); }
.card:active { cursor: grabbing; }
.card .t { font-weight: 600; font-size: 13.5px; color: var(--ink); }
.card .s { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.card.dragging { opacity: .5; }

/* ---------- Alerts ---------- */
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 13.5px; border: 1px solid; }
.flash.ok { background: var(--ok-bg); color: #14532d; border-color: #bfe5cc; }
.flash.bad { background: var(--bad-bg); color: #7f1d1d; border-color: #f3c5c5; }
.flash.warn { background: var(--warn-bg); color: #78350f; border-color: #f2d7a6; }
.flash ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- Bars (simple charts) ---------- */
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 140px 1fr 56px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.bar-track { display: block; height: 10px; background: var(--line-2); border-radius: 0 4px 4px 0; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--brand); border-radius: 0 4px 4px 0; }
.bar-row .v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.funnel .bar-fill { background: var(--brand); }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--bg); }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .panel-body { padding: 28px; }
.auth-brand { text-align: center; margin-bottom: 20px; }
.auth-brand .mark { width: 44px; height: 44px; border-radius: 10px; background: var(--brand); color: var(--brand-ink); display: inline-grid; place-items: center; font-weight: 800; margin-bottom: 10px; }
.auth-brand img { max-height: 48px; max-width: 220px; margin-bottom: 8px; }

/* ---------- Autocomplete ---------- */
.ac { position: relative; }
.ac-list { position: absolute; z-index: 40; left: 0; right: 0; top: 100%; background: var(--pop); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 24px rgba(16,24,40,.12); max-height: 260px; overflow-y: auto; display: none; }
.ac-list.open { display: block; }
.ac-list div { padding: 7px 10px; cursor: pointer; font-size: 13.5px; }
.ac-list div:hover, .ac-list div.hl { background: var(--bg); }
.ac-list div small { display: block; }

/* ---------- Matrix (role permissions) ---------- */
table.matrix td, table.matrix th { text-align: center; }
table.matrix td:first-child, table.matrix th:first-child { text-align: left; }

/* ---------- Portal ---------- */
.portal-top { background: var(--panel); border-bottom: 1px solid var(--line); }
.portal-top .inner { max-width: 1000px; margin: 0 auto; padding: 12px 20px; display: flex; align-items: center; gap: 14px; }
.portal-top nav { display: flex; gap: 4px; margin-left: 16px; }
.portal-top nav a { padding: 6px 12px; border-radius: 6px; color: var(--ink-2); font-weight: 600; }
.portal-top nav a.on { background: var(--bg); color: var(--ink); }
.portal-main { max-width: 1000px; margin: 0 auto; padding: 24px 20px 48px; }
.steps { display: flex; gap: 0; margin: 10px 0 4px; }
.steps .step { flex: 1; text-align: center; font-size: 11.5px; color: var(--ink-3); position: relative; padding-top: 18px; }
.steps .step::before { content: ""; position: absolute; top: 5px; left: 0; right: 0; height: 3px; background: var(--line); }
.steps .step::after { content: ""; position: absolute; top: 1px; left: 50%; width: 11px; height: 11px; margin-left: -5px; border-radius: 50%; background: var(--line); }
.steps .step.done::before, .steps .step.done::after { background: var(--brand); }
.steps .step.done { color: var(--ink); }

/* ---------- Print (invoices & letters) ---------- */
.doc-page { background: #fff; max-width: 820px; margin: 24px auto; padding: 56px 64px; box-shadow: var(--shadow); border: 1px solid var(--line); font-size: 14px; }
.doc-page h1 { font-size: 26px; }
.doc-toolbar { max-width: 820px; margin: 16px auto 0; display: flex; gap: 8px; justify-content: flex-end; }
@media print {
  body { background: #fff; }
  .doc-toolbar, .no-print { display: none !important; }
  .doc-page { box-shadow: none; border: 0; margin: 0; padding: 0; max-width: none; }
}

.inline-form { display: inline; }
.row-actions { display: flex; gap: 10px; justify-content: flex-end; }
.stack > * + * { margin-top: 12px; }
.flex { display: flex; gap: 8px; align-items: center; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.right { text-align: right; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.nowrap { white-space: nowrap; }
.pill-list { display: flex; flex-wrap: wrap; gap: 6px; }
details.more summary { cursor: pointer; color: var(--brand); font-weight: 600; font-size: 13px; }
code { font-family: var(--mono); font-size: 12.5px; background: var(--line-2); padding: 1px 5px; border-radius: 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .split { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 250px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .topbar { padding: 10px 16px; }
  .topbar .menu-btn { display: inline-flex; }
  .content { padding: 16px; }
  .g2, .g3, .g4, .form-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .bar-row { grid-template-columns: 96px 1fr 48px; }
  .doc-page { padding: 24px; margin: 0; }
  .portal-top .inner { flex-wrap: wrap; }
  .portal-top nav { margin-left: 0; order: 3; width: 100%; overflow-x: auto; }
}

/* ---------- Saved views & column picker ---------- */
.viewbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.viewbar-views { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--ink-2); font-size: 12.5px; font-weight: 600; }
.chip:hover { text-decoration: none; border-color: #c9ced6; color: var(--ink); }
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.chip.on small { color: inherit; opacity: .8; }
.colpick { list-style: none; margin: 0; padding: 0; columns: 2; column-gap: 16px; }
.colpick li { display: flex; align-items: center; gap: 6px; padding: 3px 6px; border: 1px solid var(--line-2); border-radius: 6px; margin-bottom: 4px; background: var(--pop); break-inside: avoid; }
.colpick li.dragging { opacity: .4; }
.colpick li.over { border-color: var(--brand); }
.colpick .grip { cursor: grab; color: var(--ink-3); font-size: 12px; letter-spacing: -2px; }
.colpick .btn.sm { min-height: 24px; padding: 0 6px; }
@media (max-width: 820px) { .colpick { columns: 1; } }

/* ---------- Repeatable rows & multi-select ---------- */
.repeat-table td { padding: 6px 8px; vertical-align: middle; }
.repeat-table input, .repeat-table select { min-height: 32px; padding: 4px 8px; }
details.multiselect { position: relative; }
details.multiselect summary { list-style: none; cursor: pointer; border: 1px solid var(--field-line); border-radius: 6px; padding: 7px 30px 7px 10px; min-height: 36px; background: var(--field); position: relative; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
details.multiselect summary::-webkit-details-marker { display: none; }
details.multiselect summary::after { content: "▾"; position: absolute; right: 10px; top: 7px; color: var(--ink-3); }
details.multiselect[open] summary { border-color: var(--brand); }
details.multiselect .ms-list { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); background: var(--pop); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 24px rgba(16,24,40,.12); max-height: 260px; overflow-y: auto; padding: 6px 10px; }
details.multiselect .ms-list .check { margin: 4px 0; font-weight: 500; }
.kv-table { margin-top: 2px; }
.kv-table th, .kv-table td { padding: 6px 10px !important; font-size: 13px; }

/* Colourful dashboard tiles */
.stat[class*="tone-"] { position: relative; overflow: hidden; border-left: 4px solid var(--tone); background: linear-gradient(135deg, var(--tone-bg) 0%, var(--panel) 70%); }
.stat[class*="tone-"] .value { color: var(--tone); }
.stat[class*="tone-"] .label { color: var(--ink-2); font-weight: 600; }
.tone-blue   { --tone: #2563eb; --tone-bg: #eff6ff; }
.tone-violet { --tone: #7c3aed; --tone-bg: #f5f3ff; }
.tone-orange { --tone: #ea580c; --tone-bg: #fff7ed; }
.tone-green  { --tone: #16a34a; --tone-bg: #f0fdf4; }
.tone-teal   { --tone: #0d9488; --tone-bg: #f0fdfa; }
.tone-red    { --tone: #dc2626; --tone-bg: #fef2f2; }
.tone-slate  { --tone: #475569; --tone-bg: #f8fafc; }
.repeat .table-wrap { overflow-x: auto; }
.repeat-table input, .repeat-table select { width: 100%; min-width: 90px; box-sizing: border-box; }
.repeat-table input[type=date] { min-width: 130px; }

/* Automations page */
.section-title { font-size: 15px; margin: 22px 0 10px; color: var(--ink-2); }
details.auto { margin-bottom: 10px; }
details.auto > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
details.auto > summary::-webkit-details-marker { display: none; }
details.auto > summary small { display: block; margin-top: 3px; line-height: 1.4; }
details.auto[open] > summary { border-bottom: 1px solid var(--line-2); }
fieldset.tpl { border: 1px solid var(--line-2); border-radius: 8px; padding: 12px 14px 4px; margin: 14px 0 8px; }
fieldset.tpl legend { padding: 0 6px; }

/* Type-to-search drop-downs */
.ss { position: relative; display: block; min-width: 0; }
.ss > select { position: absolute !important; left: 0; bottom: 0; width: 100% !important; height: 1px !important; opacity: 0; pointer-events: none; border: 0; padding: 0; margin: 0; }
.ss-input { width: 100%; cursor: pointer; padding-right: 28px !important; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 9px center; text-overflow: ellipsis; }
.ss.open .ss-input { cursor: text; }
.ss-input:disabled { cursor: not-allowed; }
.ss-list { display: none; position: absolute; z-index: 60; left: 0; right: 0; top: calc(100% + 2px); min-width: 200px; max-height: 280px; overflow-y: auto; background: var(--pop); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 24px rgba(16,24,40,.14); padding: 4px 0; text-align: left; }
.ss.open .ss-list { display: block; }
.ss.up .ss-list { top: auto; bottom: calc(100% + 2px); }
.ss-opt { padding: 7px 10px; cursor: pointer; font-size: 13.5px; line-height: 1.35; color: var(--ink); white-space: normal; }
.ss-opt.hl { background: var(--bg); }
.ss-opt.sel { font-weight: 600; }
.ss-opt.dis { color: var(--ink-3); cursor: default; }
.ss-opt mark { background: #fef08a; color: inherit; padding: 0; border-radius: 2px; }
.ss-group { padding: 6px 10px 2px; font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); }
.ss-empty { padding: 8px 10px; color: var(--ink-3); font-size: 13px; }
.ms-filter { width: 100%; margin-bottom: 6px; }
.flex > .ss, .f > .ss { flex: 1 1 auto; }
.ms-filter { position: sticky; top: -6px; z-index: 1; }
.tags{display:inline-flex;flex-wrap:wrap;gap:4px;justify-content:flex-end;max-width:360px}
.ms-box{max-height:260px;overflow-y:auto;border:1px solid var(--line);border-radius:6px;padding:6px 10px}

/* ---------- Colour themes: dark mode (My account → Appearance) ---------- */
html[data-mode="dark"] {
  --bg: #0f1520; --panel: #171f2c; --ink: #e6eaf0; --ink-2: #b9c2cf; --ink-3: #8a95a7;
  --line: #2a3443; --line-2: #222b38; --side: #0a0f17; --side-hover: #18212f;
  --ok: #4ade80; --ok-bg: #12301f; --warn: #fbbf24; --warn-bg: #3a2a10; --bad: #f87171; --bad-bg: #3b1515; --info: #93c5fd; --info-bg: #16264a;
  --field: #0f1622; --field-line: #334055; --hover: #1c2533; --pop: #1b2431;
  --link: color-mix(in srgb, var(--brand) 55%, #ffffff);
  --shadow: 0 1px 2px rgba(0,0,0,.4);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  html[data-mode="auto"] {
  --bg: #0f1520; --panel: #171f2c; --ink: #e6eaf0; --ink-2: #b9c2cf; --ink-3: #8a95a7;
  --line: #2a3443; --line-2: #222b38; --side: #0a0f17; --side-hover: #18212f;
  --ok: #4ade80; --ok-bg: #12301f; --warn: #fbbf24; --warn-bg: #3a2a10; --bad: #f87171; --bad-bg: #3b1515; --info: #93c5fd; --info-bg: #16264a;
  --field: #0f1622; --field-line: #334055; --hover: #1c2533; --pop: #1b2431;
  --link: color-mix(in srgb, var(--brand) 55%, #ffffff);
  --shadow: 0 1px 2px rgba(0,0,0,.4);
  color-scheme: dark;
  }
}
html[data-mode="dark"] .stat[class*="tone-"], html[data-mode="auto"] .stat[class*="tone-"] { --tone-bg: var(--panel); }
html[data-mode="dark"] .ss-opt mark { background: #854d0e; }
html[data-mode="dark"] .tone-blue .value, html[data-mode="dark"] .tone-violet .value { filter: brightness(1.5); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatches label { display: inline-flex; align-items: center; gap: 6px; margin: 0; border: 1px solid var(--line); border-radius: 20px; padding: 4px 10px 4px 5px; cursor: pointer; font-weight: 500; }
.swatches input { position: absolute; opacity: 0; }
.swatches .dot { width: 18px; height: 18px; border-radius: 50%; display: inline-block; }
.swatches input:checked + .dot { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--ink); }
.pager { flex-wrap: wrap; gap: 8px 14px; }
.pager.top { border-top: 0; border-bottom: 1px solid var(--line-2); }
.pager nav { flex-wrap: wrap; }
.pager span.off { padding: 4px 10px; border: 1px solid var(--line-2); border-radius: 6px; color: var(--ink-3); opacity: .6; }
.pager span.gap { padding: 4px 2px; }
.pager .perpage label { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-weight: 500; color: var(--ink-3); }
.pager .perpage select { width: auto; min-height: 30px; padding: 3px 8px; }
/* Bulk actions on lists */
th.sel, td.sel { width: 34px; padding-right: 0 !important; }
.bulkbar { display: none; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; background: color-mix(in srgb, var(--brand) 9%, var(--panel)); border-bottom: 1px solid var(--line-2); }
.bulkbar.on { display: flex; }
.bulkbar .bulk-value { min-width: 200px; flex: 1 1 220px; max-width: 360px; }
.bulkbar .bulk-value .field { margin: 0; }
.bulkbar .bulk-value label { display: none; }
/* Calendar */
.seg { display: inline-flex; border: 1px solid var(--field-line); border-radius: 6px; overflow: hidden; }
.seg a { padding: 7px 12px; font-weight: 600; font-size: 13px; color: var(--ink-2); background: var(--field); }
.seg a.on { background: var(--brand); color: var(--brand-ink); }
.seg a:hover { text-decoration: none; }
.cal { overflow: hidden; }
.cal-head, .cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-head div { padding: 8px 10px; font-size: 12px; font-weight: 650; color: var(--ink-3); border-bottom: 1px solid var(--line); text-transform: uppercase; letter-spacing: .04em; }
.cal-day { min-height: 118px; border-right: 1px solid var(--line-2); border-bottom: 1px solid var(--line-2); padding: 6px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal-day:nth-child(7n) { border-right: 0; }
.cal-day.out { background: var(--hover); }
.cal-day.out .cal-num span { color: var(--ink-3); }
.cal-num { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; font-weight: 650; }
.cal-day.today .cal-num span { background: var(--brand); color: var(--brand-ink); border-radius: 999px; padding: 1px 7px; }
.cal-add { position: relative; }
.cal-add summary { list-style: none; cursor: pointer; color: var(--ink-3); padding: 0 5px; border-radius: 4px; opacity: 0; }
.cal-day:hover .cal-add summary, .cal-add[open] summary { opacity: 1; }
.cal-add summary::-webkit-details-marker { display: none; }
.cal-add > div { position: absolute; right: 0; z-index: 20; background: var(--pop); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); display: flex; flex-direction: column; min-width: 130px; }
.cal-add > div a { padding: 6px 10px; font-size: 13px; }
.cal-item { display: block; font-size: 12px; line-height: 1.35; padding: 2px 6px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); border-left: 3px solid; }
.cal-item:hover { text-decoration: none; filter: brightness(.96); }
.cal-item b { font-weight: 650; font-variant-numeric: tabular-nums; }
.cal-item.meeting { background: color-mix(in srgb, #7c3aed 12%, var(--panel)); border-color: #7c3aed; }
.cal-item.task { background: color-mix(in srgb, #2563eb 10%, var(--panel)); border-color: #2563eb; }
.cal-item.overdue { background: color-mix(in srgb, #dc2626 12%, var(--panel)); border-color: #dc2626; }
.cal-item.done { opacity: .55; text-decoration: line-through; }
.cal-more summary { font-size: 12px; color: var(--ink-3); cursor: pointer; }
.cal-key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; }
.cal-key.meeting { background: #7c3aed; } .cal-key.task { background: #2563eb; } .cal-key.overdue { background: #dc2626; }
@media (max-width: 760px) { .cal-day { min-height: 74px; padding: 3px; } .cal-item b { display: none; } .cal-head div { padding: 6px 4px; } }
/* Help assistant */
.help-fab { position: fixed; right: 20px; bottom: 20px; z-index: 90; width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--brand); color: var(--brand-ink); font-size: 22px; font-weight: 700; cursor: pointer; box-shadow: 0 6px 18px rgba(16,24,40,.25); }
.help-panel { position: fixed; right: 20px; bottom: 80px; z-index: 91; width: min(400px, calc(100vw - 32px)); height: min(560px, calc(100vh - 120px)); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 40px rgba(16,24,40,.25); display: flex; flex-direction: column; overflow: hidden; }
.help-panel[hidden] { display: none; }
.help-panel header { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line-2); }
.help-panel header strong { flex: 1; }
.help-msgs { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.help-msgs .msg { padding: 8px 11px; border-radius: 10px; font-size: 13.5px; line-height: 1.5; max-width: 92%; overflow-wrap: anywhere; }
.help-msgs .msg.user { align-self: flex-end; background: var(--brand); color: var(--brand-ink); }
.help-msgs .msg.bot { align-self: flex-start; background: var(--hover); border: 1px solid var(--line-2); }
.help-msgs .msg.bot ul, .help-msgs .msg.bot ol { margin: 4px 0; padding-left: 18px; }
.help-msgs .msg.bot p { margin: 0 0 6px; }
.help-msgs .msg.wait { color: var(--ink-3); font-style: italic; }
.help-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.help-chips button { font: inherit; font-size: 12.5px; border: 1px solid var(--line); background: var(--field); color: var(--ink-2); border-radius: 999px; padding: 4px 10px; cursor: pointer; }
.help-panel form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line-2); align-items: flex-end; }
.help-panel textarea { flex: 1; resize: none; min-height: 40px; }
@media print { .help-bot { display: none; } }

/* Course comparison and finder (v1.7) */
.print-only { display: none; }
@media print { .print-only { display: block; margin-bottom: 12px; } .side, .topbar { display: none !important; } }
table.compare th[scope=row] { background: var(--hover); color: var(--ink-2); font-weight: 600; white-space: nowrap; vertical-align: top; width: 1%; }
table.compare td { vertical-align: top; min-width: 180px; }
table.compare thead th { vertical-align: bottom; font-size: 14px; }
.finder { padding: 12px 16px 4px; border-bottom: 1px solid var(--line); }
.finder .finder-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px 12px; }
.finder .fstep label.lbl { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.finder .fstep label.lbl b { display: inline-block; min-width: 18px; height: 18px; line-height: 18px; text-align: center; border-radius: 50%; background: var(--brand); color: #fff; font-size: 11px; margin-right: 4px; }
.finder .fee { display: flex; gap: 6px; }
.finder .fee input { min-width: 0; }
.finder .fee select { width: 90px; flex: 0 0 90px; }
.finder .fstep.wide { grid-column: span 2; }
@media (max-width: 640px) { .finder .fstep.wide { grid-column: auto; } }
.finder .finder-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 0; }
.finder details.multiselect .ms-list .ms-empty { color: var(--ink-3); font-size: 13px; padding: 4px 0; }
.shortlist-for { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ms-list label[hidden] { display: none !important; }
