/* ThreshBoard components v0.2. Requires tokens.css. Class prefix: tb- */

*, *::before, *::after { box-sizing: border-box; }
body.tb { margin: 0; font-family: var(--tb-font); font-size: var(--tb-fs-body); color: var(--tb-black); background: var(--tb-white); font-variant-numeric: tabular-nums; }
.tb :focus-visible { outline: var(--tb-focus); outline-offset: var(--tb-focus-offset); }
.tb-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Logo */
.tb-logo { display: inline-flex; align-items: center; border: 1px solid currentColor; padding: 5px 10px; font-size: 17px; font-weight: 500; letter-spacing: -0.02em; line-height: 1; color: inherit; text-decoration: none; }
.tb-logo .tb-o, .tb-logo .tb-dot { color: var(--tb-red); }

/* Type */
.tb-display { margin: 0; font-size: var(--tb-fs-display); font-weight: var(--tb-fw-black); text-transform: uppercase; letter-spacing: -0.02em; line-height: 1; }
.tb-display .tb-dot { color: var(--tb-red); }
.tb-h1 { margin: 0; font-size: var(--tb-fs-h1); font-weight: var(--tb-fw-black); text-transform: uppercase; letter-spacing: -0.02em; line-height: 1; }
.tb-h2 { margin: 0; font-size: var(--tb-fs-h2); font-weight: var(--tb-fw-bold); }
.tb-label { font-size: var(--tb-fs-label); font-weight: var(--tb-fw-bold); letter-spacing: 0.12em; text-transform: uppercase; }
.tb-muted { color: var(--tb-muted-text); }
.tb-empty { color: var(--tb-empty-text); }

