/* ================================================================
   MELAGENCE CI — COMPONENTS
   Refined, documented, and slightly smarter than the originals.
   ================================================================ */

/* ── BUTTONS ───────────────────────────────────────── */
.btn {
  --btn-bg: var(--ink);
  --btn-fg: var(--paper);
  --btn-bd: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: var(--t-sm);
  letter-spacing: var(--ls-base);
  line-height: 1;
  padding: 11px 20px;
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: var(--bw-hair) solid var(--btn-bd);
  border-radius: var(--r-md);
  cursor: pointer;
  text-decoration: none;
  transition: background var(--d-base) var(--ease-out),
              color var(--d-base) var(--ease-out),
              border-color var(--d-base) var(--ease-out),
              transform var(--d-fast) var(--ease-out);
  user-select: none;
}
.btn:hover { --btn-bg: var(--ink-soft); }
.btn:active { transform: translateY(0.5px); }
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--chalk), 0 0 0 4px var(--ink);
}
.btn:disabled, .btn[aria-disabled="true"] {
  --btn-bg: var(--mist);
  --btn-bd: var(--mist);
  --btn-fg: var(--slate);
  cursor: not-allowed;
}

.btn--outline {
  --btn-bg: transparent;
  --btn-fg: var(--ink);
  --btn-bd: var(--ink);
}
.btn--outline:hover { --btn-bg: var(--ink); --btn-fg: var(--paper); }

.btn--ghost {
  --btn-bg: transparent;
  --btn-fg: var(--ink);
  --btn-bd: transparent;
}
.btn--ghost:hover { --btn-bg: var(--bone); }

.btn--accent {
  --btn-bg: var(--accent);
  --btn-fg: var(--snow);
  --btn-bd: var(--accent);
}
.btn--accent:hover { --btn-bg: #8E2D4F; --btn-bd: #8E2D4F; }

.btn--sm { font-size: var(--t-xs); padding: 7px 12px; }
.btn--lg { font-size: var(--t-body); padding: 14px 26px; }
.btn--icon { padding: 10px; aspect-ratio: 1; }

.btn-row { display: inline-flex; gap: var(--s-3); align-items: center; flex-wrap: wrap; }

/* ── BADGES ────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 9px;
  font-weight: 500;
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: var(--r-sm);
  line-height: 1;
  white-space: nowrap;
}
.badge::before {
  content: "";
  display: inline-block;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
}
.badge--plain::before { display: none; }

.badge--retained    { color: var(--ink);      background: var(--bone); }
.badge--new         { color: var(--positive); background: var(--positive-tint); }
.badge--winback     { color: var(--accent);   background: var(--accent-tint); }
.badge--lost        { color: var(--slate);    background: var(--bone); }
.badge--targeted    { color: var(--caution);  background: var(--caution-tint); }
.badge--ordered     { color: var(--positive); background: var(--positive-tint); }
.badge--notordered  { color: var(--slate);    background: var(--bone); }
.badge--critical    { color: var(--negative); background: var(--negative-tint); }

.badge--ink         { color: var(--paper);    background: var(--ink); }

/* ── FORM CONTROLS ─────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field-label {
  font-size: var(--t-micro);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--ink);
  font-weight: 500;
}
.field-help {
  font-size: var(--t-xs);
  color: var(--slate);
  margin-top: 2px;
}
.field-error {
  font-size: var(--t-xs);
  color: var(--negative);
  margin-top: 2px;
}

.input, .select, .textarea {
  font-family: var(--font-body);
  font-size: var(--t-sm);
  color: var(--ink);
  background: var(--snow);
  border: var(--bw-hair) solid var(--mist);
  border-radius: var(--r-md);
  padding: 10px 12px;
  transition: border-color var(--d-base) var(--ease-out),
              box-shadow var(--d-base) var(--ease-out);
  width: 100%;
  line-height: 1.3;
}
.input::placeholder, .textarea::placeholder { color: var(--slate); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--graphite); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
}
.input[aria-invalid="true"] { border-color: var(--negative); }
.input:disabled { background: var(--bone); color: var(--slate); cursor: not-allowed; }

.select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'><path d='M1 3.5L5 7.5L9 3.5' stroke='%230A0A0A' stroke-width='1' fill='none'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.textarea { min-height: 96px; resize: vertical; }

/* Checkbox / radio */
.check {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  cursor: pointer;
  font-size: var(--t-sm);
  color: var(--ink);
}
.check input {
  appearance: none;
  width: 16px; height: 16px;
  border: var(--bw-thin) solid var(--ink);
  border-radius: var(--r-sm);
  background: var(--snow);
  display: inline-grid; place-content: center;
  cursor: pointer;
  transition: background var(--d-fast) var(--ease-out);
  flex-shrink: 0;
}
.check input[type="radio"] { border-radius: 50%; }
.check input:checked { background: var(--ink); }
.check input:checked::after {
  content: "";
  width: 8px; height: 8px;
  background: var(--paper);
}
.check input[type="checkbox"]:checked::after {
  width: 10px; height: 6px;
  background: transparent;
  border-left: 1.25px solid var(--paper);
  border-bottom: 1.25px solid var(--paper);
  transform: rotate(-45deg) translate(1px, -1px);
}
.check input[type="radio"]:checked::after {
  border-radius: 50%;
}

/* Toggle */
.toggle {
  --tg-bg: var(--mist);
  appearance: none;
  width: 36px; height: 20px;
  background: var(--tg-bg);
  border-radius: var(--r-pill);
  position: relative;
  cursor: pointer;
  transition: background var(--d-base) var(--ease-out);
  flex-shrink: 0;
}
.toggle::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: var(--snow);
  border-radius: 50%;
  transition: transform var(--d-base) var(--ease-out);
}
.toggle:checked { --tg-bg: var(--ink); }
.toggle:checked::after { transform: translateX(16px); }

