/* ══════════════════════════════════════════════════════
   Composants réutilisables
   ══════════════════════════════════════════════════════ */

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: var(--pad-card, 20px);
  box-shadow: var(--shadow-card);
  transition: border-color var(--t-fast);
}
.card:hover { border-color: rgba(255, 255, 255, 0.09); }
.card-flush { padding: 0; overflow: hidden; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.card-head h2 { font-size: 13px; font-weight: 600; letter-spacing: 0; color: var(--text); }
.card h3 { font-size: 12.5px; margin-bottom: 10px; color: var(--text-2); font-weight: 600; }
.card > h3:first-child { margin-top: 0; }

/* ── Boutons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border-radius: var(--r-btn); border: 1px solid var(--border-strong);
  background: var(--elevated); color: var(--text);
  font-size: 12.5px; font-weight: 500; cursor: pointer;
  transition: transform var(--t-fast), background var(--t-fast), border-color var(--t-fast), opacity var(--t-fast);
  white-space: nowrap;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); background: #202430; }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: rgba(0, 212, 255, 0.12);
  border-color: rgba(0, 212, 255, 0.45);
  color: #9fe9ff;
}
.btn-primary:hover:not(:disabled) { background: rgba(0, 212, 255, 0.2); border-color: var(--accent); }

.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--hover); color: var(--text); border-color: var(--border-strong); }

.btn-danger { background: rgba(255, 61, 87, 0.1); border-color: rgba(255, 61, 87, 0.4); color: #ff8b9c; }
.btn-danger:hover:not(:disabled) { background: rgba(255, 61, 87, 0.18); border-color: var(--danger); }

.btn-sm { height: 28px; padding: 0 10px; font-size: 11.5px; }
.btn-icon { width: 34px; padding: 0; color: var(--text-2); }
.btn-icon:hover { color: var(--text); }

.chip {
  height: 30px; padding: 0 8px; border-radius: var(--r-input);
  background: transparent; border: 1px solid var(--border);
  color: var(--text-2); font-size: 11px; cursor: pointer;
  font-family: var(--font-mono);
}
.chip:hover { color: var(--text); border-color: var(--border-strong); }

.mini-btn {
  height: 24px; padding: 0 8px; border-radius: 6px;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-2); font-size: 11px; cursor: pointer;
}
.mini-btn:hover { color: var(--text); border-color: var(--border-strong); }
.mini-btn.buy:hover { color: var(--success); border-color: rgba(0, 200, 83, 0.4); }
.mini-btn.sell:hover { color: var(--danger); border-color: rgba(255, 61, 87, 0.4); }

/* ── Inputs ── */
.input, .field input, .field select {
  width: 100%; height: 34px; padding: 0 10px;
  background: #0e1015; border: 1px solid var(--border);
  border-radius: var(--r-input); color: var(--text);
  font-size: 12.5px; transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.input:focus, .field input:focus, .field select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.14);
}
input[type="number"] { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.5px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }

/* Interrupteur */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch i {
  position: absolute; inset: 0; background: #232732; border-radius: 999px;
  transition: background var(--t-fast); cursor: pointer;
}
.switch i::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  background: #6b7280; top: 3px; left: 3px; transition: transform var(--t-fast), background var(--t-fast);
}
.switch input:checked + i { background: rgba(0, 212, 255, 0.28); }
.switch input:checked + i::after { transform: translateX(16px); background: var(--accent); }
.switch input:disabled + i { opacity: 0.5; cursor: not-allowed; }

.toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.toggle-row:last-of-type { border-bottom: none; }
.toggle-row strong { display: block; font-size: 12.5px; font-weight: 500; }
.toggle-row .hint { display: block; }

.slider-row { margin-bottom: 16px; }
.slider-row label { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.slider-row b { font-family: var(--font-mono); color: var(--accent); font-weight: 500; }
input[type="range"] {
  -webkit-appearance: none; width: 100%; height: 4px; border-radius: 2px;
  background: #232732; outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 2px solid var(--bg);
}

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 20px; padding: 0 8px; border-radius: 5px;
  font-size: 10px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  border: 1px solid transparent; white-space: nowrap;
}
.badge-run { color: var(--success); background: var(--success-dim); border-color: rgba(0, 200, 83, 0.25); }
.badge-live { color: var(--danger); background: var(--danger-dim); border-color: rgba(255, 61, 87, 0.3); }
.badge-muted { color: var(--text-2); background: var(--elevated); border-color: var(--border); }
.badge-critical { color: var(--danger); background: var(--danger-dim); border-color: rgba(255, 61, 87, 0.3); }
.badge-high { color: var(--warning); background: var(--warning-dim); border-color: rgba(245, 166, 35, 0.3); }
.badge-mid { color: var(--accent); background: var(--accent-dim); border-color: rgba(0, 212, 255, 0.25); }
.badge-ok { color: var(--success); background: var(--success-dim); border-color: rgba(0, 200, 83, 0.25); }
.badge-off { color: var(--text-3); background: transparent; border-color: var(--border); }

