/* =========================================================================
   ArbiTrade — Design System
   Palette:  bg #070B12 · surface #0E141F · surface-2 #131B29
             accent (teal) #2FD4C8 · accent-2 (violet-blue) #6C8CFF
             success #1FD97A · danger #FF4757 · warning #FFB020
   Type: Sora (display) / Inter (UI) / IBM Plex Mono (numeric data)
   ========================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Sora:wght@600;700;800&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500;600;700&display=swap');

:root{
  --bg: #070b12;
  --surface: #0e141f;
  --surface-2: #131b29;
  --surface-3: #182234;
  --border: rgba(255,255,255,0.07);
  --border-strong: rgba(255,255,255,0.14);
  --text: #eaf0fa;
  --text-dim: #8a96ac;
  --text-faint: #566079;

  --accent: #2fd4c8;
  --accent-dim: rgba(47,212,200,0.14);
  --accent-2: #6c8cff;
  --accent-2-dim: rgba(108,140,255,0.14);

  --success: #1fd97a;
  --success-dim: rgba(31,217,122,0.12);
  --danger: #ff4757;
  --danger-dim: rgba(255,71,87,0.12);
  --warning: #ffb020;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;

  --shadow-card: 0 1px 0 rgba(255,255,255,0.03) inset, 0 10px 30px -18px rgba(0,0,0,0.7);
  --shadow-pop: 0 20px 60px -20px rgba(0,0,0,0.8);

  --nav-h: 60px;
  --tab-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

*,*::before,*::after{ box-sizing: border-box; }
html{ -webkit-text-size-adjust: 100%; }

body{
  margin:0;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(108,140,255,0.08), transparent 60%),
    radial-gradient(1000px 500px at 100% 0%, rgba(47,212,200,0.06), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height:100vh;
}

.font-display{ font-family:'Sora', 'Inter', sans-serif; letter-spacing:-0.01em; }
.font-mono{ font-family:'IBM Plex Mono', ui-monospace, monospace; font-variant-numeric: tabular-nums; letter-spacing:-0.01em; }

a{ color: inherit; text-decoration:none; }
button{ font-family: inherit; }

/* ---------- Focus & motion ---------- */
:focus-visible{ outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
@media (prefers-reduced-motion: reduce){
  *{ animation-duration:0.001ms !important; animation-iteration-count:1 !important; transition-duration:0.001ms !important; }
}

/* ---------- App shell ---------- */
.app{
  max-width: 1440px;
  margin: 0 auto;
  padding-bottom: calc(var(--tab-h) + var(--safe-b) + 12px);
}
@media (min-width: 1024px){
  .app{ padding-bottom: 32px; }
}

/* ---------- Top bar ---------- */
.topbar{
  position: sticky; top:0; z-index: 40;
  display:flex; align-items:center; justify-content:space-between;
  gap:12px;
  height: var(--nav-h);
  padding: 0 16px;
  background: rgba(7,11,18,0.82);
  backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid var(--border);
}
.brand{ display:flex; align-items:center; gap:10px; }
.brand-mark{
  width:32px; height:32px; border-radius:9px;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  display:flex; align-items:center; justify-content:center;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.08) inset, 0 6px 16px -6px rgba(47,212,200,0.6);
  flex-shrink:0;
}
.brand-mark svg{ width:18px; height:18px; }
.brand-name{ font-size:16px; font-weight:700; }
.brand-name span{ color: var(--accent); }

.topbar-right{ display:flex; align-items:center; gap:10px; }
.live-pill{
  display:flex; align-items:center; gap:6px;
  font-size:12px; font-weight:600; color: var(--success);
  background: var(--success-dim);
  border:1px solid rgba(31,217,122,0.25);
  padding:6px 10px; border-radius: 999px;
}
.live-dot{ width:6px; height:6px; border-radius:50%; background: var(--success); box-shadow:0 0 0 0 rgba(31,217,122,0.6); animation: pulse-dot 1.8s infinite; }
@keyframes pulse-dot{
  0%{ box-shadow:0 0 0 0 rgba(31,217,122,0.55); }
  70%{ box-shadow:0 0 0 6px rgba(31,217,122,0); }
  100%{ box-shadow:0 0 0 0 rgba(31,217,122,0); }
}
.icon-btn{
  width:34px; height:34px; border-radius:10px;
  display:flex; align-items:center; justify-content:center;
  background: var(--surface-2); border:1px solid var(--border);
  color: var(--text-dim);
}
.icon-btn svg{ width:16px; height:16px; }

