/* ========================================================================
   Components: buttons, inputs, badges, cards, tables, etc.
   ======================================================================== */

/* ── Button ──────────────────────────────────────────────── */
.btn {
  --btn-bg: transparent;
  --btn-fg: var(--text);
  --btn-border: transparent;
  --btn-hover-bg: var(--surface-hover);
  --btn-h: 32px;

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--btn-h);
  padding: 0 12px;
  border-radius: var(--r-6);
  font-size: var(--t-13);
  font-weight: 500;
  letter-spacing: -0.005em;
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: 1px solid var(--btn-border);
  white-space: nowrap;
  line-height: 1;
  box-shadow: var(--shadow-xs);
  position: relative;
}
.btn:hover { background: var(--btn-hover-bg); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 14px; height: 14px; }

.btn-primary {
  --btn-bg: var(--text);
  --btn-fg: var(--bg);
  --btn-hover-bg: color-mix(in oklab, var(--text) 85%, transparent);
  box-shadow: var(--shadow-sm), inset 0 1px 0 oklch(1 0 0 / 0.08);
}
[data-theme="dark"] .btn-primary {
  --btn-bg: #fff;
  --btn-fg: var(--n-950);
  --btn-hover-bg: var(--n-150);
}

.btn-brand {
  --btn-bg: var(--primary);
  --btn-fg: white;
  --btn-hover-bg: var(--primary-hover);
  box-shadow: 0 1px 2px oklch(0.5 0.2 275 / 0.2), inset 0 1px 0 oklch(1 0 0 / 0.15), 0 0 0 1px oklch(0.5 0.2 275 / 0.5);
}

.btn-secondary {
  --btn-bg: var(--surface);
  --btn-border: var(--border);
  --btn-hover-bg: var(--surface-2);
}
.btn-ghost {
  --btn-fg: var(--text-muted);
  box-shadow: none;
}
.btn-ghost:hover { color: var(--text); }
.btn-danger {
  --btn-bg: var(--danger-500);
  --btn-fg: white;
  --btn-hover-bg: var(--danger-600);
}
.btn-danger-ghost {
  --btn-fg: var(--danger-500);
  --btn-hover-bg: var(--danger-50);
  box-shadow: none;
}

.btn-sm { --btn-h: 26px; padding: 0 9px; font-size: 12px; }
.btn-xs { --btn-h: 22px; padding: 0 7px; font-size: 11.5px; border-radius: var(--r-4); }
.btn-lg { --btn-h: 38px; padding: 0 16px; font-size: var(--t-14); }

.btn-icon { width: var(--btn-h); padding: 0; }

/* Split button */
.btn-group {
  display: inline-flex;
  box-shadow: var(--shadow-xs);
  border-radius: var(--r-6);
}
.btn-group > .btn { box-shadow: none; border-radius: 0; }
.btn-group > .btn:first-child { border-radius: var(--r-6) 0 0 var(--r-6); }
.btn-group > .btn:last-child { border-radius: 0 var(--r-6) var(--r-6) 0; }
.btn-group > .btn + .btn { border-left-width: 0; }
.btn-group > .btn + .btn.btn-secondary { border-left: 1px solid var(--border); }

/* ── Input / select ─────────────────────────────────────── */
.input {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-6);
  font-size: var(--t-13);
  outline: none;
  color: var(--text);
  box-shadow: var(--shadow-xs);
}
.input::placeholder { color: var(--text-faint); }
.input:hover { border-color: var(--border-strong); }
.input:focus { border-color: var(--primary); box-shadow: var(--ring); }

.input-group {
  display: flex;
  align-items: stretch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-6);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.input-group:focus-within { border-color: var(--primary); box-shadow: var(--ring); }
.input-group .input { border: 0; box-shadow: none; background: transparent; }
.input-group .input:focus { box-shadow: none; }
.input-addon {
  display: flex;
  align-items: center;
  padding: 0 10px;
  background: var(--surface-2);
  color: var(--text-subtle);
  font-size: var(--t-12);
  font-family: var(--font-mono);
  border-right: 1px solid var(--border);
}
.input-addon.suffix { border-right: 0; border-left: 1px solid var(--border); }