/* ── Tableaux ── */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 12px; }
.table th {
  text-align: left; padding: 8px 10px;
  font-size: 11px; font-weight: 500; letter-spacing: 0.5px; text-transform: uppercase;
  color: var(--text-3); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td {
  padding: 9px 10px; border-bottom: 1px solid rgba(255, 255, 255, 0.035);
  font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.table td:first-child, .table th:first-child { padding-left: 0; }
.table td:last-child, .table th:last-child { padding-right: 0; }
.table tbody tr { transition: background var(--t-fast); }
.table-hover tbody tr, .table tbody tr:hover { cursor: default; }
.table tbody tr:hover { background: var(--hover); }
.table .empty-row td {
  font-family: var(--font-ui); color: var(--text-3); text-align: center; padding: 28px 10px;
}
.table .dir { font-family: var(--font-ui); font-size: 10.5px; font-weight: 600; padding: 2px 6px; border-radius: 4px; }
.dir.buy { color: var(--success); background: var(--success-dim); }
.dir.sell { color: var(--danger); background: var(--danger-dim); }

/* ── Metrics ── */
.metric { display: flex; flex-direction: column; gap: 4px; }
.metric strong { font-size: 20px; font-weight: 500; }
.metrics-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--gap-card, 16px); margin-bottom: var(--gap-card, 16px);
}
.metrics-row .metric {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-card); padding: 14px 16px;
}
.metrics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 12px; }
.metrics-grid .metric {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px;
}
.metrics-grid .metric strong { font-size: 15px; }

.kv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin: 14px 0; }
.kv-grid > div { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; }
.kv-grid strong { display: block; font-size: 13px; margin-top: 3px; }
.kv-grid.kv-2 { grid-template-columns: 1fr 1fr; }
.kv-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.kv-row:last-child { border-bottom: none; }
.kv-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.kv-head h3 { margin: 0; }

/* ── Tabs & filtres ── */
.tabs { display: flex; gap: 2px; padding: 8px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  padding: 6px 12px; border-radius: 6px; border: none; background: transparent;
  color: var(--text-2); font-size: 12px; cursor: pointer; white-space: nowrap;
  transition: color var(--t-fast), background var(--t-fast);
}
.tab:hover { color: var(--text); background: var(--hover); }
.tab.active { color: var(--accent); background: var(--accent-dim); }

.filters { display: flex; gap: 4px; flex-wrap: wrap; }
.filter {
  height: 24px; padding: 0 9px; border-radius: 5px; border: 1px solid transparent;
  background: transparent; color: var(--text-3); font-size: 11px; cursor: pointer;
  transition: color var(--t-fast), background var(--t-fast);
}
.filter:hover { color: var(--text-2); }
.filter.active { color: var(--text); background: var(--elevated); border-color: var(--border); }

.seg { display: inline-flex; gap: 2px; padding: 2px; background: #0e1015; border: 1px solid var(--border); border-radius: 7px; }
.seg-btn {
  height: 26px; padding: 0 12px; border-radius: 5px; border: none; background: transparent;
  color: var(--text-2); font-size: 11.5px; font-weight: 500; cursor: pointer;
}
.seg-btn.active[data-side="BUY"] { background: var(--success-dim); color: var(--success); }
.seg-btn.active[data-side="SELL"] { background: var(--danger-dim); color: var(--danger); }
.speedbtn {
  height: 26px; padding: 0 10px; border-radius: 5px; border: none; background: transparent;
  color: var(--text-2); font-family: var(--font-mono); font-size: 11px; cursor: pointer;
}
.speedbtn.active { background: var(--accent-dim); color: var(--accent); }

/* ── Compteurs / divers ── */
.count {
  font-family: var(--font-mono); font-size: 10.5px; color: var(--text-3);
  background: var(--elevated); border: 1px solid var(--border);
  padding: 0 6px; border-radius: 4px; margin-left: 6px;
}
.empty-state { padding: 24px 4px; color: var(--text-3); font-size: 12.5px; line-height: 1.6; }

.spin {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid rgba(0, 212, 255, 0.25); border-top-color: var(--accent);
  display: none; animation: spin 0.7s linear infinite;
}
.spin.on { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, #14161d 25%, #1a1d26 50%, #14161d 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 6px;
  height: 12px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── Toasts ── */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 900; }
.toast {
  min-width: 240px; max-width: 380px; padding: 11px 14px;
  background: var(--elevated); border: 1px solid var(--border-strong);
  border-left: 2px solid var(--accent);
  border-radius: 8px; font-size: 12.5px; color: var(--text);
  box-shadow: var(--shadow-modal);
  animation: toast-in 180ms ease-out;
}
.toast.err { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--success); }
.toast.warn { border-left-color: var(--warning); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── Modales ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.7);
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 12vh; z-index: 800; backdrop-filter: blur(2px);
}
.modal {
  width: 420px; max-width: calc(100vw - 32px);
  background: var(--elevated); border: 1px solid var(--border-strong);
  border-radius: 12px; padding: 20px; box-shadow: var(--shadow-modal);
  animation: modal-in 160ms ease-out;
}
@keyframes modal-in { from { opacity: 0; transform: scale(0.98); } to { opacity: 1; transform: none; } }
.modal h3 { font-size: 15px; margin-bottom: 8px; }
.modal p { color: var(--text-2); font-size: 12.5px; line-height: 1.6; }

/* Palette de commandes */
.palette {
  width: 560px; max-width: calc(100vw - 32px);
  background: var(--elevated); border: 1px solid var(--border-strong);
  border-radius: 12px; overflow: hidden; box-shadow: var(--shadow-modal);
}
.palette-input {
  width: 100%; height: 48px; padding: 0 16px; background: transparent;
  border: none; border-bottom: 1px solid var(--border);
  color: var(--text); font-size: 14px; outline: none;
}
.palette-list { max-height: 340px; overflow-y: auto; padding: 6px; }
.palette-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 7px; cursor: pointer; font-size: 12.5px;
}
.palette-item .pmeta { margin-left: auto; font-size: 11px; color: var(--text-3); font-family: var(--font-mono); }
.palette-item.sel, .palette-item:hover { background: var(--hover); }
.palette-item .picon { color: var(--text-3); display: flex; }
.palette-foot { padding: 8px 14px; border-top: 1px solid var(--border); font-size: 10.5px; color: var(--text-3); }
