/* ---------- Buttons ---------- */

.btn {
  --btn-bg: var(--bg-3);
  --btn-bg-hover: var(--bg-4);
  --btn-fg: var(--text);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius-m);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-weight: 600;
  white-space: nowrap;
  user-select: none;
  transition: background-color 140ms var(--ease-out), transform 120ms var(--ease-out),
    box-shadow 140ms var(--ease-out), opacity 140ms;
  box-shadow: var(--shadow-1);
}
.btn:hover:not(:disabled) { background: var(--btn-bg-hover); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.985); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn--primary {
  --btn-bg: var(--accent);
  --btn-bg-hover: color-mix(in srgb, var(--accent) 88%, white);
  --btn-fg: var(--accent-ink);
  font-weight: 700;
  box-shadow: 0 1px 0 rgb(255 255 255 / 0.35) inset, 0 -2px 0 rgb(0 0 0 / 0.18) inset,
    0 6px 20px color-mix(in srgb, var(--accent) 28%, transparent);
}
.btn--primary:hover:not(:disabled) {
  box-shadow: 0 1px 0 rgb(255 255 255 / 0.4) inset, 0 -2px 0 rgb(0 0 0 / 0.18) inset,
    0 8px 28px color-mix(in srgb, var(--accent) 40%, transparent);
}
.btn--primary.is-stop {
  --btn-bg: var(--loss);
  --btn-bg-hover: color-mix(in srgb, var(--loss) 88%, white);
  --btn-fg: #fff;
  box-shadow: 0 1px 0 rgb(255 255 255 / 0.25) inset, 0 6px 20px color-mix(in srgb, var(--loss) 30%, transparent);
}
.btn--ghost {
  --btn-bg: transparent;
  --btn-bg-hover: var(--bg-3);
  --btn-fg: var(--text-2);
  box-shadow: none;
}
.btn--ghost:hover:not(:disabled) { color: var(--text); }
.btn--block { width: 100%; }
.btn--xl { height: 52px; font-size: 16px; border-radius: var(--radius-m); }
.btn--s { height: 32px; padding: 0 10px; font-size: 13px; border-radius: var(--radius-s); }
.btn--icon { width: 40px; padding: 0; }
.btn--icon.btn--s { width: 32px; }

.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2.5px solid color-mix(in srgb, var(--btn-fg) 30%, transparent);
  border-top-color: var(--btn-fg);
  animation: spin 600ms linear infinite;
}

/* ---------- Form fields ---------- */

.field { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; min-width: 0; }
.field__label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 600;
}
.field__label .num { color: var(--text-3); font-weight: 500; }
.field__hint { color: var(--text-3); font-size: 12px; }
.field__error {
  color: var(--loss);
  font-size: 12.5px;
  font-weight: 600;
  animation: rise-in 180ms var(--ease-out);
}

.input {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 44px;
  padding: 0 4px 0 12px;
  border-radius: var(--radius-m);
  background: var(--bg-0);
  border: 2px solid var(--line);
  transition: border-color 140ms, background-color 140ms;
}
.input:hover { border-color: var(--line-strong); }
.input:focus-within { border-color: var(--info); }
.input.is-invalid { border-color: var(--loss); }
.input.is-readonly { background: color-mix(in srgb, var(--bg-0) 60%, var(--bg-2)); }
.input > .icon { color: var(--text-3); margin-right: 6px; }
.input input {
  flex: 1 1 0;
  width: 100%;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.input input::placeholder { color: var(--text-3); font-weight: 500; }
.input input:read-only { cursor: default; }
.input__suffix { color: var(--text-3); font-weight: 600; padding-right: 8px; }
.input .btn--s { background: var(--bg-3); box-shadow: none; }
.input .btn--s:hover { background: var(--bg-4); }
.input__divider { width: 1px; height: 20px; background: var(--line); margin: 0 2px; }

/* ---------- Segmented control with a sliding thumb ---------- */

.seg {
  position: relative;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 4px;
  border-radius: 999px;
  background: var(--bg-0);
}
.seg__thumb {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 0;
  border-radius: 999px;
  background: var(--bg-3);
  box-shadow: var(--shadow-1);
  transition: transform 260ms var(--ease-out), width 260ms var(--ease-out);
}
.seg button {
  position: relative;
  z-index: 1;
  height: 36px;
  padding: 0 14px;
  border: 0;
  background: none;
  border-radius: 999px;
  color: var(--text-3);
  font-weight: 650;
  transition: color 160ms;
}
.seg button:hover { color: var(--text-2); }
.seg button[aria-selected="true"] { color: var(--text); }

/* ---------- Switch ---------- */

.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  color: var(--text-2);
  font-weight: 600;
  font-size: 13px;
}
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch__track {
  position: relative;
  width: 36px;
  height: 20px;
  border-radius: 20px;
  background: var(--bg-4);
  transition: background-color 180ms;
}
.switch__track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 220ms var(--ease-spring);
}
.switch input:checked + .switch__track { background: var(--win); }
.switch input:checked + .switch__track::after { transform: translateX(16px); background: var(--win-ink); }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--info); outline-offset: 2px; }

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
}
.check input {
  appearance: none;
  flex: none;
  width: 18px;
  height: 18px;
  margin: 1px 0 0;
  border-radius: 5px;
  border: 2px solid var(--line-strong);
  background: var(--bg-0);
  display: grid;
  place-items: center;
  transition: background-color 140ms, border-color 140ms;
  cursor: pointer;
}
.check input::after {
  content: "";
  width: 8px;
  height: 4px;
  border: solid var(--accent-ink);
  border-width: 0 0 2px 2px;
  transform: translateY(-1px) rotate(-45deg) scale(0);
  transition: transform 180ms var(--ease-spring);
}
.check input:checked { background: var(--accent); border-color: var(--accent); }
.check input:checked::after { transform: translateY(-1px) rotate(-45deg) scale(1); }

