:root {
  --bg: #0c0f12;
  --bg-2: #141a1f;
  --ink: #e8eef2;
  --muted: #8b9aa6;
  --line: #24303a;
  --accent: #2dd4bf;
  --accent-2: #f0b429;
  --card: #12181e;
  --danger: #f87171;
  --ok: #34d399;
  --warn: #fbbf24;
  --font-display: "Outfit", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --radius: 10px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  --fast: 140ms;
  --med: 220ms;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.bg-grid {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(45, 212, 191, 0.12), transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 20%, rgba(240, 180, 41, 0.07), transparent 50%),
    linear-gradient(rgba(36, 48, 58, 0.28) 1px, transparent 1px),
    linear-gradient(90deg, rgba(36, 48, 58, 0.28) 1px, transparent 1px),
    linear-gradient(180deg, #0c0f12 0%, #0a1014 100%);
  background-size: auto, auto, 48px 48px, 48px 48px, auto;
}

/* —— header —— */
.top {
  display: flex;
  align-items: center;
  gap: 1rem;
  justify-content: space-between;
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
  padding: 0.9rem 1.25rem;
  flex-wrap: wrap;
}

.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: 0.05em;
  color: var(--ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  object-fit: cover;
}
.brand-badge {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid rgba(45, 212, 191, 0.35);
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  background: rgba(45, 212, 191, 0.08);
}

.app-nav {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.app-nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.4rem 0.7rem;
  border-radius: 7px;
  transition: color var(--fast), background var(--fast);
}
.app-nav a:hover { color: var(--ink); background: rgba(255,255,255,0.04); }
.app-nav a.is-active {
  color: var(--ink);
  background: rgba(45, 212, 191, 0.12);
}

.top-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-left: auto;
}
.user-chip {
  font-size: 0.8rem;
  color: var(--muted);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* —— IP banner —— */
.ip-banner {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  max-width: 1120px;
  width: calc(100% - 2.5rem);
  margin: 0 auto 0.5rem;
  padding: 0.75rem 1rem;
  background: rgba(240, 180, 41, 0.1);
  border: 1px solid rgba(240, 180, 41, 0.35);
  border-radius: var(--radius);
  color: #f5e6b8;
  font-size: 0.88rem;
  animation: fade-in var(--med) ease;
}
.ip-banner p { flex: 1; }
.banner-dismiss {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.25rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 0.2rem;
}
.banner-dismiss:hover { color: var(--ink); }

/* —— shell —— */
.app-shell {
  flex: 1;
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
  padding: 0.75rem 1.25rem 2.5rem;
}

.view {
  animation: view-in var(--med) ease both;
}
@keyframes view-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.app-foot {
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
  padding: 1rem 1.25rem 1.5rem;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--line);
}
.app-foot a { color: var(--accent); text-decoration: none; }

/* —— typography —— */
h1 {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 3vw, 1.85rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.35rem;
}
.lede {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 1.25rem;
  max-width: 40rem;
}
.h2 {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.65rem;
}

/* —— cards / panels —— */
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem;
  box-shadow: var(--shadow);
}
.panel + .panel { margin-top: 0.85rem; }
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}
@media (max-width: 720px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* —— buttons —— */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1.1rem;
  border-radius: 7px;
  font-weight: 600;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: transform var(--fast), background var(--fast), border-color var(--fast), opacity var(--fast);
  color: var(--ink);
  background: transparent;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent); color: #04201c; }
.btn.primary:hover { background: #5eead4; }
.btn.ghost {
  border-color: var(--line);
  background: rgba(255,255,255,0.02);
}
.btn.ghost:hover { border-color: var(--muted); }
.btn.danger { border-color: rgba(248,113,113,0.4); color: var(--danger); }
.btn.sm { padding: 0.4rem 0.7rem; font-size: 0.8rem; }
.btn.block { width: 100%; }

/* —— forms —— */
.form { display: flex; flex-direction: column; gap: 0.85rem; }
.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field label {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}
.field input, .field select {
  appearance: none;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  font: inherit;
  padding: 0.65rem 0.75rem;
  transition: border-color var(--fast);
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: rgba(45, 212, 191, 0.55);
}
.field .hint { font-size: 0.75rem; color: var(--muted); }
.form-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.form-error {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.2em;
}
.form-ok {
  color: var(--ok);
  font-size: 0.85rem;
}
.auth-switch {
  margin-top: 1rem;
  color: var(--muted);
  font-size: 0.88rem;
}
.auth-switch a { color: var(--accent); text-decoration: none; }
.auth-card {
  max-width: 420px;
  margin: 1.5rem auto 0;
}

/* —— bot toggles —— */
.bot-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--line);
}
.bot-row:last-child { border-bottom: 0; padding-bottom: 0; }
.bot-row:first-child { padding-top: 0; }
.bot-meta { display: flex; flex-direction: column; gap: 0.15rem; }
.bot-label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
}
.bot-status {
  font-size: 0.78rem;
  color: var(--muted);
}
.bot-status.on { color: var(--ok); }
.bot-status.off { color: var(--muted); }
.bot-status.pending { color: var(--warn); }

