:root {
  --bg: #080c14;
  --bg-elev: #0f1624;
  --bg-card: #131c2e;
  --bg-card-hover: #182338;
  --border: #1e2b45;
  --border-strong: #2c3e61;
  --text: #eef2f9;
  --text-muted: #8b9ab8;
  --emerald: #10b981;
  --emerald-soft: rgba(16, 185, 129, 0.14);
  --rose: #f43f5e;
  --rose-soft: rgba(244, 63, 94, 0.14);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.14);
  --blue: #3b82f6;
  --blue-soft: rgba(59, 130, 246, 0.14);
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

.muted {
  color: var(--text-muted);
}

code {
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 12px;
}

/* LOGIN */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(600px circle at 20% 20%, rgba(245, 158, 11, 0.08), transparent 60%),
    radial-gradient(600px circle at 80% 80%, rgba(16, 185, 129, 0.08), transparent 60%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.brand-lockup.compact {
  margin-bottom: 24px;
}

.brand-lockup h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.04em;
}

.brand-lockup p {
  margin: 2px 0 0;
  font-size: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #0b0f17;
  font-weight: 800;
  font-size: 16px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-title {
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 14px;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.login-foot {
  margin: 18px 0 0;
  font-size: 12px;
  text-align: center;
}

/* FORM & BUTTONS */
.stack-md {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stack-sm {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

input[type="text"],
input[type="password"],
input[type="number"],
select {
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus {
  border-color: var(--amber);
}

.input-with-btn {
  display: flex;
  gap: 8px;
}

.input-with-btn input {
  flex: 1;
}

.primary-btn,
.ghost-btn,
.chip-btn {
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  padding: 10px 16px;
  transition: all 0.15s;
}

.primary-btn {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #0b0f17;
}

.primary-btn:hover {
  filter: brightness(1.08);
}

.primary-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.ghost-btn {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border-strong);
}

.ghost-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.small-btn {
  padding: 7px 12px;
  font-size: 12px;
}

.full-width {
  width: 100%;
}

.chip-btn {
  background: var(--bg-elev);
  color: var(--text-muted);
  border-color: var(--border);
  padding: 6px 11px;
  font-size: 12px;
}

.chip-btn.active {
  background: var(--amber-soft);
  color: var(--amber);
  border-color: rgba(245, 158, 11, 0.45);
}

.form-error {
  background: var(--rose-soft);
  border: 1px solid rgba(244, 63, 94, 0.35);
  color: #fda4af;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
}

/* APP SHELL */
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px 1fr;
}

.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: sticky;
  top: 0;
  height: 100vh;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 10px 12px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.nav-item.active {
  background: var(--amber-soft);
  border-color: rgba(245, 158, 11, 0.32);
  color: var(--text);
  font-weight: 600;
}

.nav-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.55;
}

.nav-item.active .nav-dot {
  background: var(--amber);
  opacity: 1;
}

.pill-mini {
  margin-left: auto;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 99px;
}

.muted-pill {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}

.on-pill {
  background: var(--emerald-soft);
  color: var(--emerald);
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sync-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 12px;
}

.sync-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.status-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
}

.status-tag.online {
  background: var(--emerald-soft);
  color: var(--emerald);
}

.status-tag.offline {
  background: var(--rose-soft);
  color: var(--rose);
}

/* TOPBAR & CONTENT */
.main-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(8, 12, 20, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.topbar-left h2 {
  margin: 0;
  font-size: 18px;
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--emerald-soft);
  color: var(--emerald);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: 99px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
}

.live-pill.error {
  background: var(--rose-soft);
  color: var(--rose);
  border-color: rgba(244, 63, 94, 0.3);
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.select-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.select-inline select {
  padding: 6px 10px;
  font-size: 12px;
}

.content {
  padding: 22px 24px 40px;
  max-width: 1360px;
  width: 100%;
  margin: 0 auto;
}

.tab-panel {
  display: none;
  flex-direction: column;
  gap: 18px;
}

.tab-panel.active {
  display: flex;
}

/* CARDS & KPI */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.kpi-card.accent-emerald {
  border-top: 2px solid var(--emerald);
}

.kpi-card.accent-rose {
  border-top: 2px solid var(--rose);
}

.kpi-card.accent-amber {
  border-top: 2px solid var(--amber);
}

.kpi-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 22px;
  font-weight: 700;
}

.kpi-sub {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.section-head h3 {
  margin: 0;
  font-size: 15px;
}

.exchange-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(275px, 1fr));
  gap: 14px;
}

.ex-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color 0.15s, background 0.15s;
}

.ex-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-strong);
}

.ex-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.ex-name {
  font-weight: 700;
  font-size: 14.5px;
}

.badge-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.badge {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
}

.badge-live {
  background: var(--emerald-soft);
  color: var(--emerald);
}

.badge-best-buy {
  background: var(--blue-soft);
  color: #60a5fa;
}

.badge-best-sell {
  background: var(--amber-soft);
  color: var(--amber);
}

.ex-prices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.price-box {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}

.price-box .lbl {
  font-size: 11px;
  color: var(--text-muted);
}

.price-box .val {
  font-size: 15px;
  font-weight: 700;
  margin-top: 2px;
}

.price-box.buy .val {
  color: var(--emerald);
}

.price-box.sell .val {
  color: #fda4af;
}

.ex-foot {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 9px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.table-card {
  padding: 0;
  overflow: hidden;
}

.pad-card-head {
  padding: 16px 18px 0;
}

.card-title {
  font-weight: 700;
  font-size: 15px;
}

.card-head-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.tag-amber {
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  white-space: nowrap;
}

.toolbar-card, .filter-bar {
  padding: 14px 18px;
}

.toolbar-group {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
}

.amount-controls, .filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.preset-group {
  display: flex;
  gap: 6px;
}

.compact-input {
  width: 96px;
  padding: 6px 10px !important;
  font-size: 13px !important;
}

.filter-bar {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.data-table th,
.data-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.data-table th {
  background: var(--bg-elev);
  color: var(--text-muted);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.profit-pos {
  color: var(--emerald);
  font-weight: 700;
}

.profit-neg {
  color: var(--rose);
  font-weight: 600;
}

.split-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.form-row-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.top3-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.top3-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
  gap: 10px;
}

.positive-banner {
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 13px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
}

.positive-banner.good {
  background: var(--emerald-soft);
  border-color: rgba(16, 185, 129, 0.35);
  color: #a7f3d0;
}

.kv-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.kv-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  gap: 12px;
}

.error-panel {
  border-color: rgba(244, 63, 94, 0.35);
}

.error-list {
  margin: 10px 0 0;
  padding-left: 18px;
  color: #fda4af;
}

/* SWITCH */
.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #273248;
  border-radius: 99px;
  transition: 0.2s;
}

.slider::before {
  content: "";
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}

.switch input:checked + .slider {
  background: var(--emerald);
}

.switch input:checked + .slider::before {
  transform: translateX(22px);
}

/* TOAST */
#toast-container {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 11px 15px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 13px;
  min-width: 240px;
}

.toast.success {
  border-left: 3px solid var(--emerald);
}

.toast.error {
  border-left: 3px solid var(--rose);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
    gap: 14px;
  }
  .nav-list {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .nav-item {
    width: auto;
    padding: 8px 11px;
  }
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .split-2, .form-row-2 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }
  .topbar, .content {
    padding-left: 14px;
    padding-right: 14px;
  }
}