/* ---------- Surfaces ---------- */

.panel {
  background: var(--bg-1);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-1);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: 6px;
  background: var(--bg-3);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.badge--live { background: color-mix(in srgb, var(--win) 16%, transparent); color: var(--win); }
.badge--live::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.35; } }

.pill-mult {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  height: 30px;
  padding: 0 10px;
  border-radius: 8px;
  background: var(--bg-3);
  color: var(--text-2);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.pill-mult.is-win { background: var(--win); color: var(--win-ink); }

/* ---------- Tables ---------- */

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 4px;
  font-variant-numeric: tabular-nums;
}
.table th {
  padding: 4px 14px;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 600;
  text-align: left;
}
.table td {
  padding: 11px 14px;
  background: var(--bg-2);
  font-weight: 600;
}
.table td:first-child { border-radius: var(--radius-s) 0 0 var(--radius-s); }
.table td:last-child { border-radius: 0 var(--radius-s) var(--radius-s) 0; }
.table .is-right { text-align: right; }
.table tbody tr { cursor: pointer; transition: transform 140ms var(--ease-out); }
.table tbody tr:hover td { background: var(--bg-3); }
.table .is-win { color: var(--win); }
.table .is-muted { color: var(--text-3); }
.table tr.is-new td { animation: row-in 420ms var(--ease-out); }
@keyframes row-in { from { opacity: 0; transform: translateY(-8px); background: var(--bg-4); } }

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgb(4 8 16 / 0.72);
  backdrop-filter: blur(3px);
  animation: fade-in 180ms var(--ease-out);
}
.modal-backdrop.is-closing { pointer-events: none; animation: fade-out 160ms var(--ease-in-out) forwards; }
.modal {
  width: min(520px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  border-radius: var(--radius-l);
  background: var(--bg-1);
  box-shadow: var(--shadow-3), 0 0 0 1px var(--line);
  animation: modal-in 260ms var(--ease-out);
}
.modal:focus { outline: none; }
.modal-backdrop.is-closing .modal { animation: modal-out 160ms var(--ease-in-out) forwards; }
@keyframes modal-in { from { opacity: 0; transform: translateY(16px) scale(0.97); } }
@keyframes modal-out { to { opacity: 0; transform: translateY(10px) scale(0.98); } }
.modal__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 0 22px;
}
.modal__head h2 { flex: 1; font-size: 17px; }
.modal__head .icon { color: var(--text-2); }
.modal__body { padding: 18px 22px 22px; display: grid; gap: 16px; }

/* ---------- Toasts ---------- */

#toasts {
  position: fixed;
  z-index: 90;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 8px;
  justify-items: end;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(380px, calc(100vw - 32px));
  padding: 12px 14px 12px 12px;
  border-radius: var(--radius-m);
  background: var(--bg-3);
  box-shadow: var(--shadow-3), 0 0 0 1px var(--line-strong);
  font-weight: 600;
  pointer-events: auto;
  animation: toast-in 320ms var(--ease-spring);
}
.toast.is-leaving { animation: toast-out 220ms var(--ease-in-out) forwards; }
.toast__icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--bg-4);
}
.toast--error .toast__icon { background: color-mix(in srgb, var(--loss) 20%, transparent); color: var(--loss); }
.toast--success .toast__icon { background: color-mix(in srgb, var(--win) 18%, transparent); color: var(--win); }
@keyframes toast-in { from { opacity: 0; transform: translateX(24px) scale(0.96); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(24px); } }

/* ---------- Tooltip ---------- */

[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  translate: -50% 4px;
  padding: 6px 9px;
  border-radius: 6px;
  background: var(--text);
  color: var(--bg-0);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms, translate 160ms var(--ease-out);
  z-index: 20;
}
[data-tip]:hover::after { opacity: 1; translate: -50% 0; transition-delay: 350ms; }

/* ---------- Skeleton ---------- */

.skeleton {
  border-radius: var(--radius-s);
  background: linear-gradient(90deg, var(--bg-2) 0 40%, var(--bg-3) 50%, var(--bg-2) 60% 100%) 0 0 / 300% 100%;
  animation: shimmer 1.3s linear infinite;
}
@keyframes shimmer { to { background-position: -150% 0; } }