/* ── SEARCH / INPUT WITH ICON ─────────────────────── */
.input-group {
  position: relative;
  display: flex;
  align-items: center;
}
.input-group .input { padding-left: 36px; }
.input-group .icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--slate);
  pointer-events: none;
}

/* ── SWATCHES ──────────────────────────────────────── */
.swatch-row { display: flex; gap: 0; border: var(--bw-hair) solid var(--fog); border-radius: 0; overflow: hidden; }
.swatch { height: 88px; flex: 1; position: relative; }
.swatch--sm { height: 56px; }
.swatch-info { display: flex; margin-top: var(--s-2); }
.swatch-cell { flex: 1; padding-right: var(--s-3); }
.swatch-name {
  font-size: var(--t-xs);
  font-weight: 500;
  display: block;
  letter-spacing: var(--ls-base);
}
.swatch-hex {
  font-size: var(--t-micro);
  color: var(--slate);
  display: block;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}
.swatch-role {
  font-size: var(--t-micro);
  color: var(--graphite);
  display: block;
  margin-top: 2px;
}

/* ── BRAND CARDS ───────────────────────────────────── */
.bc-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; border-top: var(--bw-thin) solid var(--ink); border-bottom: var(--bw-thin) solid var(--ink); }
.bc { padding: var(--s-6) var(--s-5); position: relative; transition: background var(--d-base) var(--ease-out); }
.bc:not(:last-child) { border-right: var(--bw-thin) solid var(--ink); }
.bc:hover { background: var(--bone); }
.bc-cat {
  font-size: var(--t-micro);
  font-weight: 500;
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--slate);
  margin-bottom: var(--s-3);
}
.bc-name {
  font-size: var(--t-md);
  font-weight: 500;
  line-height: 1.2;
  margin-bottom: var(--s-2);
  letter-spacing: var(--ls-normal);
}
.bc-sub { font-size: var(--t-sm); color: var(--graphite); }

