/* ==========================================================================
   COMPONENTS
   ========================================================================== */

/* ---------------------------- Buttons ----------------------------------- */
.btn{
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: var(--fs-sm); font-weight: 560;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--dur-fast) var(--ease-out);
  user-select: none;
  background: transparent;
}
.btn svg{ width: 15px; height: 15px; }
.btn:active{ transform: translateY(1px); }
.btn:disabled{ opacity: 0.45; cursor: not-allowed; pointer-events: none; }

.btn-primary{
  background: linear-gradient(155deg, var(--accent-400), var(--accent-600));
  color: #fff;
  box-shadow: 0 1px 0 rgba(255,255,255,0.12) inset, 0 4px 14px -4px hsl(var(--hue-violet)/0.6);
}
.btn-primary:hover{ filter: brightness(1.08); box-shadow: 0 1px 0 rgba(255,255,255,0.15) inset, 0 6px 18px -4px hsl(var(--hue-violet)/0.7); }

.btn-ember{
  background: linear-gradient(155deg, var(--ember-400), var(--ember-600));
  color: #170a03;
  box-shadow: 0 1px 0 rgba(255,255,255,0.18) inset, 0 4px 14px -4px hsl(var(--hue-ember)/0.6);
}
.btn-ember:hover{ filter: brightness(1.06); }

.btn-secondary{
  background: var(--bg-surface-2);
  border-color: var(--border-default);
  color: var(--text-primary);
}
.btn-secondary:hover{ background: var(--bg-hover); border-color: var(--border-strong); }

.btn-ghost{ color: var(--text-secondary); }
.btn-ghost:hover{ background: var(--bg-hover); color: var(--text-primary); }

.btn-danger{ color: var(--danger-500); }
.btn-danger:hover{ background: rgba(248,113,113,0.12); }

.btn-sm{ height: 30px; padding: 0 11px; font-size: var(--fs-xs); border-radius: var(--radius-sm); }
.btn-lg{ height: 44px; padding: 0 20px; font-size: var(--fs-base); border-radius: var(--radius-lg); }
.btn-icon{ width: 36px; padding: 0; }
.btn-icon.btn-sm{ width: 30px; }
.btn-block{ width: 100%; }

.btn-round{
  width: 32px; height: 32px; border-radius: var(--radius-full);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-tertiary); cursor: pointer; background: transparent; border: 1px solid transparent;
  transition: all var(--dur-fast) var(--ease-out);
}
.btn-round svg{ width: 16px; height: 16px; }
.btn-round:hover{ background: var(--bg-hover); color: var(--text-primary); }
.btn-round.active{ background: var(--accent-soft); color: var(--accent-strong); }

/* ---------------------------- Cards ------------------------------------- */
.card{
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  transition: border-color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.card-pad{ padding: var(--space-5); }
.card-hover:hover{ border-color: var(--border-strong); box-shadow: var(--shadow-sm); }

.stat-card{
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  position: relative;
  overflow: hidden;
}
.stat-card::after{
  content: "";
  position: absolute; top: -40%; right: -20%;
  width: 140px; height: 140px; border-radius: 50%;
  background: radial-gradient(circle, hsl(var(--hue-violet) / 0.16), transparent 70%);
  pointer-events: none;
}
.stat-card[data-tone="ember"]::after{ background: radial-gradient(circle, hsl(var(--hue-ember)/0.18), transparent 70%); }
.stat-card-icon{
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent-strong);
  margin-bottom: var(--space-4);
}
.stat-card[data-tone="ember"] .stat-card-icon{ background: var(--ember-soft); color: var(--ember); }
.stat-card-icon svg{ width: 17px; height: 17px; }
.stat-card-value{ font-family: var(--font-display); font-size: var(--fs-2xl); font-weight: 700; letter-spacing: var(--tracking-tight); line-height: 1; }
.stat-card-label{ font-size: var(--fs-xs); color: var(--text-tertiary); margin-top: 6px; }
.stat-card-delta{ display: inline-flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; margin-top: 10px; }
.stat-card-delta.up{ color: var(--success-500); }
.stat-card-delta.down{ color: var(--danger-500); }
.stat-card-delta svg{ width: 11px; height: 11px; }

