/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-size: var(--fs-sm); font-weight: 600; line-height: 1.2;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.disabled { opacity: .5; pointer-events: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-soft { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-danger { background: var(--down); border-color: var(--down); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--down) 88%, #000); }
.btn-success { background: var(--up); border-color: var(--up); color: #04140d; }
.btn-sm { padding: 5px 10px; font-size: var(--fs-xs); }
.btn-lg { padding: 11px 20px; font-size: var(--fs-base); }
.btn-block { width: 100%; }
.btn-icon { padding: 8px; border-radius: var(--radius-sm); color: var(--text-muted); border: 0; background: transparent; position: relative; }
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn-icon .ping { position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--down); border: 2px solid var(--surface); }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.btn-group .btn.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); z-index: 1; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h3 { font-size: var(--fs-base); }
.card-head .sub { color: var(--text-muted); font-size: var(--fs-xs); }
.card-body { padding: var(--sp-5); }
.card-body.flush { padding: 0; }
.card-foot { padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border); }

/* Stat tiles */
.stat { padding: var(--sp-4) var(--sp-5); }
.stat-label { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .07em; color: var(--text-faint); font-weight: 600; }
.stat-value { font-size: 1.65rem; font-weight: 700; letter-spacing: -.02em; margin: 4px 0; font-variant-numeric: tabular-nums; }
.stat-delta { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-delta .icon { width: 14px; height: 14px; }
.stat-spark { height: 38px; margin-top: var(--sp-2); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: var(--radius-full); font-size: 11px; font-weight: 650; background: var(--surface-3); color: var(--text-muted); white-space: nowrap; }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-up, .badge-success { background: color-mix(in srgb, var(--up) 16%, transparent); color: var(--up); }
.badge-down, .badge-danger { background: color-mix(in srgb, var(--down) 16%, transparent); color: var(--down); }
.badge-warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge-info { background: color-mix(in srgb, var(--info) 16%, transparent); color: var(--info); }
.badge-mock { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); border: 1px dashed var(--warn); }
.badge-outline { background: transparent; border: 1px solid var(--border-strong); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: var(--radius-full); background: var(--surface-2); border: 1px solid var(--border); font-size: var(--fs-xs); }
.chip button { color: var(--text-faint); display: inline-flex; }
.chip button:hover { color: var(--down); }
.ticker { font-family: var(--font-mono); font-weight: 700; letter-spacing: .02em; }

/* Avatar */
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: var(--fs-sm); flex: none; }
.avatar-sm { width: 28px; height: 28px; font-size: 11px; }
.avatar-lg { width: 64px; height: 64px; font-size: 1.3rem; }
.logo-tile { width: 36px; height: 36px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; font-weight: 800; font-family: var(--font-mono); font-size: 12px; flex: none; }

/* Forms */
.field { display: grid; gap: 6px; margin-bottom: var(--sp-4); }
.field label, .label { font-size: var(--fs-sm); font-weight: 600; }
.hint { font-size: var(--fs-xs); color: var(--text-faint); }
.input, .select, .textarea {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.textarea { min-height: 96px; resize: vertical; }
.input::placeholder { color: var(--text-faint); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.input.invalid, .select.invalid { border-color: var(--down); }
.error-text { color: var(--down); font-size: var(--fs-xs); }
.input-group { display: flex; }
.input-group .input { border-radius: 0; }
.input-group > :first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group > :last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.input-addon { display: inline-flex; align-items: center; padding: 0 12px; background: var(--surface-2); border: 1px solid var(--border-strong); border-right: 0; color: var(--text-muted); font-size: var(--fs-sm); }
.input-addon:last-child { border-right: 1px solid var(--border-strong); border-left: 0; }
.field-row { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: var(--fs-sm); }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: var(--fs-sm); }
.switch input { position: absolute; opacity: 0; }
.switch .track { width: 38px; height: 22px; border-radius: var(--radius-full); background: var(--surface-3); border: 1px solid var(--border-strong); position: relative; transition: background var(--transition); flex: none; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform var(--transition); }
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.filter-row { display: grid; grid-template-columns: minmax(0, 1.6fr) 110px minmax(0, 1fr) auto; gap: var(--sp-2); align-items: center; padding: var(--sp-2) 0; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th, .table td { padding: 11px var(--sp-4); text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-faint); font-weight: 650; background: var(--surface); position: sticky; top: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; }
.table th[data-sort] { cursor: pointer; user-select: none; }
.table th[data-sort]::after { content: "↕"; margin-left: 6px; opacity: .35; }
.table th.sorted-asc::after { content: "↑"; opacity: 1; color: var(--accent); }
.table th.sorted-desc::after { content: "↓"; opacity: 1; color: var(--accent); }
.table-toolbar { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) var(--sp-5); flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.table-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border); font-size: var(--fs-xs); color: var(--text-muted); flex-wrap: wrap; }
.table-compact th, .table-compact td { padding: 7px var(--sp-4); }
.table-striped tbody tr:nth-child(even) { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.cell-company { display: flex; align-items: center; gap: 10px; }
.cell-company small { display: block; color: var(--text-faint); font-size: var(--fs-xs); }
.pagination { display: inline-flex; gap: 4px; }
.pagination button { min-width: 30px; height: 30px; padding: 0 8px; border-radius: var(--radius-sm); border: 1px solid var(--border); font-size: var(--fs-xs); font-weight: 600; }
.pagination button:hover { background: var(--surface-2); }
.pagination button.active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.pagination button:disabled { opacity: .4; pointer-events: none; }

/* Alerts */
.alert { display: flex; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-radius: var(--radius); border: 1px solid; font-size: var(--fs-sm); align-items: flex-start; }
.alert .icon { margin-top: 2px; }
.alert-info { background: color-mix(in srgb, var(--info) 10%, transparent); border-color: color-mix(in srgb, var(--info) 35%, transparent); color: var(--info); }
.alert-success { background: color-mix(in srgb, var(--up) 10%, transparent); border-color: color-mix(in srgb, var(--up) 35%, transparent); color: var(--up); }
.alert-warn { background: color-mix(in srgb, var(--warn) 10%, transparent); border-color: color-mix(in srgb, var(--warn) 35%, transparent); color: var(--warn); }
.alert-danger { background: color-mix(in srgb, var(--down) 10%, transparent); border-color: color-mix(in srgb, var(--down) 35%, transparent); color: var(--down); }
.alert > div { color: var(--text); }

/* Tabs */
.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab { padding: 10px var(--sp-4); font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; padding-top: var(--sp-4); }
.tab-panel.active { display: block; }

/* Dropdown */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px; z-index: 60;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: var(--sp-2); display: none;
}
.dropdown.open > .dropdown-menu { display: block; }
.dropdown-menu a, .dropdown-menu button.item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--text); font-size: var(--fs-sm); text-align: left; }
.dropdown-menu a:hover, .dropdown-menu button.item:hover { background: var(--surface-2); text-decoration: none; }
.dropdown-menu .divider { height: 1px; background: var(--border); margin: var(--sp-2) 0; }
.dropdown-menu .menu-head { padding: 8px 10px; font-size: var(--fs-xs); color: var(--text-faint); text-transform: uppercase; letter-spacing: .07em; }
.notif { display: flex; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); font-size: var(--fs-sm); }
.notif:hover { background: var(--surface-2); }
.notif small { display: block; color: var(--text-faint); }

