/* ==========================================================
   TV2MT5 Bridge — Global Design System
   Aesthetic: Precision Dark (Industrial Utilitarian + Luxury Refined)
   Fonts: Space Grotesk (display) + JetBrains Mono (data/code)
   ========================================================== */

/* ---------- CSS Variables ---------- */
:root {
  /* Color Story: Deep void + Electric green terminal + Amber accent */
  --bg-void:      #050608;
  --bg-surface:   #0a0c10;
  --bg-elevated:  #0f1117;
  --bg-card:      #131720;
  --bg-card-hover:#171c28;
  --bg-input:     #0c0f16;

  --border:       #1e2535;
  --border-light: #2a3347;
  --border-focus: #39ff8a;

  /* Terminal green — the signature color */
  --green:        #39ff8a;
  --green-dim:    #1a7a42;
  --green-glow:   rgba(57, 255, 138, 0.15);
  --green-glow-sm:rgba(57, 255, 138, 0.08);

  /* Amber accent — warnings, secondary actions */
  --amber:        #f59e0b;
  --amber-dim:    #78490a;

  /* Red — danger, losses */
  --red:          #ff3b5c;
  --red-dim:      #7a1029;

  /* Blues */
  --blue:         #3b82f6;
  --blue-dim:     #1a3a7a;
  --cyan:         #22d3ee;

  /* Purple */
  --purple:       #a855f7;

  /* Text hierarchy */
  --text-primary:   #f0f4ff;
  --text-secondary: #8892a8;
  --text-muted:     #4a5568;
  --text-disabled:  #2d3748;

  /* Typography */
  --font-display: 'Space Grotesk', sans-serif;
  --font-mono:    'JetBrains Mono', monospace;

  /* Spacing rhythm: 4px base */
  --s1: 0.25rem;   /* 4px */
  --s2: 0.5rem;    /* 8px */
  --s3: 0.75rem;   /* 12px */
  --s4: 1rem;      /* 16px */
  --s5: 1.25rem;   /* 20px */
  --s6: 1.5rem;    /* 24px */
  --s8: 2rem;      /* 32px */
  --s10: 2.5rem;   /* 40px */
  --s12: 3rem;     /* 48px */
  --s16: 4rem;     /* 64px */
  --s20: 5rem;     /* 80px */
  --s24: 6rem;     /* 96px */

  /* Border radius */
  --r1: 4px;
  --r2: 8px;
  --r3: 12px;
  --r4: 16px;
  --r-full: 9999px;

  /* Shadows */
  --shadow-card:  0 4px 24px rgba(0,0,0,0.4), 0 1px 4px rgba(0,0,0,0.3);
  --shadow-glow:  0 0 20px var(--green-glow), 0 0 60px rgba(57,255,138,0.06);
  --shadow-lift:  0 8px 40px rgba(0,0,0,0.6);

  /* Transitions */
  --t-fast:   0.12s ease;
  --t-mid:    0.25s ease;
  --t-slow:   0.4s ease;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-display);
  background: var(--bg-void);
  color: var(--text-primary);
  line-height: 1.6;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
}

ul { list-style: none; }

img { max-width: 100%; display: block; }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-surface); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--green-dim); }

/* ---------- Focus States (Accessible) ---------- */
:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 3px;
  border-radius: var(--r1);
}

/* ---------- Global Typography ---------- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

code, pre, .mono {
  font-family: var(--font-mono);
}

/* ---------- Utility Classes ---------- */
.text-green  { color: var(--green); }
.text-amber  { color: var(--amber); }
.text-red    { color: var(--red); }
.text-blue   { color: var(--blue); }
.text-muted  { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }

.mono { font-family: var(--font-mono); }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border-width: 0;
}

/* ---------- Status Indicators ---------- */
.status-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.connected    { background: var(--green); box-shadow: 0 0 6px var(--green); animation: pulse-green 2s infinite; }
.status-dot.disconnected { background: var(--text-muted); }
.status-dot.error        { background: var(--red); animation: pulse-red 1.5s infinite; }
.status-dot.pending      { background: var(--amber); animation: pulse-amber 1.5s infinite; }

@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 4px var(--green); }
  50% { box-shadow: 0 0 12px var(--green), 0 0 20px var(--green-glow); }
}
@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 4px var(--red); }
  50% { box-shadow: 0 0 12px var(--red); }
}
@keyframes pulse-amber {
  0%, 100% { box-shadow: 0 0 4px var(--amber); }
  50% { box-shadow: 0 0 12px var(--amber); }
}