.label {
  display: block;
  font-size: var(--t-12);
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-2);
}
.hint {
  font-size: 11.5px;
  color: var(--text-subtle);
  margin-top: 5px;
}

/* ── Checkbox / switch ──────────────────────────────────── */
.check {
  appearance: none;
  width: 15px; height: 15px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-4);
  background: var(--surface);
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  position: relative;
}
.check:hover { border-color: var(--primary); }
.check:checked {
  background: var(--primary);
  border-color: var(--primary);
}
.check:checked::after {
  content: "";
  width: 9px; height: 9px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='white'%3E%3Cpath d='M13.3 3.6L5.7 11.2 2.7 8.1l1.4-1.4 1.6 1.6 6.2-6.1 1.4 1.4z'/%3E%3C/svg%3E") center/contain no-repeat;
}

.switch {
  appearance: none;
  width: 28px; height: 16px;
  background: var(--border-strong);
  border-radius: var(--r-full);
  position: relative;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out);
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 12px; height: 12px;
  border-radius: var(--r-full);
  background: white;
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-fast) var(--ease-spring);
}
.switch:checked { background: var(--primary); }
.switch:checked::after { transform: translateX(12px); }

/* ── Badge / pill ───────────────────────────────────────── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 8px;
  height: 20px;
  border-radius: var(--r-full);
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: -0.005em;
  line-height: 1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}
.pill-dot::before {
  content: "";
  width: 5px; height: 5px;
  border-radius: var(--r-full);
  background: currentColor;
  flex-shrink: 0;
}
.pill-success { background: var(--success-50); color: var(--success-600); border-color: color-mix(in oklab, var(--success-500) 20%, transparent); }
.pill-warning { background: var(--warning-50); color: var(--warning-600); border-color: color-mix(in oklab, var(--warning-500) 20%, transparent); }
.pill-danger  { background: var(--danger-50);  color: var(--danger-600);  border-color: color-mix(in oklab, var(--danger-500) 20%, transparent); }
.pill-info    { background: var(--info-50);    color: var(--info-600);    border-color: color-mix(in oklab, var(--info-500) 20%, transparent); }
.pill-brand   { background: var(--primary-soft); color: var(--primary-text); border-color: var(--primary-border); }
.pill-solid-success { background: var(--success-500); color: white; border: 0; }
.pill-solid-brand   { background: var(--primary);      color: white; border: 0; }

[data-theme="dark"] .pill-success { color: var(--success-400); }
[data-theme="dark"] .pill-warning { color: var(--warning-400); }
[data-theme="dark"] .pill-danger { color: var(--danger-400); }
[data-theme="dark"] .pill-info { color: var(--info-400); }

/* Chip for filters */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: var(--r-full);
  font-size: var(--t-12);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  box-shadow: var(--shadow-xs);
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip.on {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.chip svg { width: 12px; height: 12px; }

/* ── Card / panel ───────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-12);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.card-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-body { padding: 18px; }
.card-body.pad-0 { padding: 0; }
.card-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: var(--t-12);
  color: var(--text-muted);
}

/* ── Metric tiles (role-aware) ──────────────────────────── */
.metric-grid {
  display: grid;
  gap: 0;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-12);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.metric {
  padding: 16px 20px 44px;
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  min-width: 0;
}
.metric:last-child { border-right: 0; }
.metric-label {
  font-size: var(--t-12);
  color: var(--text-subtle);
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}
.metric-label svg { width: 12px; height: 12px; }
.metric-value {
  font-family: var(--font-display);
  font-size: var(--t-28);
  font-weight: 600;
  letter-spacing: -0.028em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: baseline;
  gap: 4px;
  color: var(--text);
}
.metric-value .unit {
  font-size: var(--t-14);
  color: var(--text-subtle);
  font-weight: 500;
  letter-spacing: -0.005em;
}
.metric-trend {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-family: var(--font-mono);
  font-size: var(--t-12);
  font-weight: 500;
}
.metric-trend.up { color: var(--success-600); }
.metric-trend.down { color: var(--danger-600); }
[data-theme="dark"] .metric-trend.up { color: var(--success-400); }
[data-theme="dark"] .metric-trend.down { color: var(--danger-400); }
.metric-trend svg { width: 11px; height: 11px; }
.metric-sub {
  font-size: var(--t-12);
  color: var(--text-subtle);
}
.metric-spark {
  position: absolute;
  left: 20px;
  right: 20px;
  bottom: 12px;
  width: auto;
  height: 24px;
  opacity: 0.85;
}
@media (max-width: 900px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .metric:nth-child(2n) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--border-subtle); }
}