/* Modal & toast */
.modal { position: fixed; inset: 0; z-index: 100; display: none; align-items: center; justify-content: center; padding: var(--sp-4); background: rgba(2, 8, 18, .6); }
.modal.open { display: flex; }
.modal-dialog { width: min(520px, 100%); max-height: 90vh; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); }
.modal-body { padding: var(--sp-5); }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border); }
.toast-stack { position: fixed; right: var(--sp-5); bottom: var(--sp-5); z-index: 120; display: grid; gap: var(--sp-2); }
.toast { min-width: 260px; max-width: 360px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--radius); box-shadow: var(--shadow-lg); font-size: var(--fs-sm); animation: toast-in .2s ease; }
.toast.success { border-left-color: var(--up); }
.toast.danger { border-left-color: var(--down); }
.toast.warn { border-left-color: var(--warn); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* Progress / meters */
.progress { height: 8px; border-radius: var(--radius-full); background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.progress.up > span { background: var(--up); }
.progress.warn > span { background: var(--warn); }
.progress.down > span { background: var(--down); }
.range-bar { position: relative; height: 6px; border-radius: var(--radius-full); background: var(--surface-3); }
.range-bar i { position: absolute; top: -4px; width: 3px; height: 14px; border-radius: 2px; background: var(--text); }

/* Lists / timeline / key-value */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: var(--sp-3); padding: 11px var(--sp-5); border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 10px var(--sp-4); font-size: var(--fs-sm); }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 var(--sp-4); border-left: 2px solid var(--border); display: grid; gap: var(--sp-4); }
.timeline li { position: relative; }
.timeline li::before { content: ""; position: absolute; left: calc(-1 * var(--sp-4) - 6px); top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid var(--surface); }
.timeline time { font-size: var(--fs-xs); color: var(--text-faint); display: block; }

/* Charts */
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; max-width: none; }
.chart text { font-family: var(--font-sans); font-size: 11px; fill: var(--text-faint); }
.chart-tip { position: absolute; pointer-events: none; padding: 6px 10px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border-strong); box-shadow: var(--shadow); font-size: 12px; white-space: nowrap; transform: translate(-50%, -110%); display: none; z-index: 5; }
.legend { display: flex; flex-wrap: wrap; gap: var(--sp-3); font-size: var(--fs-xs); color: var(--text-muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; }

/* Chat (AI research) */
.chat { display: flex; flex-direction: column; gap: var(--sp-4); }
.msg { max-width: 82%; padding: 12px 16px; border-radius: 14px; font-size: var(--fs-sm); line-height: 1.6; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-contrast); border-bottom-right-radius: 4px; }
.msg.ai { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.evidence { display: inline-block; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; padding: 1px 7px; border-radius: 4px; margin-right: 6px; }
.evidence.fact { background: color-mix(in srgb, var(--info) 18%, transparent); color: var(--info); }
.evidence.calc { background: color-mix(in srgb, var(--up) 18%, transparent); color: var(--up); }
.evidence.ai { background: color-mix(in srgb, var(--chart-3) 20%, transparent); color: var(--chart-3); }
.source-ref { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; padding: 1px 8px; border-radius: var(--radius-full); border: 1px solid var(--border-strong); color: var(--text-muted); }

/* Misc */
.empty { text-align: center; padding: var(--sp-6); color: var(--text-muted); }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--radius-sm); min-height: 14px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.demo-block { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: center; }
.code-sample { font-size: 12px; }
.matrix td, .matrix th { text-align: center; }
.matrix td:first-child, .matrix th:first-child { text-align: left; }