.toggle {
  position: relative;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
}
.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.toggle-track {
  position: absolute;
  inset: 0;
  background: #1a2229;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: background var(--fast), border-color var(--fast);
}
.toggle-track::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  background: var(--muted);
  border-radius: 50%;
  transition: transform var(--fast), background var(--fast);
}
.toggle input:checked + .toggle-track {
  background: rgba(45, 212, 191, 0.25);
  border-color: rgba(45, 212, 191, 0.5);
}
.toggle input:checked + .toggle-track::after {
  transform: translateX(20px);
  background: var(--accent);
}
.toggle input:disabled + .toggle-track { opacity: 0.5; cursor: not-allowed; }

/* —— pools —— */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
  margin-bottom: 0.85rem;
}
.toolbar .field { flex: 1; min-width: 160px; }
.toolbar input, .toolbar select {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  font: inherit;
  padding: 0.55rem 0.7rem;
}
.refresh-hint {
  font-size: 0.78rem;
  color: var(--muted);
  min-height: 1.1em;
  opacity: 0;
  transition: opacity var(--med);
}
.refresh-hint.is-on { opacity: 1; color: var(--accent); }

.pools-table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}
.pools-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.pools-table th, .pools-table td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.pools-table th {
  position: sticky;
  top: 0;
  background: #151c22;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
}
.pools-table th:hover { color: var(--ink); }
.pools-table th .sort-ind { margin-left: 0.25rem; opacity: 0.7; }
.pools-table tbody tr {
  transition: background var(--fast);
}
.pools-table tbody tr:hover { background: rgba(45, 212, 191, 0.05); }
.pools-table td.num { font-variant-numeric: tabular-nums; }
.fav-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.05rem;
  padding: 0.15rem;
  line-height: 1;
  transition: color var(--fast), transform var(--fast);
}
.fav-btn:hover { color: var(--accent-2); transform: scale(1.1); }
.fav-btn.is-on { color: var(--accent-2); }
.chip {
  display: inline-block;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  background: rgba(45, 212, 191, 0.1);
  border: 1px solid rgba(45, 212, 191, 0.2);
  font-size: 0.72rem;
  color: var(--accent);
}
.empty-state {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

/* —— skeleton —— */
.skel {
  background: linear-gradient(90deg, #151c22 25%, #1c252e 50%, #151c22 75%);
  background-size: 200% 100%;
  animation: skel 1.1s ease infinite;
  border-radius: 6px;
  height: 0.9rem;
}
@keyframes skel {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skel-row { display: flex; gap: 0.75rem; padding: 0.65rem 0.75rem; border-bottom: 1px solid var(--line); }
.skel-row .skel { flex: 1; }

/* —— portfolio —— */
.portfolio-status {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.65rem;
}
.portfolio-status.busy { color: var(--accent); }
.kv {
  display: grid;
  grid-template-columns: 9rem 1fr;
  gap: 0.35rem 0.75rem;
  font-size: 0.9rem;
}
.kv dt { color: var(--muted); }
.kv dd { font-variant-numeric: tabular-nums; word-break: break-all; }

/* —— vault hints —— */
.status-dots {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}
.pill {
  font-size: 0.75rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.pill.ok {
  border-color: rgba(52, 211, 153, 0.4);
  color: var(--ok);
  background: rgba(52, 211, 153, 0.08);
}
.pill.miss {
  border-color: rgba(248, 113, 113, 0.35);
  color: var(--danger);
  background: rgba(248, 113, 113, 0.06);
}

/* —— toasts —— */
.toasts {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(360px, calc(100vw - 2rem));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 0.75rem 0.95rem;
  border-radius: 8px;
  background: #172028;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  animation: toast-in var(--med) ease;
}
.toast.err { border-color: rgba(248,113,113,0.45); color: #fecaca; }
.toast.ok { border-color: rgba(52,211,153,0.4); color: #a7f3d0; }
.toast.info { color: var(--ink); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(12px); }
  to { opacity: 1; transform: translateX(0); }
}

[hidden] { display: none !important; }