/* ---------- Desktop nav (hidden on mobile) ---------- */
.desknav{ display:none; }
@media (min-width: 1024px){
  .desknav{ display:flex; gap:4px; }
  .desknav a{
    font-size:13px; font-weight:600; color: var(--text-dim);
    padding:8px 14px; border-radius:10px;
    letter-spacing:0.02em;
  }
  .desknav a.active{ color: var(--text); background: var(--surface-2); }
}

/* ---------- Mobile bottom tab bar ---------- */
.tabbar{
  position: fixed; left:0; right:0; bottom:0; z-index:40;
  height: calc(var(--tab-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: rgba(14,20,31,0.92);
  backdrop-filter: blur(16px) saturate(140%);
  border-top: 1px solid var(--border);
  display:flex;
}
@media (min-width: 1024px){ .tabbar{ display:none; } }
.tab-item{
  flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center;
  gap:4px; color: var(--text-faint); font-size:10.5px; font-weight:600;
}
.tab-item svg{ width:20px; height:20px; }
.tab-item.active{ color: var(--accent); }

/* ---------- Layout grid ---------- */
.container{ padding: 14px; }
@media (min-width: 640px){ .container{ padding:20px; } }
@media (min-width: 1024px){ .container{ padding:24px; } }

.grid{ display:grid; gap:14px; }
@media (min-width: 640px){ .grid{ gap:16px; } }

.grid-3{ grid-template-columns: repeat(1,1fr); }
@media (min-width:640px){ .grid-3{ grid-template-columns: repeat(3,1fr); } }
@media (min-width:1024px){ .grid-3{ grid-template-columns: repeat(3,1fr); } }

.grid-2{ grid-template-columns: repeat(1,1fr); }
@media (min-width:1100px){ .grid-2{ grid-template-columns: 1.55fr 1fr; } }

.grid-2-even{ grid-template-columns: repeat(1,1fr); }
@media (min-width:900px){ .grid-2-even{ grid-template-columns: repeat(2,1fr); } }
@media (min-width:1280px){ .grid-2-even{ grid-template-columns: repeat(2,1fr); } }

.grid-tri{ grid-template-columns: repeat(1,1fr); }
@media (min-width:1280px){ .grid-tri{ grid-template-columns: repeat(3,1fr); } }
@media (min-width:900px) and (max-width:1279px){ .grid-tri{ grid-template-columns: repeat(2,1fr); } }

/* ---------- Card ---------- */
.card{
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow:hidden;
}
.card-pad{ padding:16px; }
@media (min-width:640px){ .card-pad{ padding:20px; } }

.card-head{
  display:flex; align-items:center; justify-content:space-between;
  padding:14px 16px; border-bottom:1px solid var(--border);
}
.card-title{
  font-size:12px; font-weight:700; letter-spacing:0.08em; text-transform:uppercase;
  color: var(--text-dim);
  display:flex; align-items:center; gap:8px;
}
.card-title .scan-dot{
  width:6px; height:6px; border-radius:50%; background: var(--accent);
  box-shadow: 0 0 8px 1px rgba(47,212,200,0.7);
  animation: scan-blink 1.6s infinite;
}
@keyframes scan-blink{ 0%,100%{opacity:.35} 50%{opacity:1} }

/* ---------- Ticker strip (exchange price cards) ---------- */
.ticker-scroll{
  display:flex; gap:10px; overflow-x:auto; padding: 2px 2px 6px;
  scroll-snap-type:x mandatory; -webkit-overflow-scrolling:touch;
}
.ticker-scroll::-webkit-scrollbar{ display:none; }
.ticker-card{
  scroll-snap-align:start; flex: 0 0 auto;
  width: 190px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border:1px solid var(--border); border-radius: var(--radius-md);
  padding:14px; box-shadow: var(--shadow-card);
}
@media (min-width:1024px){
  .ticker-scroll{ display:grid; grid-template-columns: repeat(6,1fr); overflow:visible; }
  .ticker-card{ width:auto; }
}
.ticker-top{ display:flex; align-items:center; justify-content:space-between; margin-bottom:10px;}
.ticker-pair{ font-size:12px; color:var(--text-dim); font-weight:600; }
.ticker-exchange{ font-size:14px; font-weight:700; margin-top:2px; }
.ticker-price{ font-size:19px; font-weight:700; }
.ticker-change{ font-size:12px; font-weight:700; margin-top:6px; display:inline-flex; align-items:center; gap:3px; }
.up{ color: var(--success); }
.down{ color: var(--danger); }
.spark{ width:100%; height:28px; margin-top:8px; }

/* ---------- Tables -> stacked cards on mobile ---------- */
.table-wrap{ overflow-x:auto; }
table.data{ width:100%; border-collapse:collapse; min-width:640px; }
table.data th{
  text-align:left; font-size:11px; text-transform:uppercase; letter-spacing:0.06em;
  color: var(--text-faint); font-weight:700; padding:10px 16px; border-bottom:1px solid var(--border);
  white-space:nowrap;
}
table.data td{
  padding:12px 16px; font-size:13.5px; border-bottom:1px solid var(--border); white-space:nowrap;
}
table.data tbody tr{ transition: background .15s; }
table.data tbody tr:hover{ background: rgba(255,255,255,0.02); }
table.data tbody tr:last-child td{ border-bottom:none; }

@media (max-width: 767px){
  .table-wrap.stack table.data,
  .table-wrap.stack thead{ display:none; }
  .table-wrap.stack table.data, .table-wrap.stack tbody, .table-wrap.stack tr{ display:block; width:100%; min-width:0; }
  .table-wrap.stack tr{
    border-bottom:1px solid var(--border); padding:14px 16px;
  }
  .table-wrap.stack td{
    display:flex; justify-content:space-between; align-items:center;
    padding:5px 0; border:none; font-size:13px;
  }
  .table-wrap.stack td::before{
    content: attr(data-label); color: var(--text-faint); font-size:11px;
    text-transform:uppercase; letter-spacing:0.05em; font-weight:700;
  }
  .table-wrap.stack td.tw-action{ padding-top:10px; }
  .table-wrap.stack td.tw-action::before{ content:none; }
}

.pill-profit{ font-weight:700; }
.btn-trade{
  background: linear-gradient(135deg, var(--accent), #21b8ad);
  color:#04211d; font-weight:700; font-size:12.5px;
  border:none; padding:8px 16px; border-radius:9px; cursor:pointer;
  box-shadow: 0 6px 14px -6px rgba(47,212,200,0.55);
}
.btn-trade:active{ transform: scale(0.97); }
.btn-trade:disabled{ opacity:.4; cursor:not-allowed; box-shadow:none; }

/* ---------- Chart panel ---------- */
.chart-legend{ display:flex; flex-wrap:wrap; gap:10px; padding:12px 16px 0; }
.legend-chip{ display:flex; align-items:center; gap:6px; font-size:11.5px; color:var(--text-dim); font-weight:600; }
.legend-dot{ width:8px; height:8px; border-radius:50%; }
.chart-frame{ width:100%; aspect-ratio: 16/11; border:0; display:block; background: var(--surface); }
@media (min-width:1024px){ .chart-frame{ aspect-ratio: 16/8; } }

/* ---------- Balance overview ---------- */
.balance-total{ padding:14px 16px; border-top:1px solid var(--border); display:flex; justify-content:space-between; align-items:center; }
.balance-total .val{ font-size:18px; font-weight:700; }

/* ---------- Triangular arbitrage diagram ---------- */
.tri-wrap{ padding:22px 16px 18px; display:flex; flex-direction:column; align-items:center; gap:0; }
.tri-diagram{ position:relative; width:100%; max-width:340px; aspect-ratio:1/0.92; }
.tri-node{
  position:absolute; width:64px; height:64px; border-radius:18px;
  display:flex; align-items:center; justify-content:center; font-weight:800; font-size:13px;
  border:1px solid var(--border-strong); box-shadow: var(--shadow-pop);
}
.tri-node.btc{ top:0; left:50%; transform:translateX(-50%); background: linear-gradient(145deg,#f7931a,#c9720e); }
.tri-node.eth{ bottom:0; left:0; background: linear-gradient(145deg,#6c8cff,#4a63d6); }
.tri-node.usdt{ bottom:0; right:0; background: linear-gradient(145deg,#1fd97a,#159a56); }
.tri-edge-label{ position:absolute; font-size:11px; text-align:center; line-height:1.4; }
.tri-edge-label .amt{ font-weight:700; color:var(--text); font-family:'IBM Plex Mono',monospace; }
.tri-edge-label .pct{ color:var(--success); font-weight:700; }
.tri-center{ position:absolute; top:50%; left:50%; transform:translate(-50%,-50%); text-align:center; }
.tri-center .lbl{ font-size:10.5px; color:var(--text-faint); text-transform:uppercase; letter-spacing:0.08em; font-weight:700; }
.tri-center .val{ font-size:20px; font-weight:800; color:var(--accent); margin-top:2px; }
.tri-center .sub{ font-size:11.5px; color:var(--text-dim); margin-top:2px; }

/* ---------- Market depth ---------- */
.depth-cols{ display:grid; grid-template-columns:1fr 1fr; }
.depth-col + .depth-col{ border-left:1px solid var(--border); }
.depth-head{ padding:10px 12px; font-size:11px; font-weight:700; letter-spacing:0.05em; }
.depth-row{ display:flex; justify-content:space-between; padding:6px 12px; font-size:12px; font-family:'IBM Plex Mono',monospace; }
.depth-bars{ display:flex; align-items:flex-end; gap:2px; height:64px; padding:10px 12px 14px; }
.depth-bar{ flex:1; border-radius:2px 2px 0 0; min-width:2px; }
.depth-spread{ text-align:center; padding:10px 0 14px; font-size:11px; color:var(--text-faint); }
.depth-spread .num{ font-weight:700; color:var(--text); }

/* ---------- Settings form ---------- */
.field{ margin-bottom:14px; }
.field label{ display:block; font-size:12px; font-weight:600; color:var(--text-dim); margin-bottom:6px; }
.field-input{
  position:relative; display:flex; align-items:center;
  background: var(--surface-3); border:1px solid var(--border); border-radius:11px;
}
.field-input input{
  flex:1; background:transparent; border:none; outline:none; color:var(--text);
  font-family:'IBM Plex Mono',monospace; font-size:14px; font-weight:600; padding:11px 12px;
  min-width:0;
}
.field-input .suffix{ padding:0 12px; font-size:12px; color:var(--text-faint); font-weight:700; }
.field-input:focus-within{ border-color: var(--accent); box-shadow:0 0 0 3px var(--accent-dim); }

.target-callout{
  background: var(--accent-2-dim); border:1px solid rgba(108,140,255,0.28);
  border-radius:14px; padding:14px; margin-bottom:16px;
}
.target-callout .lbl{ font-size:11px; color:var(--text-dim); text-transform:uppercase; letter-spacing:0.06em; font-weight:700; }
.target-callout .val{ font-size:24px; font-weight:800; color:var(--accent-2); margin-top:4px; font-family:'IBM Plex Mono',monospace; }
.target-callout .hint{ font-size:11.5px; color:var(--text-faint); margin-top:4px; }

.toggle-row{ display:flex; align-items:center; justify-content:space-between; padding:4px 0 14px; }
.switch{ position:relative; width:44px; height:26px; }
.switch input{ opacity:0; width:0; height:0; }
.slider{ position:absolute; inset:0; background: var(--surface-3); border:1px solid var(--border-strong); border-radius:999px; transition:.2s; cursor:pointer; }
.slider::before{ content:""; position:absolute; width:20px; height:20px; left:2px; top:2px; background:#fff; border-radius:50%; transition:.2s; }
.switch input:checked + .slider{ background: var(--success); border-color:transparent; }
.switch input:checked + .slider::before{ transform: translateX(18px); }

.btn-primary{
  width:100%; background: linear-gradient(135deg, var(--accent-2), #4a63d6);
  color:#fff; font-weight:700; font-size:14px; border:none; padding:13px; border-radius:12px; cursor:pointer;
  box-shadow: 0 10px 24px -10px rgba(108,140,255,0.6);
}
.btn-primary:active{ transform: scale(0.985); }

/* ---------- System status ---------- */
.status-row{ display:flex; justify-content:space-between; align-items:center; padding:12px 16px; border-bottom:1px solid var(--border); font-size:13px; }
.status-row:last-child{ border-bottom:none; }
.status-ok{ color:var(--success); font-weight:700; font-size:12.5px; display:flex; align-items:center; gap:6px; }
.status-ok::before{ content:""; width:6px; height:6px; border-radius:50%; background:var(--success); }
.load-bar{ width:90px; height:6px; background:var(--surface-3); border-radius:999px; overflow:hidden; }
.load-bar-fill{ height:100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

/* ---------- Recent trades status chip ---------- */
.chip-completed{ color:var(--success); font-weight:700; font-size:12px; background:var(--success-dim); padding:4px 9px; border-radius:999px; }

/* ─── Profit Strip Container ──────────────────────────────── */
.profit-strip-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 0 0 20px;
}

/* ─── Profit Cards ─────────────────────────────────────────── */
.profit-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px 24px;
  transition: all 0.2s ease;
}

.profit-card:hover {
  border-color: rgba(47, 212, 200, 0.3);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
}

.profit-card-alt {
  background: linear-gradient(135deg, rgba(47, 212, 200, 0.05), rgba(108, 140, 255, 0.04));
}

/* ─── Card Header ──────────────────────────────────────────── */
.profit-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.profit-card-icon {
  font-size: 18px;
  line-height: 1;
}

.profit-card-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
  font-weight: 700;
}

/* ─── Card Value ───────────────────────────────────────────── */
.profit-card-value {
  font-size: 28px;
  font-weight: 800;
  font-family: 'IBM Plex Mono', monospace;
  margin-bottom: 12px;
  letter-spacing: -0.02em;
}

.profit-card-value.positive {
  color: var(--success);
}

.profit-card-value.wallet {
  color: var(--accent-2);
}

/* ─── Progress ────────────────────────────────────────────── */
.profit-card-progress {
  max-width: 100%;
}

.progress-track {
  height: 6px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 6px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--success));
  transition: width 0.8s ease;
  border-radius: 999px;
}

.progress-caption {
  font-size: 10.5px;
  color: var(--text-faint);
  display: flex;
  justify-content: space-between;
}

/* ─── Card Footer ──────────────────────────────────────────── */
.profit-card-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  margin-top: 4px;
}

.profit-card-meta {
  font-size: 11.5px;
  color: var(--text-dim);
}

.profit-card-meta:first-child {
  color: var(--text-faint);
}

/* ─── Mobile Responsive ───────────────────────────────────── */
@media (max-width: 480px) {
  .profit-card {
    padding: 16px 18px;
  }
  
  .profit-card-value {
    font-size: 22px;
  }
  
  .profit-card-footer {
    flex-direction: column;
    gap: 4px;
  }
  
  .profit-card-meta {
    font-size: 10.5px;
  }
}

/* ---------- Section title (mobile) ---------- */
.section-title{ font-size:15px; font-weight:700; margin: 4px 2px 10px; }

/* ---------- Status / error banners (dashboard flash messages) ---------- */
.status-banner{
  background: var(--success-dim); border:1px solid rgba(31,217,122,0.3); color: var(--success);
  padding:10px 14px; border-radius:10px; font-size:13px; font-weight:600; margin-bottom:16px;
}
.error-banner{
  background: var(--danger-dim); border:1px solid rgba(255,71,87,0.3); color:#ffb3ba;
  padding:10px 14px; border-radius:10px; font-size:12.5px; margin-bottom:16px;
}
.error-banner ul{ margin:4px 0 0; padding-left:18px; }

.btn-sm{ font-size:12.5px; font-weight:700; padding:8px 14px; border-radius:9px; border:none; cursor:pointer; }
.btn-accent{ background:linear-gradient(135deg,var(--accent),#21b8ad); color:#04211d; }
.btn-ghost{ background:var(--surface-3); color:var(--text-dim); border:1px solid var(--border); }

.badge{ font-size:11px; font-weight:700; padding:3px 9px; border-radius:999px; display:inline-block; }
.badge-active{ color:var(--success); background:var(--success-dim); }
.badge-inactive{ color:var(--text-faint); background:var(--surface-3); }
.badge-pending{ color:var(--warning); background:rgba(255,176,32,0.14); }

/* ---------- Utility ---------- */
.text-dim{ color:var(--text-dim); }
.mt-14{ margin-top:14px; }
.hide-mobile{ display:none; }
@media (min-width:1024px){ .hide-mobile{ display:block; } }