/* ---------------------------- Inputs ------------------------------------ */
.field{ display: flex; flex-direction: column; gap: 6px; }
.field-label{ font-size: var(--fs-xs); font-weight: 600; color: var(--text-secondary); display: flex; align-items: center; justify-content: space-between; }
.field-hint{ font-size: 11px; color: var(--text-tertiary); }
.input, .textarea, .select{
  width: 100%;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  color: var(--text-primary);
  font-size: var(--fs-sm);
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.input::placeholder, .textarea::placeholder{ color: var(--text-tertiary); }
.input:focus, .textarea:focus, .select:focus{ border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.textarea{ resize: vertical; min-height: 90px; line-height: var(--lh-normal); font-family: var(--font-mono); font-size: var(--fs-sm); }
.select{ cursor: pointer; appearance: none; -webkit-appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238A8DA0' stroke-width='1.4' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 30px; }

.input-icon-wrap{ position: relative; }
.input-icon-wrap .input{ padding-left: 34px; }
.input-icon-wrap svg{ position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--text-tertiary); }

.checkbox-row{ display: flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.checkbox{
  width: 17px; height: 17px; border-radius: 5px; border: 1.5px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: all var(--dur-fast) var(--ease-out); background: var(--bg-surface-2);
}
.checkbox.checked{ background: var(--accent); border-color: var(--accent); }
.checkbox svg{ width: 11px; height: 11px; color: #fff; opacity: 0; transform: scale(0.6); transition: all var(--dur-fast) var(--ease-spring); }
.checkbox.checked svg{ opacity: 1; transform: scale(1); }

.switch{ width: 38px; height: 22px; border-radius: var(--radius-full); background: var(--bg-surface-3); border: 1px solid var(--border-default); position: relative; cursor: pointer; flex-shrink: 0; transition: background var(--dur-base) var(--ease-out); }
.switch::after{ content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-xs); transition: transform var(--dur-base) var(--ease-spring); }
.switch.on{ background: linear-gradient(120deg, var(--accent-400), var(--accent-600)); border-color: transparent; }
.switch.on::after{ transform: translateX(16px); }

/* ---------------------------- Badges / chips ----------------------------- */
.badge{ display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--radius-full); font-size: 11px; font-weight: 600; background: var(--bg-surface-3); color: var(--text-secondary); }
.badge-dot{ width: 6px; height: 6px; border-radius: 50%; }
.badge-accent{ background: var(--accent-soft); color: var(--accent-strong); }
.badge-ember{ background: var(--ember-soft); color: var(--ember); }
.badge-success{ background: rgba(52,211,153,0.14); color: var(--success-500); }
.badge-warning{ background: rgba(245,165,36,0.14); color: var(--warning-500); }
.badge-danger{ background: rgba(248,113,113,0.14); color: var(--danger-500); }

.tag-chip{ display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px 3px 8px; border-radius: var(--radius-full); background: var(--bg-surface-3); border: 1px solid var(--border-subtle); font-size: 11.5px; color: var(--text-secondary); font-weight: 500; }
.tag-chip button{ background: none; border: none; cursor: pointer; color: var(--text-tertiary); display: flex; padding: 0; }
.tag-chip button svg{ width: 10px; height: 10px; }
.tag-chip button:hover{ color: var(--danger-500); }

.chip-btn{ display: inline-flex; align-items: center; gap: 5px; padding: 5px 11px; border-radius: var(--radius-full); background: var(--bg-surface-2); border: 1px solid var(--border-default); font-size: var(--fs-xs); font-weight: 560; color: var(--text-secondary); cursor: pointer; transition: all var(--dur-fast) var(--ease-out); }
.chip-btn:hover{ border-color: var(--border-strong); color: var(--text-primary); }
.chip-btn.active{ background: var(--accent-soft); border-color: transparent; color: var(--accent-strong); }
.chip-btn svg{ width: 12px; height: 12px; }

/* ---------------------------- Avatars / icon tiles ----------------------- */
.icon-tile{ width: 38px; height: 38px; border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.icon-tile svg{ width: 18px; height: 18px; }

/* ---------------------------- Empty states ------------------------------- */
.empty-state{ display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: var(--space-10) var(--space-6); color: var(--text-tertiary); }
.empty-state-icon{ width: 56px; height: 56px; border-radius: var(--radius-xl); background: var(--bg-surface-2); border: 1px solid var(--border-subtle); display: flex; align-items: center; justify-content: center; margin-bottom: var(--space-4); color: var(--text-tertiary); }
.empty-state-icon svg{ width: 24px; height: 24px; }
.empty-state h3{ font-size: var(--fs-base); color: var(--text-primary); margin-bottom: 4px; }
.empty-state p{ font-size: var(--fs-sm); max-width: 340px; margin-bottom: var(--space-4); }

/* ---------------------------- Divider ------------------------------------ */
.divider{ height: 1px; background: var(--border-subtle); border: none; margin: var(--space-4) 0; }
.divider-v{ width: 1px; background: var(--border-subtle); align-self: stretch; }

/* ---------------------------- Tooltip ------------------------------------ */
[data-tooltip]{ position: relative; }
[data-tooltip]:hover::after{
  content: attr(data-tooltip);
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  background: var(--bg-surface-3); color: var(--text-primary); border: 1px solid var(--border-default);
  padding: 5px 9px; border-radius: var(--radius-sm); font-size: 11px; white-space: nowrap; z-index: 80;
  box-shadow: var(--shadow-sm); pointer-events: none; animation: tipIn var(--dur-fast) var(--ease-out);
}
@keyframes tipIn{ from{ opacity: 0; transform: translate(-50%, 3px);} to{ opacity: 1; transform: translate(-50%, 0);} }

/* ---------------------------- Segmented control --------------------------- */
.segmented{ display: inline-flex; padding: 3px; background: var(--bg-surface-2); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); gap: 2px; }
.segmented button{ border: none; background: transparent; color: var(--text-tertiary); padding: 6px 10px; border-radius: var(--radius-sm); cursor: pointer; display: flex; align-items: center; gap: 6px; font-size: var(--fs-xs); font-weight: 600; transition: all var(--dur-fast) var(--ease-out); }
.segmented button svg{ width: 14px; height: 14px; }
.segmented button.active{ background: var(--bg-surface); color: var(--text-primary); box-shadow: var(--shadow-xs); }

/* ---------------------------- Progress bar -------------------------------- */
.progress{ height: 6px; border-radius: var(--radius-full); background: var(--bg-surface-3); overflow: hidden; }
.progress-fill{ height: 100%; border-radius: var(--radius-full); background: linear-gradient(90deg, var(--accent), var(--ember)); transition: width var(--dur-slow) var(--ease-out); }

/* ---------------------------- Skeleton ------------------------------------ */
.skel{ background: linear-gradient(100deg, var(--bg-surface-2) 30%, var(--bg-surface-3) 50%, var(--bg-surface-2) 70%); background-size: 200% 100%; animation: shimmer 1.4s ease-in-out infinite; border-radius: var(--radius-sm); }
@keyframes shimmer{ from{ background-position: 200% 0;} to{ background-position: -200% 0;} }

/* ---------------------------- Color swatch -------------------------------- */
.swatch{ width: 22px; height: 22px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; position: relative; transition: transform var(--dur-fast) var(--ease-spring); }
.swatch:hover{ transform: scale(1.1); }
.swatch.selected{ border-color: var(--bg-surface); box-shadow: 0 0 0 2px currentColor; }
