/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: 42px; padding: 0 var(--sp-5);
  border: 1px solid transparent; border-radius: var(--r-full);
  font-weight: 600; font-size: var(--fs-sm); line-height: 1;
  text-decoration: none !important; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s, box-shadow 0.15s;
}
.btn:active { transform: translateY(1px); }
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--gradient-cta); background-color: var(--brand); color: #fff; box-shadow: 0 4px 14px rgba(98, 72, 255, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.18); }
.btn-primary:hover { background: linear-gradient(120deg, var(--brand-600) 0%, #4f35f0 55%, #6248ff 100%); transform: translateY(-1px); box-shadow: 0 10px 26px rgba(98, 72, 255, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.18); }
.btn-lime { background: var(--lime); color: var(--ink); box-shadow: 0 4px 14px rgba(155, 140, 255, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.35); }
.btn-lime:hover { background: #e0dbff; transform: translateY(-1px); box-shadow: 0 10px 26px rgba(155, 140, 255, 0.42); }
.btn-dark { background: var(--ink); color: #fff; }
.btn-dark:hover { background: var(--ink-3); }
.btn-outline { background: var(--surface); border-color: var(--line-strong); color: var(--text); }
.btn-outline:hover { border-color: var(--brand); color: var(--brand-700); background: var(--brand-50); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: rgba(17, 14, 47, 0.05); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { height: 34px; padding: 0 var(--sp-4); font-size: var(--fs-xs); }
.btn-lg { height: 52px; padding: 0 var(--sp-6); font-size: var(--fs-base); border-radius: var(--r-full); }
.btn-block { width: 100%; }
.btn[disabled], .btn.is-loading { opacity: 0.6; pointer-events: none; }
.btn.is-loading::after {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px;
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); color: var(--text-2);
}
.icon-btn:hover { border-color: var(--line-strong); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: var(--r-full);
  font-size: var(--fs-xs); font-weight: 600; line-height: 1.5;
  background: var(--paper); color: var(--text-2); border: 1px solid var(--line);
}
.badge-brand { background: var(--brand-50); color: var(--brand-600); border-color: var(--brand-100); }
.badge-success { background: var(--success-50); color: var(--success); border-color: transparent; }
.badge-warning { background: var(--warning-50); color: var(--warning); border-color: transparent; }
.badge-danger { background: var(--danger-50); color: var(--danger); border-color: transparent; }
.badge-info { background: var(--info-50); color: var(--info); border-color: transparent; }
.badge-lime { background: var(--brand); color: #fff; border-color: transparent; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--sp-5); box-shadow: var(--shadow-sm);
}
.card-header { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.card-header h3, .card-header h4 { margin: 0; white-space: nowrap; }
.card-flush { padding: 0; overflow: hidden; }
.card-hover { transition: border-color 0.15s, box-shadow 0.2s, transform 0.2s; }
.card-hover:hover { border-color: var(--line-strong); box-shadow: var(--shadow-md); transform: translateY(-2px); }

.stat-card { display: flex; flex-direction: column; gap: 4px; }
.stat-card .label { font-size: var(--fs-xs); color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.stat-card .value { font-family: var(--font-display); font-size: var(--fs-xl); font-weight: 700; letter-spacing: -0.02em; }
.stat-card .delta { font-size: var(--fs-xs); font-weight: 600; }
.delta.up { color: var(--success); }
.delta.down { color: var(--danger); }
.stat-icon {
  width: 36px; height: 36px; border-radius: var(--r-md); display: grid; place-items: center;
  background: var(--brand-50); color: var(--brand); margin-bottom: var(--sp-2);
}
.stat-icon svg { width: 18px; height: 18px; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-4); }
.field label, .label-text { font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); }
.input, .select, .textarea {
  width: 100%; height: 44px; padding: 0 var(--sp-4);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-md);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.textarea { height: auto; min-height: 120px; padding: var(--sp-3) var(--sp-4); resize: vertical; line-height: 1.6; }
.select {
  appearance: none; padding-right: 36px;
  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='%236b6f82' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--faint); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.field.has-error .input, .field.has-error .textarea { border-color: var(--danger); }
.field-error { font-size: var(--fs-xs); color: var(--danger); min-height: 0; }
.field-hint { font-size: var(--fs-xs); color: var(--muted); }
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 44px; }
.input-wrap .toggle-vis {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: none; color: var(--muted); padding: 6px; border-radius: var(--r-sm);
}
.input-wrap .toggle-vis svg { width: 18px; height: 18px; }
.checkbox { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); color: var(--text-2); cursor: pointer; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--brand); }

.strength { display: flex; gap: 4px; margin-top: 2px; }
.strength span { flex: 1; height: 4px; border-radius: 2px; background: var(--line); transition: background 0.2s; }
.strength[data-level="1"] span:nth-child(-n + 1) { background: var(--danger); }
.strength[data-level="2"] span:nth-child(-n + 2) { background: var(--warning); }
.strength[data-level="3"] span:nth-child(-n + 3) { background: #6248ff; }
.strength[data-level="4"] span:nth-child(-n + 4) { background: var(--success); }

/* Segmented / choice controls */
.segmented { display: inline-flex; padding: 4px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-md); gap: 2px; flex-wrap: wrap; }
.segmented button {
  border: 0; background: transparent; padding: 8px 16px; border-radius: 7px;
  font-size: var(--fs-sm); font-weight: 600; color: var(--muted);
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.choice-grid { display: grid; gap: var(--sp-3); grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.choice {
  position: relative; text-align: left; display: flex; flex-direction: column; gap: 6px;
  padding: var(--sp-4); background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--r-lg);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.choice:hover { border-color: var(--line-strong); }
.choice[aria-checked="true"] { border-color: var(--brand); background: var(--brand-50); box-shadow: 0 0 0 1px var(--brand) inset; }
.choice .choice-icon { width: 38px; height: 38px; border-radius: var(--r-md); display: grid; place-items: center; background: var(--paper); color: var(--text-2); }
.choice[aria-checked="true"] .choice-icon { background: var(--brand); color: #fff; }
.choice .choice-icon svg { width: 20px; height: 20px; }
.choice strong { font-family: var(--font-display); font-size: var(--fs-base); }
.choice .check {
  position: absolute; top: 12px; right: 12px; width: 20px; height: 20px; border-radius: 50%;
  border: 1.5px solid var(--line-strong); display: grid; place-items: center; color: #fff;
}
.choice[aria-checked="true"] .check { background: var(--brand); border-color: var(--brand); }
.choice .check svg { width: 12px; height: 12px; }

/* ---------- Table ---------- */
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th {
  text-align: left; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); font-weight: 600; padding: 12px var(--sp-5); background: var(--surface-2);
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 14px var(--sp-5); border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background 0.1s; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: var(--surface-2); }

.score-pill {
  display: inline-grid; place-items: center; min-width: 42px; height: 26px; padding: 0 8px;
  border-radius: var(--r-full); font-weight: 700; font-size: var(--fs-xs); font-family: var(--font-display);
}
.score-high { background: var(--success-50); color: var(--success); }
.score-mid { background: var(--warning-50); color: var(--warning); }
.score-low { background: var(--danger-50); color: var(--danger); }

/* ---------- Progress ---------- */
.progress { height: 8px; background: var(--paper); border-radius: var(--r-full); overflow: hidden; border: 1px solid var(--line); }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: inherit; transition: width 0.6s var(--ease); }
.progress.lime > span { background: var(--lime-600); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; background: rgba(17, 14, 47, 0.5);
  display: grid; place-items: center; padding: var(--sp-5);
  animation: fade-in 0.15s ease;
}
.modal {
  width: 100%; max-width: 460px; background: var(--surface); border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg); padding: var(--sp-6); animation: pop-in 0.2s var(--ease);
}
.modal h3 { margin-bottom: var(--sp-2); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); margin-top: var(--sp-5); }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.96) translateY(6px); } }

