/*
 * components.css - buttons, cards, icon tiles, badges, forms, segmented
 * control, tabs, accordion, modal, toast, progress, stat tiles, tables.
 * Every component has square corners.
 */

/* ---------- Buttons ---------- */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  height: 48px;
  padding: 0 20px;
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: transform var(--t-micro) var(--ease-out), box-shadow var(--t-micro) var(--ease-out),
    background-color var(--t-micro) var(--ease-out), border-color var(--t-micro) var(--ease-out), color var(--t-micro) var(--ease-out);
}
.btn:hover:not(:disabled):not([aria-disabled="true"]) {
  border-color: var(--ink);
  box-shadow: var(--shadow-hover);
  transform: translate(-2px, -2px);
}
.btn:active:not(:disabled) { box-shadow: 0 0 0 var(--ink); transform: translate(0, 0); }
.btn-sm { height: 40px; padding: 0 14px; font-size: 14px; }
.btn-lg { height: 56px; padding: 0 26px; font-size: 16px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { color: var(--accent-ink); background: var(--accent-hover); }
.btn-dark { background: var(--ink); color: var(--white); }
.btn-dark:hover { color: var(--white); }
.btn-outline { background: var(--bg); color: var(--ink); border-color: var(--ink); }
.btn-outline:hover { color: var(--ink); }
.btn-ghost { background: transparent; color: var(--accent); padding-inline: var(--s-3); }
.btn-ghost:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent); box-shadow: none; transform: none; border-color: transparent; }
.btn-danger { background: var(--danger); color: var(--white); }
.btn-danger:hover { color: var(--white); }
.btn-outline-danger { background: var(--bg); color: var(--danger); border-color: var(--danger); }
.btn-outline-danger:hover:not(:disabled) { color: var(--danger); border-color: var(--danger); box-shadow: 4px 4px 0 var(--danger); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .4; cursor: not-allowed; }
.btn.is-loading { color: transparent; pointer-events: none; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 14px; height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid var(--white);
  animation: spin .8s linear infinite;
}
.btn-outline.is-loading::after { border-color: var(--ink); }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px; height: 44px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
}
.icon-btn:hover { border-color: var(--ink); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }

/* Keyboard shortcut badge, hidden on touch devices */
.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border: 1px solid currentColor;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  opacity: .75;
  font-variant-numeric: tabular-nums;
}
@media (hover: none) { .kbd { display: none; } }

/* ---------- Cards ---------- */
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: var(--s-5);
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink);
}
.card-text { color: var(--ink-2); font-size: 15px; line-height: 1.6; }
.card-link {
  text-decoration: none;
  transition: transform var(--t-micro) var(--ease-out), box-shadow var(--t-micro) var(--ease-out), border-color var(--t-micro) var(--ease-out);
}
.card-link:hover { color: var(--ink); border-color: var(--ink); box-shadow: var(--shadow-hover); transform: translate(-2px, -2px); }
.card-link:active { box-shadow: 0 0 0 var(--ink); transform: translate(0, 0); }
.card-arrow { margin-top: auto; color: var(--accent); transition: transform var(--t-micro) var(--ease-out); }
.card-link:hover .card-arrow { transform: translateX(4px); }
.group-bar-attention { border-top: 4px solid var(--g-attention); }
.group-bar-speed { border-top: 4px solid var(--g-speed); }
.group-bar-memory { border-top: 4px solid var(--g-memory); }
.card-compact { flex-direction: row; align-items: center; padding: var(--s-4); }
.card-compact .card-title { font-size: 16px; }

/* ---------- Icon tiles ---------- */
.icon-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 44px; height: 44px;
  background: var(--accent-soft);
  color: var(--accent);
}
.icon-tile-sm { width: 36px; height: 36px; }
.icon-tile-accent { background: var(--accent-soft); color: var(--accent); }
.icon-tile.group-attention { background: var(--accent-soft); color: var(--accent); }
.icon-tile.group-speed { background: var(--warning-soft); color: var(--warning-ink); }
.icon-tile.group-memory { background: var(--bg-sunken); color: var(--c-purple); }
.group-dot { display: inline-block; width: 12px; height: 12px; }
.group-dot.group-attention { background: var(--g-attention); }
.group-dot.group-speed { background: var(--g-speed); }
.group-dot.group-memory { background: var(--g-memory); }

