/* === Components ======================================================
 * Buttons, form fields, cards, badges, KPI tiles, toasts.
 * ===================================================================== */

/* ─── Buttons ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: 10px 16px;
  border-radius: var(--rs);
  font-size: var(--text-base);
  font-weight: var(--w-medium);
  letter-spacing: -0.005em;
  border: 1px solid transparent;
  transition: background var(--t-fast),
              border-color var(--t-fast),
              box-shadow var(--t-fast),
              transform var(--t-fast);
  white-space: nowrap;
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn--primary {
  background: var(--primary);
  color: var(--on-primary);
  border-color: var(--primary);
  font-weight: var(--w-semibold);
  box-shadow: var(--sh-primary);
}
.btn--primary:hover:not(:disabled) {
  background: var(--primary-lo);
  border-color: var(--primary-lo);
  box-shadow: var(--sh-primary-hover);
  transform: translateY(-1px);
}
.btn--primary:active { transform: translateY(0); }

.btn--secondary {
  background: var(--surface);
  color: var(--tx);
  border-color: var(--b1);
  box-shadow: var(--sh-1);
}
.btn--secondary:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--b2);
  box-shadow: var(--sh-2);
}

.btn--ghost {
  background: transparent;
  color: var(--t2);
}
.btn--ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--tx);
}

.btn--danger {
  background: var(--surface);
  color: var(--negative);
  border-color: var(--b1);
}
.btn--danger:hover:not(:disabled) {
  background: var(--negative-tint);
  border-color: var(--negative);
}

.btn--block { width: 100%; }
.btn--sm    { padding: 6px 12px; font-size: var(--text-sm); }
.btn--lg    { padding: 14px 20px; font-size: var(--text-md); }

.btn__label { display: inline-block; }

/* Loading spinner state */
.btn.is-loading { pointer-events: none; position: relative; }
.btn.is-loading .btn__label { opacity: 0; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  animation: spin 700ms linear infinite;
}

/* ─── Icon button ─────────────────────────────────────────────────── */
.iconbtn {
  width: 36px; height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--rs);
  color: var(--t2);
  transition: background var(--t-fast), color var(--t-fast);
}
.iconbtn:hover {
  background: var(--surface-2);
  color: var(--tx);
}
.iconbtn--menu {
  display: none;
}

/* ─── Form field ──────────────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field__label {
  font-size: var(--text-sm);
  font-weight: var(--w-medium);
  color: var(--t2);
  letter-spacing: -0.005em;
}
.field__input {
  width: 100%;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--b1);
  border-radius: var(--rs);
  color: var(--tx);
  font-size: var(--text-md);
  transition: border-color var(--t-fast),
              box-shadow var(--t-fast),
              background var(--t-fast);
}
.field__input::placeholder { color: var(--t4); }
.field__input:hover { border-color: var(--b2); }
.field__input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-tint);
}
.field__hint  { font-size: var(--text-xs); color: var(--t3); }
.field__error { font-size: var(--text-xs); color: var(--negative); }

/* ─── Card ────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--b1);
  border-radius: var(--r);
  padding: var(--s-5);
  box-shadow: var(--sh-1);
}
.card--clickable {
  cursor: pointer;
  transition: border-color var(--t-fast),
              box-shadow var(--t-fast),
              transform var(--t-fast);
}
.card--clickable:hover {
  border-color: var(--b2);
  box-shadow: var(--sh-2);
  transform: translateY(-1px);
}

/* ─── Badge ───────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: var(--r-full);
  font-size: var(--text-2xs);
  font-weight: var(--w-semibold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--surface-2);
  color: var(--t2);
  border: 1px solid var(--b1);
  white-space: nowrap;
}
.badge--positive { color: var(--positive-deep); background: var(--positive-tint); border-color: transparent; }
.badge--negative { color: var(--negative); background: var(--negative-tint); border-color: transparent; }
.badge--warning  { color: var(--amber-lo); background: var(--warning-tint); border-color: transparent; }
.badge--info     { color: var(--indigo); background: var(--info-tint); border-color: transparent; }

/* Status dot */
.dot {
  width: 8px; height: 8px;
  border-radius: var(--r-full);
  display: inline-block;
  background: var(--t4);
}
.dot--positive { background: var(--positive); }
.dot--negative { background: var(--negative); }
.dot--warning  { background: var(--warning); }
.dot--primary  { background: var(--primary); }

/* ─── Empty state ─────────────────────────────────────────────────── */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--s-16) var(--s-6);
  text-align: center;
  color: var(--t2);
}
.empty__icon {
  width: 48px; height: 48px;
  border-radius: var(--rs);
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--b1);
  color: var(--t3);
  font-size: var(--text-xl);
  margin-bottom: var(--s-4);
}
.empty__title {
  font-family: var(--fd);
  font-size: var(--text-lg);
  font-weight: var(--w-semibold);
  color: var(--tx);
  margin-bottom: var(--s-2);
}
.empty__text {
  max-width: 360px;
  font-size: var(--text-sm);
  line-height: 1.55;
  margin-bottom: var(--s-5);
  color: var(--t2);
}