/* ── Data table (Stripe-vari, dense) ────────────────────── */
.tbl-wrap {
  width: 100%;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-12);
  box-shadow: var(--shadow-sm);
  position: relative;
}
.tbl-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--surface);
  flex-wrap: wrap;
  position: sticky; top: 0; z-index: 2;
}
.tbl {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--t-13);
}
.tbl th {
  text-align: left;
  font-weight: 500;
  color: var(--text-subtle);
  font-size: var(--t-11);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 8px var(--d-cell-x);
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
  white-space: nowrap;
  position: sticky; top: 0; z-index: 1;
}
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--text); }
.tbl th.sortable::after {
  content: "↕";
  margin-left: 4px;
  opacity: 0.3;
  font-size: 10px;
}
.tbl th.sorted-asc::after { content: "↑"; opacity: 1; color: var(--primary); }
.tbl th.sorted-desc::after { content: "↓"; opacity: 1; color: var(--primary); }
.tbl td {
  padding: var(--d-cell-y) var(--d-cell-x);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
  color: var(--text);
  height: var(--d-row-h);
}
.tbl tbody tr {
  transition: background var(--dur-fast) var(--ease-out);
}
.tbl tbody tr:hover {
  background: var(--surface-2);
  cursor: pointer;
}
.tbl tbody tr.selected { background: var(--primary-soft); }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl .col-n { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--font-mono); letter-spacing: -0.01em; }
.tbl .col-id { font-family: var(--font-mono); color: var(--text-muted); font-size: var(--t-12); letter-spacing: -0.01em; }
.tbl .col-check { width: 32px; padding-right: 0; }
.tbl .col-more { width: 40px; text-align: right; }

.cell-strong { font-weight: 500; color: var(--text); }
.cell-muted { color: var(--text-muted); font-size: var(--t-12); }
.cell-primary { color: var(--primary-text); font-weight: 500; }
.cell-amount { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 500; letter-spacing: -0.01em; }