/* ---------- Badges and chips ---------- */
.badge, .chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink-2);
  font-size: var(--fs-micro);
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.badge-ink { background: var(--ink); border-color: var(--ink); color: var(--white); }
.badge-accent { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip-success { background: var(--success-soft); border-color: var(--success); color: var(--ink); }
.chip-accent { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip-warning { background: var(--warning-soft); border-color: var(--warning); color: var(--ink); }
.chip-danger { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.chip-lg { height: 32px; padding: 0 12px; font-size: 13px; }

/* ---------- Forms ---------- */
.field { display: grid; gap: var(--s-2); }
.field-label { font-size: var(--fs-small); font-weight: 700; color: var(--ink); }
.field-hint { font-size: 13px; color: var(--ink-3); }
.input, .select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 48px;
  padding: 0 var(--s-4);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  font-weight: 500;
  transition: border-color var(--t-micro) var(--ease-out), box-shadow var(--t-micro) var(--ease-out);
}
.input:hover, .select:hover { border-color: var(--ink-3); }
.input:focus, .select:focus { border-color: var(--accent); }
.input:focus-visible, .select:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.select {
  padding-right: 44px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%230B1220' stroke-width='2' stroke-linecap='square' stroke-linejoin='miter'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  cursor: pointer;
}
.select-sm { height: 40px; font-size: 14px; }

/* Checkbox and radio */
.check { display: inline-flex; align-items: center; gap: var(--s-3); min-height: 44px; cursor: pointer; font-weight: 600; font-size: 15px; }
input[type="checkbox"], input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 20px; height: 20px;
  margin: 0;
  border: 1px solid var(--ink);
  background: var(--bg);
  display: inline-grid;
  place-content: center;
  cursor: pointer;
}
input[type="checkbox"]::before {
  content: "";
  width: 12px; height: 12px;
  background: var(--white);
  clip-path: polygon(14% 52%, 0 66%, 38% 100%, 100% 22%, 86% 8%, 38% 72%);
  transform: scale(0);
}
input[type="checkbox"]:checked { background: var(--ink); }
input[type="checkbox"]:checked::before { transform: scale(1); }
input[type="radio"]::before { content: ""; width: 10px; height: 10px; background: var(--ink); transform: scale(0); }
input[type="radio"]:checked::before { transform: scale(1); }

/* Range slider */
input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 28px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 4px; background: var(--bg-sunken); border: 0; }
input[type="range"]::-moz-range-track { height: 4px; background: var(--bg-sunken); border: 0; }
input[type="range"]::-moz-range-progress { height: 4px; background: var(--ink); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7px; background: var(--ink); border: 0; }
input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; background: var(--ink); border: 0; }

/* Segmented control (radio group built on native inputs) */
.option-row { border: 0; margin: 0 0 var(--s-5); padding: 0; min-width: 0; }
.option-label { display: block; margin-bottom: var(--s-2); font-size: var(--fs-small); font-weight: 700; color: var(--ink); padding: 0; }
.segmented { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--ink); max-width: 100%; }
.segment { position: relative; display: inline-flex; }
.segment + .segment { border-left: 1px solid var(--ink); }
.segment input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; margin: 0; cursor: pointer; border: 0; }
.segment span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 var(--s-4);
  font-size: 14px;
  font-weight: 700;
  background: var(--bg);
  color: var(--ink);
  transition: background-color var(--t-micro) var(--ease-out), color var(--t-micro) var(--ease-out);
}
.segment input:hover + span { background: var(--bg-soft); }
.segment input:checked + span { background: var(--ink); color: var(--white); }
.segment input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; position: relative; z-index: 1; }

/* ---------- Tabs ---------- */
.tabs { position: relative; display: flex; align-items: stretch; border-bottom: 1px solid var(--line); }
.tabs-scroll { position: relative; flex: 1; overflow-x: auto; scrollbar-width: none; scroll-behavior: smooth; }
.tabs-scroll::-webkit-scrollbar { display: none; }
.tab-list { position: relative; display: flex; width: max-content; }
.tab {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  min-height: 52px;
  padding: 0 var(--s-4);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-2);
  white-space: nowrap;
}
.tab { text-decoration: none; }
.tab:hover { color: var(--ink); background: var(--bg-soft); }
.tab[aria-selected="true"] { color: var(--ink); }
.tab .badge { height: 20px; padding: 0 6px; }
.tab-indicator {
  position: absolute;
  left: 0; bottom: 0;
  height: 3px;
  width: 0;
  background: var(--ink);
  pointer-events: none;
  transform-origin: left;
}
.tabs-arrow { flex: none; width: 44px; border: 0; border-left: 1px solid var(--line); background: var(--bg); display: inline-flex; align-items: center; justify-content: center; }
.tabs-arrow:first-child { border-left: 0; border-right: 1px solid var(--line); }
.tabs-arrow:disabled { color: var(--line); cursor: default; }