/* ─── Toast ───────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: calc(var(--bottom-h) + 16px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  z-index: var(--z-toast);
  pointer-events: none;
}
@media (min-width: 768px) {
  .toast-container { bottom: 24px; }
}
.toast {
  background: var(--surface);
  border: 1px solid var(--b1);
  border-radius: var(--rs);
  padding: 10px 16px;
  font-size: var(--text-sm);
  color: var(--tx);
  box-shadow: var(--sh-3);
  pointer-events: auto;
  animation: fadeUp 220ms var(--ease-out);
  min-width: 240px;
  max-width: 400px;
}
.toast--positive { border-left: 3px solid var(--positive); }
.toast--negative { border-left: 3px solid var(--negative); }
.toast--warning  { border-left: 3px solid var(--warning); }

/* ─── Undo / Redo pair ────────────────────────────────────────────── */
.undo-pair {
  display: inline-flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--b1);
  border-radius: var(--rs);
  padding: 2px;
  gap: 2px;
  box-shadow: var(--sh-1);
}

.undo-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  color: var(--t2);
  transition: background var(--t-fast), color var(--t-fast);
  position: relative;
}
.undo-btn:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--tx);
}
.undo-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.undo-btn svg {
  width: 16px;
  height: 16px;
}

/* Tooltip on hover */
.undo-btn[data-label]:not(:disabled):hover::after {
  content: attr(data-label);
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  background: var(--tx);
  color: var(--bg-2);
  font-size: var(--text-xs);
  padding: 4px 8px;
  border-radius: 4px;
  pointer-events: none;
  z-index: var(--z-overlay);
  box-shadow: var(--sh-2);
}

@media (max-width: 640px) {
  .undo-pair { box-shadow: none; }
}

/* ─── Userchip ────────────────────────────────────────────────────── */
.userchip {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 4px 12px 4px 4px;
  border-radius: var(--r-full);
  background: var(--surface);
  border: 1px solid var(--b1);
  font-size: var(--text-sm);
  color: var(--tx);
  box-shadow: var(--sh-1);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.userchip:hover { border-color: var(--b2); box-shadow: var(--sh-2); }

.userchip__avatar {
  width: 28px; height: 28px;
  border-radius: var(--r-full);
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--primary-hi), var(--primary-deep));
  color: var(--on-primary);
  font-weight: var(--w-bold);
  font-size: var(--text-sm);
  letter-spacing: -0.02em;
  box-shadow: var(--sh-primary);
}
.userchip__name { font-weight: var(--w-medium); }

@media (max-width: 640px) {
  .userchip__name { display: none; }
  .userchip { padding: 4px; box-shadow: none; }
  .userchip__avatar { box-shadow: none; }
}

/* ─── KPI Tile ────────────────────────────────────────────────────── */
.tile {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--b1);
  border-radius: var(--r);
  padding: var(--s-5);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  box-shadow: var(--sh-1);
  overflow: hidden;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.tile:hover {
  border-color: var(--b2);
  box-shadow: var(--sh-2);
}
/* Accent stripe on top for visual rhythm */
.tile::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--primary), transparent);
  opacity: 0.4;
}

.tile__label {
  font-size: var(--text-2xs);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--t3);
  font-weight: var(--w-semibold);
}
.tile__value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-2xl);
  font-weight: var(--w-medium);
  letter-spacing: -0.02em;
  color: var(--tx);
  line-height: 1.1;
}
.tile__sub {
  font-size: var(--text-xs);
  color: var(--t3);
  display: flex;
  align-items: center;
  gap: 6px;
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--s-4);
}
@media (max-width: 640px) {
  .tile-grid { grid-template-columns: 1fr 1fr; gap: var(--s-3); }
  .tile { padding: var(--s-4); }
  .tile__value { font-size: var(--text-xl); }
}

/* ─── "Coming soon" placeholder ──────────────────────────────────── */
.coming-soon {
  background: var(--surface);
  border: 1px solid var(--b1);
  border-radius: var(--r);
  padding: var(--s-12) var(--s-6);
  text-align: center;
  box-shadow: var(--sh-1);
  position: relative;
  overflow: hidden;
}
.coming-soon::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg,
    var(--primary) 0%,
    var(--indigo) 50%,
    var(--coral) 100%);
  opacity: 0.5;
}

.coming-soon__chip {
  display: inline-block;
  padding: 5px 12px;
  background: var(--primary-tint);
  color: var(--primary-deep);
  border-radius: var(--r-full);
  font-size: var(--text-2xs);
  font-weight: var(--w-bold);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: var(--s-4);
}

.coming-soon__title {
  font-family: var(--fd);
  font-size: var(--text-xl);
  font-weight: var(--w-semibold);
  color: var(--tx);
  margin-bottom: var(--s-2);
  letter-spacing: -0.02em;
}

.coming-soon__text {
  font-size: var(--text-sm);
  color: var(--t2);
  max-width: 480px;
  margin: 0 auto var(--s-5);
  line-height: 1.65;
}

.coming-soon__phase {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--t3);
  letter-spacing: 0.08em;
}