/* ── KPI CARDS ─────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; border-top: var(--bw-thin) solid var(--ink); border-bottom: var(--bw-thin) solid var(--ink); }
.kpi { padding: var(--s-5) var(--s-5); }
.kpi:not(:last-child) { border-right: var(--bw-hair) solid var(--mist); }
.kpi-lbl {
  font-size: var(--t-micro);
  font-weight: 500;
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--slate);
  margin-bottom: var(--s-3);
}
.kpi-val {
  font-size: 36px;
  font-weight: 500;
  letter-spacing: var(--ls-snug);
  line-height: 1;
  margin-bottom: var(--s-2);
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.kpi-sub {
  font-size: var(--t-xs);
  color: var(--graphite);
}
.trend-up { color: var(--positive); font-size: 16px; }
.trend-dn { color: var(--negative); font-size: 16px; }

/* ── TABLES ────────────────────────────────────────── */
.tbl { width: 100%; border-collapse: collapse; font-size: var(--t-sm); font-variant-numeric: tabular-nums; }
.tbl thead tr { border-top: var(--bw-thin) solid var(--ink); border-bottom: var(--bw-thin) solid var(--ink); }
.tbl thead th {
  font-size: 9px;
  font-weight: 500;
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--ink);
  padding: 10px 12px;
  text-align: left;
  vertical-align: bottom;
}
.tbl th.num, .tbl td.num { text-align: right; }
.tbl tbody td { padding: 12px; border-bottom: var(--bw-hair) solid var(--mist); vertical-align: middle; }
.tbl tbody tr { transition: background var(--d-fast) var(--ease-out); }
.tbl tbody tr:hover { background: var(--bone); }
.tbl tfoot td {
  padding: 12px;
  font-weight: 500;
  border-top: var(--bw-thin) solid var(--ink);
  border-bottom: var(--bw-thin) solid var(--ink);
}

/* Density variants */
.tbl--compact tbody td, .tbl--compact thead th { padding: 6px 10px; }
.tbl--dense tbody td, .tbl--dense thead th { padding: 8px 10px; font-size: var(--t-xs); }
.tbl--dense { font-size: var(--t-xs); }
.tbl--sparse tbody td, .tbl--sparse thead th { padding: 18px 12px; }
.tbl--sparse thead th { padding-bottom: 12px; }

/* Striped variant (optional) */
.tbl--striped tbody tr:nth-child(even) { background: var(--chalk); }
.tbl--striped tbody tr:hover { background: var(--bone); }

/* Black-foot (totals row in ink) */
.tbl--ink-foot tfoot tr { background: var(--ink); color: var(--paper); }
.tbl--ink-foot tfoot td { border-color: var(--ink); color: var(--paper); }
.tbl--ink-foot tfoot td.pos { color: var(--positive); }
.tbl--ink-foot tfoot td.neg { color: var(--negative); }

/* ── NAVIGATION ────────────────────────────────────── */
.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s-4) var(--s-6);
  border-bottom: var(--bw-thin) solid var(--ink);
  background: var(--chalk);
  gap: var(--s-6);
}
.topnav-brand {
  display: inline-flex;
  align-items: center;
  color: var(--ink);
}
.topnav-brand svg { width: 130px; height: auto; display: block; }
.topnav-links {
  display: flex;
  gap: var(--s-5);
  list-style: none;
}
.topnav-links a {
  font-size: var(--t-sm);
  color: var(--ink);
  text-decoration: none;
  padding: 4px 0;
  border-bottom: var(--bw-hair) solid transparent;
  transition: border-color var(--d-base) var(--ease-out), color var(--d-base) var(--ease-out);
}
.topnav-links a:hover, .topnav-links a[aria-current="page"] { border-bottom-color: var(--ink); }

