/* ==========================================================================
   Apiro — components: cards, badges, code, tabs, gauge, flags, FAQ, forms, tables
   ========================================================================== */

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(20px, 2.4vw, 28px);
  box-shadow: var(--shadow-sm);
}
.card h3 + p { margin-top: 8px; color: var(--ink-2); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.72rem; font-weight: 600; line-height: 1.4;
  letter-spacing: 0.02em;
  background: var(--bg-tint);
  color: var(--ink-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.9; }
.badge--plain::before { display: none; }
.badge--ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge--warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge--high { background: var(--high-bg); color: var(--high); border-color: transparent; }
.badge--crit { background: var(--crit-bg); color: var(--crit); border-color: transparent; }
.badge--planned {
  color: var(--violet);
  background: color-mix(in srgb, var(--violet) 9%, transparent);
  border-color: color-mix(in srgb, var(--violet) 28%, transparent);
}
:root[data-theme="dark"] .badge--planned { color: #b98cff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge--planned { color: #b98cff; } }
.badge--planned::before { display: none; }

/* ---------- Code blocks ---------- */
.code {
  position: relative;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  overflow: hidden;
  color: var(--code-ink);
  box-shadow: var(--shadow-md);
  min-width: 0;
}
.code-bar {
  display: flex; align-items: center; gap: 12px;
  min-height: 44px;
  padding: 0 10px 0 16px;
  background: var(--code-bar);
  border-bottom: 1px solid var(--code-border);
}
.code-title { font-family: var(--font-mono); font-size: 0.78rem; color: #8f9abf; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.code-bar .spacer { flex: 1; }
.code pre {
  margin: 0;
  padding: 18px 20px 20px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.84rem;
  line-height: 1.7;
  tab-size: 2;
  scrollbar-width: thin;
  scrollbar-color: #2a3560 transparent;
}
.code pre code { font-size: inherit; white-space: pre; }
code, kbd, samp, .formula, .mono { font-variant-ligatures: none; }
.code--wrap pre code { white-space: pre-wrap; word-break: break-word; }

.copy-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 10px;
  border-radius: 8px;
  border: 1px solid #26305a;
  background: #121a36;
  color: #c3cbe8;
  font-family: var(--font-mono); font-size: 0.74rem; font-weight: 500;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.copy-btn:hover { background: #18214a; color: #fff; border-color: #34407a; }
.copy-btn svg { width: 14px; height: 14px; }
.copy-btn.is-copied { color: #5eead4; border-color: #1f5f5a; }

/* Language switcher inside a code bar */
.code-langs { display: flex; gap: 2px; }
.code-langs button {
  height: 30px; padding: 0 10px;
  border: 0; border-radius: 8px;
  background: transparent;
  color: #8f9abf;
  font-family: var(--font-mono); font-size: 0.76rem; font-weight: 500;
}
.code-langs button:hover { color: #e6ebff; }
.code-langs button[aria-selected="true"] { color: #fff; background: #1a2346; }

/* Syntax tokens — hues drawn from the logo gradient */
.tk-key { color: #67e3fb; }
.tk-str { color: #d7b8ff; }
.tk-num { color: #ffc27a; }
.tk-bool, .tk-null { color: #ff7ac6; }
.tk-kw { color: #ff7ac6; }
.tk-fn { color: #8fb8ff; }
.tk-builtin { color: #67e3fb; }
.tk-flag { color: #ff9ad5; }
.tk-com { color: #6c779c; font-style: italic; }
.tk-punc { color: #8d97bb; }
.tk-op { color: #b6c0e3; }
.tk-dec { color: #ffc27a; }

/* ---------- Tabs ---------- */
.tab-list {
  display: inline-flex; flex-wrap: wrap; gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: var(--bg-tint);
  border: 1px solid var(--border);
}
.tab-list [role="tab"] {
  min-height: 38px; padding: 0 16px;
  border: 0; border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font-size: 0.9rem; font-weight: 600;
  transition: color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}
.tab-list [role="tab"]:hover { color: var(--ink); }
.tab-list [role="tab"][aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); }
[role="tabpanel"]:focus-visible { outline-offset: 6px; }

/* ---------- Score gauge ---------- */
.gauge { --pos: 0%; position: relative; padding-top: 30px; }
.gauge-track {
  display: grid;
  grid-template-columns: 25fr 20fr 25fr 30fr;
  gap: 3px;
  height: 10px;
}
.gauge-track span { border-radius: 3px; }
.gauge-track span:nth-child(1) { background: var(--crit-solid); }
.gauge-track span:nth-child(2) { background: var(--high-solid); }
.gauge-track span:nth-child(3) { background: var(--warn-solid); }
.gauge-track span:nth-child(4) { background: var(--ok-solid); }
.gauge-marker {
  position: absolute; top: 0; left: var(--pos);
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center;
  transition: left 0.9s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.gauge-marker b {
  font-family: var(--font-mono); font-size: 0.75rem; font-weight: 600;
  padding: 2px 7px; border-radius: 6px;
  background: var(--ink); color: var(--bg);
}
.gauge-marker::after { content: ""; width: 2px; height: 18px; margin-top: 2px; background: var(--ink); border-radius: 2px; }
.gauge-scale {
  position: relative; height: 18px; margin-top: 8px;
  font-family: var(--font-mono); font-size: 0.7rem; color: var(--ink-3);
}
.gauge-scale span { position: absolute; transform: translateX(-50%); }
.gauge-scale span:first-child { transform: none; }
.gauge-scale span:last-child { transform: translateX(-100%); }
.gauge-legend {
  display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px;
  font-family: var(--font-mono); font-size: 0.72rem; color: var(--ink-3);
}
.gauge-legend span { display: inline-flex; align-items: center; gap: 6px; }
.gauge-legend i { width: 8px; height: 8px; border-radius: 2px; }

/* ---------- Flag cards ---------- */
.flag {
  --sev: var(--crit-solid);
  position: relative;
  padding: 16px 18px 16px 20px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
}
.flag::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--sev); }
.flag--high { --sev: var(--high-solid); }
.flag--moderate { --sev: var(--warn-solid); }
.flag-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.flag-name { font-family: var(--font-mono); font-size: 0.86rem; font-weight: 600; color: var(--ink); }
.flag-value { margin-left: auto; font-family: var(--font-mono); font-size: 0.86rem; color: var(--ink-2); }
.flag-detail { margin-top: 8px; color: var(--ink-2); font-size: 0.93rem; line-height: 1.6; }

/* ---------- Metric list ---------- */
.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.metrics div { background: var(--surface); padding: 12px 14px; min-width: 0; }
.metrics dt { font-family: var(--font-mono); font-size: 0.7rem; color: var(--ink-3); overflow-wrap: anywhere; }
.metrics dd { margin-top: 4px; font-family: var(--font-mono); font-size: 0.95rem; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---------- Callouts ---------- */
.callout {
  display: flex; gap: 12px;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--bg-tint);
  border: 1px solid var(--border);
  color: var(--ink-2);
  font-size: 0.93rem;
}
.callout svg { flex: none; width: 18px; height: 18px; margin-top: 3px; color: var(--link); }
.callout strong { color: var(--ink); }

/* ---------- FAQ ---------- */
.faq { border-top: 1px solid var(--border); }
.faq details { border-bottom: 1px solid var(--border); }
.faq summary {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 22px 4px;
  list-style: none; cursor: pointer;
  font-family: var(--font-display); font-size: clamp(1.02rem, 1.5vw, 1.18rem); font-weight: 600; letter-spacing: -0.01em;
  color: var(--ink);
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: ""; flex: none; width: 28px; height: 28px; border-radius: 50%;
  border: 1px solid var(--border-strong);
  background:
    linear-gradient(var(--ink-2), var(--ink-2)) center / 11px 1.5px no-repeat,
    linear-gradient(var(--ink-2), var(--ink-2)) center / 1.5px 11px no-repeat;
  transition: transform 0.25s ease;
}
.faq details[open] summary::after { transform: rotate(45deg); }
.faq .faq-body { padding: 0 4px 24px; max-width: 72ch; color: var(--ink-2); }
.faq .faq-body p + p { margin-top: 10px; }

/* ---------- Forms ---------- */
.field { display: grid; gap: 7px; }
.field label { font-size: 0.875rem; font-weight: 600; color: var(--ink); }
.field .hint { font-size: 0.8rem; color: var(--ink-3); }
.input, .select, .textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.95rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.input::placeholder, .textarea::placeholder { color: var(--ink-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.input[aria-invalid="true"] { border-color: var(--crit-solid); }
.select {
  appearance: none;
  padding-right: 38px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.textarea { min-height: 96px; resize: vertical; }
.form-error { font-size: 0.82rem; color: var(--crit); }
.form-status { font-size: 0.9rem; border-radius: 10px; padding: 12px 14px; }
.form-status.is-ok { background: var(--ok-bg); color: var(--ok); }
.form-status.is-warn { background: var(--warn-bg); color: var(--warn); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.data-table { width: 100%; font-size: 0.93rem; }
.data-table th, .data-table td { padding: 12px 16px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.data-table thead th {
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 500;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3);
  background: var(--surface-2);
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table td code { white-space: nowrap; }
.data-table .right { text-align: right; }

/* Stack table rows as cards on narrow screens instead of scrolling */
@media (max-width: 640px) {
  .table-stack { border: 0; background: transparent; overflow: visible; }
  .table-stack .data-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table-stack .data-table, .table-stack .data-table tbody, .table-stack .data-table tr, .table-stack .data-table td { display: block; width: 100%; }
  .table-stack .data-table tr { margin-bottom: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); overflow: hidden; }
  .table-stack .data-table td { border-bottom: 1px solid var(--border); padding: 10px 14px; }
  .table-stack .data-table td:last-child { border-bottom: 0; }
  .table-stack .data-table td[data-label]::before {
    content: attr(data-label);
    display: block; margin-bottom: 3px;
    font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3);
  }
  .table-stack .data-table td code { white-space: normal; overflow-wrap: anywhere; }
}

/* ---------- Misc ---------- */
.divider { height: 1px; background: var(--border); border: 0; margin: 0; }
.dot-list { list-style: none; padding: 0; display: grid; gap: 10px; }
.dot-list li { position: relative; padding-left: 22px; color: var(--ink-2); }
.dot-list li::before {
  content: ""; position: absolute; left: 2px; top: 0.62em;
  width: 8px; height: 8px; border-radius: 2px;
  background: var(--grad-brand);
  transform: rotate(45deg);
}
.check-list { list-style: none; padding: 0; display: grid; gap: 10px; }
.check-list li { display: flex; gap: 10px; align-items: flex-start; color: var(--ink-2); font-size: 0.95rem; }
.check-list li::before {
  content: ""; flex: none; width: 18px; height: 18px; margin-top: 3px; border-radius: 50%;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='white' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5.5 10.5l3 3 6-7'/%3E%3C/svg%3E") center / 12px no-repeat,
    var(--grad-button);
}