/* App shell */
.tb-topbar { min-height: var(--tb-topbar-height); display: flex; align-items: center; gap: 20px; padding: 0 24px; border-bottom: var(--tb-border-strong); flex-wrap: wrap; }
.tb-shell { display: flex; flex-wrap: wrap; min-height: calc(100vh - var(--tb-topbar-height)); }
.tb-nav { flex: 1 1 var(--tb-nav-width); max-width: 100%; background: var(--tb-black); color: var(--tb-white); padding: 20px 0; display: flex; flex-direction: column; gap: 4px; }
.tb-nav a { display: flex; align-items: center; gap: 12px; padding: 10px 24px; color: var(--tb-white); text-decoration: none; border-left: 3px solid transparent; }
.tb-nav a[aria-current="page"] { font-weight: 700; border-left-color: var(--tb-red); background: #1f1f1f; }
.tb-nav .tb-label { color: var(--tb-on-black-muted); margin: 20px 24px 6px; }
.tb-content { flex: 999 1 560px; min-width: 0; padding: 32px 40px 48px; display: flex; flex-direction: column; gap: 24px; }

/* Buttons */
.tb-btn { height: var(--tb-button-height); padding: 0 16px; border: 1px solid var(--tb-black); border-radius: var(--tb-radius); background: var(--tb-white); color: var(--tb-black); font: 500 13px var(--tb-font); display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.tb-btn--primary { background: var(--tb-red-action); border-color: var(--tb-red-action); color: var(--tb-white); font-weight: 700; }
.tb-btn--dark { background: var(--tb-black); color: var(--tb-white); font-weight: 700; }
.tb-btn--link { border-color: transparent; background: transparent; text-decoration: underline; padding: 0 8px; }
.tb-btn--sm { height: 32px; padding: 0 12px; font-size: 12px; }
.tb-btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.tb-segmented { display: inline-flex; border: 1px solid var(--tb-black); }
.tb-segmented button { height: 36px; padding: 0 14px; border: 0; background: var(--tb-white); font: 500 13px var(--tb-font); cursor: pointer; }
.tb-segmented button + button { border-left: 1px solid var(--tb-black); }
.tb-segmented button[aria-pressed="true"] { background: var(--tb-black); color: var(--tb-white); }

/* Inputs */
.tb-field { display: flex; flex-direction: column; gap: 5px; }
.tb-field > label, .tb-field > .tb-field-label { font-size: var(--tb-fs-label); font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }
.tb-input, .tb-select { height: var(--tb-control-height); border: 1px solid var(--tb-border); border-radius: 0; padding: 0 10px; font: 13px var(--tb-font); background: var(--tb-white); color: var(--tb-black); }
.tb-input[aria-invalid="true"] { border-color: var(--tb-red-action); }
.tb-field-error { font-size: 12px; color: var(--tb-red-text); }

/* Filter panel (black) */
.tb-filters { background: var(--tb-black); color: var(--tb-white); }
.tb-filters__grid { padding: 18px 20px; display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px 16px; align-items: end; }
.tb-filters__chips { border-top: 1px solid #3a3a3a; padding: 12px 20px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tb-filters .tb-btn--link { color: var(--tb-white); }
.tb-chip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 4px 0 10px; border: 1px solid currentColor; font-size: 12px; }
.tb-chip button { width: 22px; height: 22px; background: transparent; color: inherit; border: 0; cursor: pointer; font-size: 14px; line-height: 1; }

/* Menus and popovers */
.tb-menu { background: var(--tb-white); color: var(--tb-black); border: var(--tb-border-strong); box-shadow: var(--tb-shadow-pop); display: flex; flex-direction: column; min-width: 200px; }
.tb-menu > button, .tb-menu > label { height: 38px; padding: 0 14px; border: 0; border-bottom: 1px solid var(--tb-gray-100); background: var(--tb-white); font: 13px var(--tb-font); text-align: left; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.tb-popover { border: var(--tb-border-strong); box-shadow: var(--tb-shadow-pop); background: var(--tb-white); max-width: 320px; }
.tb-popover__head { background: var(--tb-black); color: var(--tb-white); padding: 10px 16px; font-size: 13px; font-weight: 700; }
.tb-popover__body { padding: 16px; font-size: 13px; line-height: 1.5; display: flex; flex-direction: column; gap: 8px; }

/* Badges */
.tb-badge { display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; padding: 4px 7px; border: 1px solid transparent; }
.tb-badge--draft { border-color: var(--tb-border); color: var(--tb-ink-2); }
.tb-badge--review { border-color: var(--tb-warning); color: var(--tb-warning-text); background: var(--tb-warning-fill); }
.tb-badge--published { background: var(--tb-black); color: var(--tb-white); }
.tb-badge--archived { border: 1px dashed var(--tb-border); color: var(--tb-muted-text); }
.tb-badge--claude { border-color: var(--tb-red-action); color: var(--tb-red-text); }
.tb-badge--paid { background: var(--tb-asf-paid-bg); color: var(--tb-asf-paid-ink); }
.tb-badge--organic { background: var(--tb-asf-organic-bg); color: var(--tb-asf-organic-ink); }
.tb-badge--direct { background: var(--tb-asf-direct-bg); color: var(--tb-asf-direct-ink); }
.tb-badge--referral { background: var(--tb-asf-referral-bg); color: var(--tb-asf-referral-ink); }
.tb-badge--other { background: var(--tb-asf-other-bg); color: var(--tb-asf-other-ink); }
.tb-badge--unattributed { border: 1px dashed var(--tb-empty-text); color: var(--tb-ink-2); }

/* Cards */
.tb-card { border: var(--tb-border-strong); display: flex; flex-direction: column; background: var(--tb-white); }
.tb-card__head { background: var(--tb-black); color: var(--tb-white); padding: 10px 16px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tb-card__head h2, .tb-card__head h3 { margin: 0; font-size: 13px; font-weight: 700; }
.tb-card__body { padding: 20px; }
.tb-card--light .tb-card__head { background: var(--tb-white); color: var(--tb-black); border-bottom: var(--tb-border-strong); }

/* Scorecards */
.tb-scorecards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); border: var(--tb-border-strong); }
.tb-scorecard { padding: 20px 22px; display: flex; flex-direction: column; gap: 10px; border-right: var(--tb-border-rule); }
.tb-scorecard__value { font-size: var(--tb-fs-figure); font-weight: 700; line-height: 1; }
.tb-scorecard__delta { font-size: 12px; color: var(--tb-muted-text); }
.tb-delta--good { color: var(--tb-positive); font-weight: 700; }
.tb-delta--bad { color: var(--tb-negative); font-weight: 700; }

/* Tables */
.tb-table-wrap { overflow: auto; max-height: var(--tb-table-max-height, none); }
.tb-table { width: 100%; border-collapse: collapse; font-size: var(--tb-fs-table); }
.tb-table th { position: sticky; top: 0; background: var(--tb-black); color: var(--tb-white); text-align: left; padding: 9px 14px; font-size: 10px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; white-space: nowrap; }
.tb-table td { padding: 0 14px; height: var(--tb-row-comfortable); border-bottom: 1px solid var(--tb-gray-100); }
.tb-table--dense td { height: var(--tb-row-dense); }
.tb-table .tb-num { text-align: right; }
.tb-table tfoot td { background: var(--tb-gray-50); font-weight: 700; border-top: 2px solid var(--tb-black); }
.tb-table tr.tb-row--muted td { color: var(--tb-empty-text); }
.tb-table th[aria-sort="descending"]::after { content: " ↓"; color: var(--tb-red); }
.tb-table th[aria-sort="ascending"]::after { content: " ↑"; color: var(--tb-red); }
.tb-table__foot { padding: 10px 16px; display: flex; justify-content: space-between; font-size: 12px; color: var(--tb-muted-text); border-top: var(--tb-border-rule); }
.tb-cellbar { display: flex; justify-content: flex-end; align-items: center; gap: 10px; }
.tb-cellbar__track { width: 90px; height: 8px; background: var(--tb-gray-100); display: flex; justify-content: flex-end; }
.tb-cellbar__fill { height: 8px; background: var(--tb-red); }

/* Key and value list (Applicant Details) */
.tb-kv { margin: 0; display: grid; grid-template-columns: 190px 1fr; }
.tb-kv dt { padding: 9px 18px; font-size: 12px; color: var(--tb-muted-text); border-bottom: 1px solid var(--tb-gray-100); }
.tb-kv dd { margin: 0; padding: 9px 18px 9px 0; font-size: 13px; font-weight: 500; border-bottom: 1px solid var(--tb-gray-100); overflow-wrap: anywhere; }

/* Funnel table row bar */
.tb-funnelbar { height: 14px; background: #f0f0f0; }
.tb-funnelbar > span { display: block; height: 14px; background: var(--tb-red); }
.tb-funnel-group th { background: var(--tb-gray-50); color: var(--tb-black); position: static; border-top: var(--tb-border-strong); }

/* Tapered funnel step: set --top and --bottom as inset percentages per step */
.tb-taper { height: 64px; background: var(--tb-chart-3); clip-path: polygon(var(--top) 0, calc(100% - var(--top)) 0, calc(100% - var(--bottom)) 100%, var(--bottom) 100%); display: flex; align-items: center; justify-content: center; font-weight: 700; }

/* States */
.tb-skeleton { background: var(--tb-gray-100); }
.tb-emptystate { padding: 28px 20px; display: flex; gap: 14px; align-items: center; background: var(--tb-gray-50); }
.tb-toast { background: var(--tb-black); color: var(--tb-white); padding: 12px 14px; font-size: 13px; border-left: 4px solid var(--tb-positive-on-black); }
.tb-toast--alert { border-left-color: var(--tb-red); }

/* Tabs */
.tb-tabs { display: flex; border-bottom: var(--tb-border-strong); }
.tb-tabs [role="tab"] { height: 38px; padding: 0 12px; background: none; border: 0; border-bottom: 3px solid transparent; font: 500 13px var(--tb-font); color: var(--tb-muted-text); cursor: pointer; }
.tb-tabs [role="tab"][aria-selected="true"] { color: var(--tb-black); font-weight: 700; border-bottom-color: var(--tb-red); }

/* Responsive: phone is read-only for clients */
@media (max-width: 720px) {
  .tb-content { padding: 20px 16px 32px; }
  .tb-filters__grid { grid-template-columns: 1fr 1fr; }
  .tb-kv { grid-template-columns: 1fr; }
  .tb-kv dd { padding: 0 18px 9px; }
}

/* Print and PDF */
@media print {
  .tb-nav, .tb-topbar, .tb-filters__chips button, .tb-btn { display: none !important; }
  .tb-content { padding: 0; }
  .tb-card, .tb-table tr { break-inside: avoid; }
  .tb-table th, .tb-card__head, .tb-filters { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body.tb { font-size: 11pt; }
}