/* ---------- Accordion ---------- */
.accordion { border-top: 1px solid var(--line); }
.accordion-item { border-bottom: 1px solid var(--line); }
.accordion-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  min-height: 64px;
  padding: var(--s-4) 0;
  list-style: none;
  cursor: pointer;
  font-weight: 700;
  font-size: 17px;
  line-height: 1.4;
}
.accordion-summary::-webkit-details-marker { display: none; }
.accordion-summary:hover { color: var(--accent); }
.accordion-icon { transition: transform var(--t-small) var(--ease-out); }
.accordion-item[open] .accordion-icon { transform: rotate(45deg); }
.accordion-content { overflow: hidden; }
.accordion-inner { padding-bottom: var(--s-5); color: var(--ink-2); max-width: 68ch; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-backdrop);
  background: var(--backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s-4);
}
.modal {
  position: relative;
  z-index: var(--z-modal);
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--ink);
  box-shadow: var(--shadow-shell);
  padding: var(--s-6) var(--s-5) var(--s-5);
}
.modal-wide { max-width: 960px; }
.modal-close { position: absolute; top: var(--s-2); right: var(--s-2); }
.modal-icon { margin-bottom: var(--s-4); }
.modal-title { font-size: 22px; font-weight: 800; line-height: 1.25; letter-spacing: -.01em; padding-right: var(--s-7); }
.modal-body { margin-top: var(--s-3); color: var(--ink-2); }
.modal-body p + p { margin-top: var(--s-2); }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--s-3); margin-top: var(--s-6); }
.modal-iframe { width: 100%; height: min(75vh, 820px); border: 1px solid var(--line); margin-top: var(--s-4); background: var(--bg-soft); }

/* ---------- Toast ---------- */
.toast-region {
  position: fixed;
  left: 50%;
  bottom: var(--s-4);
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: grid;
  gap: var(--s-2);
  width: min(calc(100% - 32px), 420px);
  pointer-events: none;
}
@media (min-width: 768px) {
  .toast-region { left: auto; right: var(--s-5); bottom: var(--s-5); transform: none; }
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-4);
  background: var(--ink);
  color: var(--white);
  font-size: 15px;
  font-weight: 500;
  line-height: 1.5;
  pointer-events: auto;
  border-left: 4px solid var(--accent);
}
.toast-error { border-left-color: var(--danger); }
.toast-success { border-left-color: var(--success); }

/* ---------- Progress ---------- */
.progress { position: relative; height: 6px; background: var(--bg-sunken); overflow: hidden; }
.progress-fill { position: absolute; inset: 0; background: var(--accent); transform-origin: left; transform: scaleX(0); }

/* ---------- Stat tiles ---------- */
.stat-tile { display: grid; gap: var(--s-1); padding: var(--s-4); border: 1px solid var(--line); background: var(--bg); align-content: start; }
.stat-label { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); }
.stat-value { font-size: 28px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat-unit { font-size: 15px; font-weight: 700; color: var(--ink-3); margin-left: 3px; }
.stat-delta { font-size: 13px; color: var(--ink-3); font-weight: 600; }

/* Tooltip */
.tip-wrap { position: relative; display: inline-flex; }
.tip-btn { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; margin: -6px; color: var(--ink-3); }
.tip-btn:hover, .tip-btn[aria-expanded="true"] { color: var(--accent); }
.tooltip {
  position: absolute;
  right: -4px;
  bottom: calc(100% + 8px);
  z-index: var(--z-dropdown);
  width: max-content;
  max-width: 240px;
  padding: var(--s-2) var(--s-3);
  background: var(--ink);
  color: var(--white);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.45;
  text-transform: none;
  letter-spacing: 0;
}

/* ---------- Dropdown ---------- */
.dropdown { position: relative; display: inline-flex; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: var(--z-dropdown);
  min-width: 280px;
  background: var(--bg);
  border: 1px solid var(--ink);
  box-shadow: var(--shadow-panel);
  padding: var(--s-2);
}
.dropdown-item {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  width: 100%;
  padding: var(--s-3);
  text-align: left;
  color: var(--ink);
}
.dropdown-item:hover, .dropdown-item:focus-visible { background: var(--bg-soft); }
.dropdown-item strong { display: block; font-size: 15px; }
.dropdown-item span span { display: block; font-size: 13px; color: var(--ink-3); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); background: var(--bg); }
.table { font-size: 15px; }
.table caption { text-align: left; padding: var(--s-4) var(--s-4) var(--s-2); font-weight: 800; font-size: 17px; caption-side: top; }
.table th, .table td { padding: var(--s-3) var(--s-4); border-top: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table thead th { font-size: var(--fs-micro); font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); background: var(--bg-soft); }
.table td.num, .table .num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Notes and disclaimer ---------- */
.note-inline { display: flex; gap: var(--s-2); align-items: flex-start; color: var(--ink-2); font-size: var(--fs-small); max-width: 80ch; margin-bottom: var(--s-5); margin-top: calc(-1 * var(--s-4)); }
.note-inline .icon { margin-top: 1px; color: var(--accent); }
.disclaimer-card { display: flex; gap: var(--s-4); align-items: flex-start; padding: var(--s-5); background: var(--warning-soft); border: 1px solid var(--warning); color: var(--ink); }
.disclaimer-card > .icon { color: var(--warning-ink); }
.disclaimer-title { font-size: 18px; font-weight: 800; margin-bottom: var(--s-1); }
.notice { display: flex; gap: var(--s-3); align-items: flex-start; padding: var(--s-4); border: 1px solid var(--line); background: var(--bg-soft); font-size: 15px; }
.notice-warning { background: var(--warning-soft); border-color: var(--warning); }
.notice-error { background: var(--danger-soft); border-color: var(--danger); }
.notice .icon { margin-top: 2px; }