.tabs {
  display: flex;
  border-bottom: var(--bw-thin) solid var(--mist);
  gap: 0;
}
.tabs a {
  font-size: var(--t-sm);
  color: var(--graphite);
  text-decoration: none;
  padding: var(--s-3) var(--s-4);
  border-bottom: 1.5px solid transparent;
  margin-bottom: -1.5px;
  transition: color var(--d-base) var(--ease-out), border-color var(--d-base) var(--ease-out);
  font-weight: 500;
  letter-spacing: var(--ls-base);
}
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"], .tabs a.active { color: var(--ink); border-bottom-color: var(--ink); }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-size: var(--t-xs);
  color: var(--slate);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
}
.breadcrumb a { color: var(--slate); text-decoration: none; transition: color var(--d-base) var(--ease-out); }
.breadcrumb a:hover { color: var(--ink); }
.breadcrumb a[aria-current="page"] { color: var(--ink); }
.breadcrumb-sep { color: var(--mist); }

.sidebar {
  width: 220px;
  border-right: var(--bw-thin) solid var(--mist);
  padding: var(--s-5) 0;
}
.sidebar-group { padding: 0 var(--s-4) var(--s-4); }
.sidebar-heading {
  font-size: var(--t-micro);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--slate);
  margin-bottom: var(--s-2);
  padding-left: var(--s-3);
}
.sidebar-item {
  display: block;
  font-size: var(--t-sm);
  color: var(--graphite);
  text-decoration: none;
  padding: 8px var(--s-3);
  border-left: 2px solid transparent;
  transition: border-color var(--d-base) var(--ease-out), color var(--d-base) var(--ease-out), background var(--d-base) var(--ease-out);
}
.sidebar-item:hover { color: var(--ink); background: var(--bone); }
.sidebar-item.active { color: var(--ink); border-left-color: var(--ink); background: var(--bone); }

/* ── MODAL ─────────────────────────────────────────── */
.modal-demo {
  position: relative;
  background: var(--bone);
  padding: var(--s-7);
  border-radius: var(--r-md);
  overflow: hidden;
  min-height: 280px;
}
.modal {
  background: var(--snow);
  border: var(--bw-hair) solid var(--mist);
  border-radius: var(--r-md);
  padding: var(--s-6);
  box-shadow: var(--shadow-2);
  max-width: 420px;
  margin: 0 auto;
}
.modal-title {
  font-size: var(--t-lg);
  font-weight: 500;
  letter-spacing: var(--ls-normal);
  margin-bottom: var(--s-3);
  line-height: var(--lh-snug);
}
.modal-body {
  font-size: var(--t-sm);
  color: var(--graphite);
  line-height: var(--lh-relaxed);
  margin-bottom: var(--s-5);
}
.modal-foot { display: flex; justify-content: flex-end; gap: var(--s-3); }

.toast {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  background: var(--ink);
  color: var(--paper);
  padding: 12px var(--s-4);
  border-radius: var(--r-md);
  font-size: var(--t-sm);
  max-width: 380px;
  box-shadow: var(--shadow-2);
}
.toast-icon { flex-shrink: 0; color: var(--positive); }

.drawer {
  background: var(--snow);
  border: var(--bw-hair) solid var(--mist);
  border-radius: var(--r-md);
  width: 100%;
  max-width: 320px;
  padding: var(--s-5);
  box-shadow: var(--shadow-2);
}

/* ── FEEDBACK BLOCK ────────────────────────────────── */
.fb {
  border-left: var(--bw-med) solid var(--ink);
  padding: var(--s-5) var(--s-5);
  background: var(--snow);
  margin-bottom: var(--s-4);
}
.fb-hdr { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--s-4); gap: var(--s-4); }
.fb-name { font-size: var(--t-body); font-weight: 500; letter-spacing: var(--ls-normal); }
.fb-scores { display: flex; gap: var(--s-6); margin-bottom: var(--s-4); flex-wrap: wrap; }
.sc-lbl {
  font-size: var(--t-micro);
  font-weight: 500;
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  margin-bottom: 6px;
  color: var(--slate);
}
.dots { display: flex; gap: 4px; margin-bottom: 4px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink); display: inline-block; }
.dot--off { background: var(--mist); }
.sc-num { font-size: var(--t-xs); font-weight: 500; font-variant-numeric: tabular-nums; }
.fb-txt { font-size: var(--t-sm); line-height: var(--lh-relaxed); color: var(--graphite); max-width: 560px; }