/* Product/user cell */
.ent-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ent-thumb {
  width: 32px; height: 32px;
  border-radius: var(--r-6);
  background: var(--bg-sunken);
  display: grid; place-items: center;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 10.5px;
  border: 1px solid var(--border-subtle);
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
}
.ent-thumb.stripe-a { background: repeating-linear-gradient(45deg, var(--n-150), var(--n-150) 4px, var(--n-100) 4px, var(--n-100) 8px); }
.ent-thumb.stripe-b { background: repeating-linear-gradient(135deg, var(--n-150), var(--n-150) 4px, var(--n-200) 4px, var(--n-200) 8px); }
.ent-name { font-weight: 500; color: var(--text); }
.ent-meta { font-size: 11.5px; color: var(--text-subtle); font-family: var(--font-mono); }
.avatar-init {
  width: 28px; height: 28px;
  border-radius: var(--r-full);
  background: linear-gradient(135deg, var(--p-400), var(--p-700));
  color: white;
  font-size: 10.5px;
  font-weight: 600;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.avatar-init.av-g { background: linear-gradient(135deg, oklch(0.65 0.13 145), oklch(0.45 0.14 165)); }
.avatar-init.av-o { background: linear-gradient(135deg, oklch(0.7 0.14 60), oklch(0.55 0.16 35)); }
.avatar-init.av-r { background: linear-gradient(135deg, oklch(0.68 0.19 22), oklch(0.5 0.18 10)); }

/* ── Filter toolbar ─────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  height: 26px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-full);
  font-size: var(--t-12);
  color: var(--text-muted);
  background: transparent;
}
.filter-btn:hover { border-color: var(--text-muted); color: var(--text); }
.filter-btn.has-value {
  border-style: solid;
  border-color: transparent;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs), inset 0 0 0 1px var(--border);
}
.filter-btn svg { width: 12px; height: 12px; }
.filter-btn .val-count {
  background: var(--primary-soft);
  color: var(--primary-text);
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 0 5px;
  border-radius: var(--r-full);
  font-weight: 600;
}

/* ── Tabs ───────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  position: relative;
}
.tab {
  padding: 8px 12px;
  font-size: var(--t-13);
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-weight: 450;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--text);
  border-bottom-color: var(--text);
  font-weight: 500;
}
.tab .tab-count {
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 1px 5px;
  border-radius: var(--r-4);
  background: var(--bg-sunken);
  color: var(--text-muted);
}
.tab.active .tab-count { background: var(--primary-soft); color: var(--primary-text); }

/* ── Pagination ─────────────────────────────────────────── */
.pager {
  display: flex;
  align-items: center;
  gap: 2px;
  font-family: var(--font-mono);
  font-size: var(--t-12);
}
.pager-btn {
  min-width: 26px;
  height: 26px;
  padding: 0 8px;
  border-radius: var(--r-4);
  color: var(--text-muted);
  display: inline-grid;
  place-items: center;
}
.pager-btn:hover { background: var(--surface-hover); color: var(--text); }
.pager-btn.on {
  background: var(--primary-soft);
  color: var(--primary-text);
  font-weight: 600;
}
.pager-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Empty state ────────────────────────────────────────── */
.empty {
  padding: 56px 24px;
  text-align: center;
  color: var(--text-subtle);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.empty-icon {
  width: 56px; height: 56px;
  border-radius: var(--r-12);
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  display: grid; place-items: center;
  color: var(--text-faint);
  margin-bottom: 10px;
}
.empty-icon svg { width: 22px; height: 22px; }
.empty-title {
  color: var(--text);
  font-weight: 500;
  font-size: var(--t-14);
  margin-bottom: 4px;
}
.empty-desc {
  font-size: var(--t-13);
  max-width: 380px;
}
.empty-actions {
  margin-top: 14px;
  display: flex;
  gap: 8px;
}

/* ── Skeleton ───────────────────────────────────────────── */
.skel {
  background: linear-gradient(90deg,
    var(--bg-sunken) 0%,
    var(--surface-2) 50%,
    var(--bg-sunken) 100%);
  background-size: 200% 100%;
  animation: skel 1.4s linear infinite;
  border-radius: var(--r-4);
  display: inline-block;
}
@keyframes skel {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Misc helpers ───────────────────────────────────────── */
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; gap: 4px; }
.stack-2 > * + * { margin-top: 8px; }
.stack-3 > * + * { margin-top: 12px; }
.stack-4 > * + * { margin-top: 16px; }
.stack-6 > * + * { margin-top: 24px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.spacer { flex: 1; }
.divider { height: 1px; background: var(--divider); margin: 16px 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--d-gap); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--d-gap); }
.grid-12 { display: grid; grid-template-columns: repeat(12, 1fr); gap: var(--d-gap); }
.col-span-4 { grid-column: span 4; }
.col-span-5 { grid-column: span 5; }
.col-span-6 { grid-column: span 6; }
.col-span-7 { grid-column: span 7; }
.col-span-8 { grid-column: span 8; }
.col-span-12 { grid-column: span 12; }
@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-12 { grid-template-columns: 1fr; }
  [class*="col-span-"] { grid-column: 1 / -1; }
}

.mono-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-subtle);
  letter-spacing: -0.01em;
}

.bar {
  height: 6px;
  background: var(--bg-sunken);
  border-radius: var(--r-full);
  overflow: hidden;
  position: relative;
}
.bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: var(--r-full);
  transition: width var(--dur-slow) var(--ease-out);
}
.bar-fill.success { background: var(--success-500); }
.bar-fill.warning { background: var(--warning-500); }
.bar-fill.danger  { background: var(--danger-500);  }