/* ---------- Buttons ---------- */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s3) var(--s6);
  background: var(--green);
  color: var(--bg-void);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: var(--r2);
  transition: all var(--t-fast);
  letter-spacing: 0.01em;
  position: relative;
  overflow: hidden;
}
.btn-primary::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.15) 0%, transparent 60%);
  opacity: 0;
  transition: opacity var(--t-fast);
}
.btn-primary:hover {
  background: #4dffa0;
  box-shadow: var(--shadow-glow);
  transform: translateY(-1px);
}
.btn-primary:hover::before { opacity: 1; }
.btn-primary:active { transform: translateY(0); }

.btn-primary--lg {
  padding: var(--s4) var(--s8);
  font-size: 1rem;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s3) var(--s6);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--r2);
  transition: all var(--t-fast);
}
.btn-ghost:hover {
  border-color: var(--border-light);
  color: var(--text-primary);
  background: rgba(255,255,255,0.03);
}

.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) var(--s4);
  background: rgba(255,59,92,0.1);
  color: var(--red);
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 500;
  border: 1px solid rgba(255,59,92,0.25);
  border-radius: var(--r2);
  transition: all var(--t-fast);
}
.btn-danger:hover {
  background: rgba(255,59,92,0.18);
  border-color: rgba(255,59,92,0.4);
}

/* ---------- Form Elements ---------- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}

.form-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.form-input {
  width: 100%;
  padding: var(--s3) var(--s4);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r2);
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 0.9rem;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  outline: none;
}
.form-input:hover { border-color: var(--border-light); }
.form-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--green-glow-sm);
}
.form-input::placeholder { color: var(--text-muted); }
.form-input.error { border-color: var(--red); }
.form-input.mono { font-family: var(--font-mono); font-size: 0.85rem; }

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%238892a8' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-error {
  font-size: 0.78rem;
  color: var(--red);
  display: none;
}
.form-error.visible { display: block; }

.form-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ---------- Card Base ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r3);
  padding: var(--s6);
  transition: border-color var(--t-mid);
}
.card:hover { border-color: var(--border-light); }

/* ---------- Badge / Tag ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  padding: 2px var(--s2);
  border-radius: var(--r-full);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.badge-success { background: rgba(57,255,138,0.1); color: var(--green); border: 1px solid rgba(57,255,138,0.25); }
.badge-error   { background: rgba(255,59,92,0.1);  color: var(--red);   border: 1px solid rgba(255,59,92,0.25); }
.badge-warning { background: rgba(245,158,11,0.1); color: var(--amber); border: 1px solid rgba(245,158,11,0.25); }
.badge-info    { background: rgba(59,130,246,0.1); color: var(--blue);  border: 1px solid rgba(59,130,246,0.25); }
.badge-neutral { background: rgba(136,146,168,0.1); color: var(--text-secondary); border: 1px solid var(--border); }

/* ---------- Table Base ---------- */
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.85rem;
}
.data-table th {
  padding: var(--s3) var(--s4);
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid rgba(30,37,53,0.5);
  color: var(--text-secondary);
  transition: color var(--t-fast);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { color: var(--text-primary); background: rgba(255,255,255,0.01); }
.data-table .mono { font-family: var(--font-mono); font-size: 0.82rem; }

/* ---------- Scrollable container ---------- */
.table-scroll {
  overflow-x: auto;
  border-radius: var(--r3);
  border: 1px solid var(--border);
}
.table-scroll .data-table th:first-child { padding-left: var(--s6); }
.table-scroll .data-table td:first-child { padding-left: var(--s6); }

/* ---------- Number animations ---------- */
@keyframes number-flash {
  0%   { color: var(--green); }
  100% { color: inherit; }
}
.num-flash { animation: number-flash 0.6s ease-out; }

/* ---------- Toast Notifications ---------- */
.toast-container {
  position: fixed;
  bottom: var(--s6);
  right: var(--s6);
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  z-index: 9999;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) var(--s5);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r3);
  font-size: 0.85rem;
  box-shadow: var(--shadow-lift);
  pointer-events: all;
  animation: toast-in 0.3s ease;
  max-width: 320px;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.warning { border-left: 3px solid var(--amber); }
.toast.info    { border-left: 3px solid var(--blue); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(24px); }
  to   { opacity: 1; transform: translateX(0); }
}
.toast-out {
  animation: toast-out 0.25s ease forwards;
}
@keyframes toast-out {
  to { opacity: 0; transform: translateX(24px); }
}

/* ---------- Loading skeleton ---------- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-card-hover) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--r2);
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---------- Dividers ---------- */
.divider {
  height: 1px;
  background: var(--border);
  margin: var(--s6) 0;
}

/* ---------- Responsive helpers ---------- */
@media (max-width: 768px) {
  .hide-mobile { display: none !important; }
}
@media (min-width: 769px) {
  .hide-desktop { display: none !important; }
}