/* ---------- Toast ---------- */
.toast-stack { position: fixed; z-index: 200; bottom: var(--sp-5); right: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-2); max-width: calc(100vw - 32px); }
.toast {
  display: flex; align-items: flex-start; gap: var(--sp-3); min-width: 280px; max-width: 380px;
  padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); background: var(--ink); color: #fff;
  box-shadow: var(--shadow-lg); font-size: var(--fs-sm); animation: toast-in 0.25s var(--ease);
}
.toast svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.toast.success svg { color: var(--lime); }
.toast.error svg { color: #ff8a8a; }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: all 0.2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ---------- Accordion ---------- */
.accordion-item { border-bottom: 1px solid var(--line); }
.accordion-trigger {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
  padding: var(--sp-5) 0; background: none; border: 0; text-align: left;
  font-family: var(--font-display); font-weight: 600; font-size: var(--fs-md);
}
.accordion-trigger svg { width: 20px; height: 20px; flex-shrink: 0; transition: transform 0.25s var(--ease); color: var(--muted); }
.accordion-item.open .accordion-trigger svg { transform: rotate(45deg); color: var(--brand); }
.accordion-panel { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.3s var(--ease); }
.accordion-panel > div { overflow: hidden; }
.accordion-item.open .accordion-panel { grid-template-rows: 1fr; }
.accordion-panel p { color: var(--text-2); padding-bottom: var(--sp-5); margin: 0; }

/* ---------- Misc ---------- */
.empty-state { text-align: center; padding: var(--sp-8) var(--sp-5); }
.empty-state .empty-icon {
  width: 56px; height: 56px; margin: 0 auto var(--sp-4); border-radius: var(--r-lg);
  display: grid; place-items: center; background: var(--brand-50); color: var(--brand);
}
.empty-state .empty-icon svg { width: 26px; height: 26px; }
.empty-state p { color: var(--muted); max-width: 380px; margin: 0 auto var(--sp-5); }

.skeleton { background: linear-gradient(90deg, var(--line) 25%, var(--surface-2) 50%, var(--line) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: var(--r-sm); }
@keyframes shimmer { to { background-position: -200% 0; } }

.divider { display: flex; align-items: center; gap: var(--sp-3); color: var(--faint); font-size: var(--fs-xs); margin: var(--sp-5) 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.alert { display: flex; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); font-size: var(--fs-sm); }
.alert svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 2px; }
.alert-info { background: var(--info-50); color: #1e40af; }
.alert-danger { background: var(--danger-50); color: #991b1b; }
.alert-success { background: var(--success-50); color: #166534; }

.list-check { list-style: none; padding: 0; margin: 0; }
.list-check li { display: flex; gap: var(--sp-2); align-items: flex-start; padding: 5px 0; color: var(--text-2); font-size: var(--fs-sm); }
.list-check li svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 2px; }
.list-check .ok svg { color: var(--success); }
.list-check .todo svg { color: var(--faint); }
.list-check .warn svg { color: var(--warning); }

.kbd { font-family: var(--font-mono); font-size: 0.75em; padding: 2px 6px; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; background: var(--surface); }

/* CSS bar chart fallback (when Chart.js can't load) */
.bar-fallback { display: flex; align-items: flex-end; gap: 6px; height: 200px; padding-top: var(--sp-4); }
.bar-fallback .bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; height: 100%; }
.bar-fallback .bar span { width: 100%; max-width: 40px; background: var(--brand); border-radius: 6px 6px 2px 2px; min-height: 4px; }
.bar-fallback .bar small { font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.hbar-fallback { display: flex; flex-direction: column; gap: var(--sp-3); }
.hbar-fallback .hbar { display: grid; grid-template-columns: 130px 1fr 36px; gap: var(--sp-3); align-items: center; font-size: var(--fs-sm); }
.hbar-fallback .hbar .progress { height: 10px; }

/* Button hover: brush "cut" effect. A 30-frame brush mask steps across a colour layer behind the label. */
.btn:not(.btn-ghost) { position: relative; overflow: hidden; isolation: isolate; --btn-cut: #340859; --btn-cut-text: #fff; }
.btn:not(.btn-ghost)::before {
  content: ""; position: absolute; inset: -1px; z-index: -1; border-radius: inherit; background: var(--btn-cut); pointer-events: none;
  -webkit-mask-image: url("../assets/images/btn-mask.svg"); mask-image: url("../assets/images/btn-mask.svg");
  -webkit-mask-size: 3000% 100%; mask-size: 3000% 100%; -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  -webkit-mask-position: 100% 0; mask-position: 100% 0;
  transition: -webkit-mask-position 0.6s steps(29), mask-position 0.6s steps(29);
}
.btn:not(.btn-ghost):hover::before, .btn:not(.btn-ghost):focus-visible::before { -webkit-mask-position: 0 0; mask-position: 0 0; }
.btn:not(.btn-ghost):hover, .btn:not(.btn-ghost):focus-visible { color: var(--btn-cut-text); transition: color 0.2s 0.15s, border-color 0.2s, box-shadow 0.15s, transform 0.1s; }
.btn.btn-dark, .btn.btn-primary { --btn-cut: #16a6a1; }
.btn-outline:hover { border-color: #340859; }
.fbx-btn-main:hover { color: #fff; filter: none; }
.btn.fbx-btn-ghost { --btn-cut: #2fd6cc; --btn-cut-text: #0f0626; }
.fbx-btn-ghost:hover { color: #0f0626; border-color: #2fd6cc; }
.btn:not(.btn-ghost):hover svg { color: inherit; }
@media (prefers-reduced-motion: reduce) {
  .btn:not(.btn-ghost)::before { transition-duration: 0.6s !important; }
}

/* ---------------- credits chip (app top bar) ---------------- */
.credit-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--brand-50, #eef0fe);
  color: var(--brand-700, #3d47d9);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s ease;
}
.credit-chip:hover { background: #e3e6fd; }
.credit-chip b { font-weight: 700; font-variant-numeric: tabular-nums; }
.credit-chip span { font-weight: 500; color: var(--muted, #6b6f80); }
.credit-chip.low { background: #fff4e5; color: #b45309; }
.credit-chip.low span { color: #b45309; opacity: .75; }
@media (max-width: 720px) { .credit-chip span { display: none; } }