/* ── CTA BLOCKS ────────────────────────────────────── */
.cta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-4); }
.cta {
  padding: var(--s-6);
  border-radius: var(--r-md);
}
.cta--bordered { border: var(--bw-thin) solid var(--ink); background: transparent; }
.cta--paper    { background: var(--paper); }
.cta--ink      { background: var(--ink); color: var(--paper); }
.cta--ink .cta-body { color: rgba(244,239,230,0.7); }
.cta--ink .btn--outline { --btn-fg: var(--paper); --btn-bd: var(--paper); }
.cta--ink .btn--outline:hover { --btn-bg: var(--paper); --btn-fg: var(--ink); }
.cta-ttl {
  font-size: var(--t-lg);
  font-weight: 500;
  letter-spacing: var(--ls-normal);
  line-height: var(--lh-snug);
  margin-bottom: var(--s-3);
  text-wrap: balance;
}
.cta-body {
  font-size: var(--t-sm);
  line-height: var(--lh-relaxed);
  color: var(--graphite);
  margin-bottom: var(--s-5);
  max-width: 38ch;
}

/* ── STATES (empty / loading / error) ──────────────── */
.state {
  text-align: center;
  padding: var(--s-8) var(--s-5);
  border: var(--bw-hair) dashed var(--mist);
  border-radius: var(--r-md);
  background: var(--chalk);
}
.state-icon {
  width: 40px; height: 40px;
  margin: 0 auto var(--s-4);
  color: var(--slate);
}
.state-title {
  font-size: var(--t-md);
  font-weight: 500;
  letter-spacing: var(--ls-normal);
  margin-bottom: var(--s-2);
}
.state-body {
  font-size: var(--t-sm);
  color: var(--graphite);
  max-width: 36ch;
  margin: 0 auto var(--s-5);
  line-height: var(--lh-relaxed);
}

.skeleton {
  background: linear-gradient(90deg, var(--mist) 0%, var(--bone) 50%, var(--mist) 100%);
  background-size: 200% 100%;
  border-radius: var(--r-sm);
  animation: shimmer 1.4s var(--ease-io) infinite;
  height: 12px;
}
@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* ── PAGINATION ────────────────────────────────────── */
.pagination {
  display: flex;
  gap: 2px;
  align-items: center;
}
.pagination a, .pagination span {
  min-width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--t-sm);
  color: var(--graphite);
  text-decoration: none;
  border: var(--bw-hair) solid transparent;
  border-radius: var(--r-sm);
  padding: 0 var(--s-2);
  transition: border-color var(--d-base) var(--ease-out), color var(--d-base) var(--ease-out);
  font-variant-numeric: tabular-nums;
}
.pagination a:hover { border-color: var(--mist); color: var(--ink); }
.pagination a[aria-current="page"] { border-color: var(--ink); color: var(--ink); font-weight: 500; }

/* ── HERO ──────────────────────────────────────────── */
.hero-eye {
  font-size: var(--t-micro);
  font-weight: 500;
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--slate);
  margin-bottom: var(--s-5);
}
.hero-ttl {
  font-size: var(--t-3xl);
  font-weight: 500;
  letter-spacing: var(--ls-tight);
  line-height: 1.0;
  margin-bottom: var(--s-5);
  text-wrap: balance;
}
.hero-body {
  font-size: var(--t-md);
  line-height: var(--lh-relaxed);
  max-width: 520px;
  margin-bottom: var(--s-6);
  color: var(--graphite);
}

/* ── ICON DEFAULT ──────────────────────────────────── */
.icon { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.25; stroke-linecap: round; stroke-linejoin: round; }
.icon--sm { width: 16px; height: 16px; }
.icon--lg { width: 24px; height: 24px; }
.icon--xl { width: 32px; height: 32px; stroke-width: 1; }
