/* ===========================================================
   EDGE ALGO — COMPONENT LIBRARY
   Reused across every screen. No one-off variants per screen.
   =========================================================== */

/* ---------- Type scale ---------- */
.text-display { font-size: var(--text-display); font-weight: 700; letter-spacing: -0.02em; }
.text-h1 { font-size: var(--text-h1); font-weight: 700; letter-spacing: -0.01em; }
.text-h2 { font-size: var(--text-h2); font-weight: 600; }
.text-h3 { font-size: var(--text-h3); font-weight: 600; }
.text-caption { font-size: var(--text-caption); color: var(--text-muted); }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.numeric-lg { font-family: var(--font-mono); font-size: var(--text-numeric-lg); font-weight: 600; font-variant-numeric: tabular-nums; }
.numeric-sm { font-family: var(--font-mono); font-size: var(--text-numeric-sm); font-variant-numeric: tabular-nums; }
h1,h2,h3,h4 { margin: 0; }
p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout helpers ---------- */
.container { max-width: 1440px; margin: 0 auto; padding: 0 var(--space-6); }
.grid-12 { display: grid; grid-template-columns: repeat(12, 1fr); gap: var(--space-5); }
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--space-1); } .gap-2 { gap: var(--space-2); } .gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); } .gap-6 { gap: var(--space-6); }

/* ---------- Icons ---------- */
.icon { flex-shrink: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  font-family: var(--font-ui); font-size: 0.875rem; font-weight: 600;
  padding: 0 var(--space-4); height: 40px; border-radius: var(--radius-sm);
  border: 1px solid transparent; cursor: pointer; white-space: nowrap;
  transition: background var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease), opacity var(--duration-fast) var(--ease);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { height: 32px; padding: 0 var(--space-3); font-size: 0.8125rem; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--bg-surface-raised); color: var(--text-primary); border-color: var(--border-default); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-surface-hover); }
.btn-destructive { background: transparent; color: var(--loss); border-color: var(--loss); }
.btn-destructive:hover:not(:disabled) { background: var(--loss-bg); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-surface-hover); color: var(--text-primary); }
.btn-icon { width: 40px; height: 40px; padding: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-secondary); border: 1px solid transparent; }
.btn-icon:hover { background: var(--bg-surface-hover); color: var(--text-primary); }
.btn-icon svg { width: 18px; height: 18px; }
.btn.loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.loading::after {
  content: ''; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent; color: #fff;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Cards / panels ---------- */
.card {
  background: var(--bg-surface); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md); box-shadow: var(--shadow-card); padding: var(--space-5);
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-4); }
.card-interactive { cursor: pointer; transition: border-color var(--duration-fast) var(--ease), background var(--duration-fast) var(--ease); }
.card-interactive:hover { border-color: var(--border-strong); background: var(--bg-surface-raised); }

/* ---------- Badges / pills ---------- */
.badge { display: inline-flex; align-items: center; gap: var(--space-1); padding: 2px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge svg { width: 12px; height: 12px; }
.badge-profit { background: var(--profit-bg); color: var(--profit); }
.badge-loss { background: var(--loss-bg); color: var(--loss); }
.badge-flat { background: var(--flat-bg); color: var(--flat); }
.badge-risk-low { background: var(--risk-low-bg); color: var(--risk-low); }
.badge-risk-medium { background: var(--risk-medium-bg); color: var(--risk-medium); }
.badge-risk-high { background: var(--risk-high-bg); color: var(--risk-high); }
.badge-ai { background: var(--ai-accent-bg); color: var(--ai-accent); }
.badge-connected { background: var(--profit-bg); color: var(--status-connected); }
.badge-disconnected { background: var(--loss-bg); color: var(--status-disconnected); }
.badge-running { background: rgba(59,130,246,0.12); color: var(--status-running); }
.badge-paused { background: var(--risk-medium-bg); color: var(--status-paused); }
.badge-neutral { background: var(--bg-surface-raised); color: var(--text-secondary); border: 1px solid var(--border-default); }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-profit { background: var(--profit); } .dot-loss { background: var(--loss); } .dot-flat { background: var(--flat); }
.dot-connected { background: var(--status-connected); } .dot-disconnected { background: var(--status-disconnected); }
.dot-running { background: var(--status-running); box-shadow: 0 0 0 3px rgba(59,130,246,0.2); }

/* ---------- Paper mode indicator ---------- */
.paper-banner {
  background: var(--paper-mode-bg); border: 1px solid var(--paper-mode); color: var(--paper-mode);
  font-weight: 700; font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase;
  padding: var(--space-2) var(--space-4); border-radius: var(--radius-sm); display: inline-flex; align-items: center; gap: var(--space-2);
}
.paper-tag { background: var(--paper-mode); color: #1A1200; font-weight: 700; font-size: 0.6875rem; padding: 1px 7px; border-radius: 4px; letter-spacing: 0.04em; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: var(--space-4); }
.field { display: flex; flex-direction: column; gap: var(--space-1); }
.field label { font-size: 0.8125rem; font-weight: 600; color: var(--text-secondary); }
.input, .select, textarea.textarea {
  background: var(--bg-surface-raised); border: 1px solid var(--border-default); color: var(--text-primary);
  border-radius: var(--radius-sm); padding: 0 var(--space-3); height: 40px; font-family: var(--font-ui); font-size: 0.875rem;
  width: 100%; transition: border-color var(--duration-fast) var(--ease);
}
textarea.textarea { height: auto; padding: var(--space-3); resize: vertical; min-height: 96px; font-family: var(--font-ui); }
.input:focus, .select:focus, textarea.textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-bg); }
.input::placeholder, textarea::placeholder { color: var(--text-muted); }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237C8AA5' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 32px; cursor: pointer; }
.help-text { font-size: 0.75rem; color: var(--text-muted); }
.error-text { font-size: 0.75rem; color: var(--loss); }
.field.has-error .input, .field.has-error .select { border-color: var(--loss); }

.toggle { position: relative; width: 42px; height: 24px; border-radius: 999px; background: var(--border-default); cursor: pointer; border: none; flex-shrink: 0; transition: background var(--duration-fast) var(--ease); }
.toggle::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform var(--duration-fast) var(--ease); }
.toggle[aria-checked="true"] { background: var(--primary); }
.toggle[aria-checked="true"]::after { transform: translateX(18px); }

.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--border-subtle); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: var(--space-3) var(--space-4); font-size: 0.875rem; font-weight: 600; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; flex-shrink: 0; white-space: nowrap; }
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--text-primary); border-bottom-color: var(--primary); }

.slider { width: 100%; accent-color: var(--primary); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-md); border: 1px solid var(--border-subtle); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; min-width: 640px; }
.data-table th { text-align: left; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); font-weight: 600; padding: var(--space-3) var(--space-4); background: var(--bg-surface-raised); border-bottom: 1px solid var(--border-subtle); white-space: nowrap; cursor: pointer; user-select: none; }
.data-table th.no-sort { cursor: default; }
.data-table td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border-subtle); color: var(--text-primary); white-space: nowrap; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg-surface-raised); }
.sort-arrow { display: inline-block; margin-left: 4px; opacity: 0.5; font-size: 0.7rem; }

/* ---------- Feedback ---------- */
.toast-container { position: fixed; bottom: var(--space-6); right: var(--space-6); z-index: var(--z-toast); display: flex; flex-direction: column; gap: var(--space-2); }
.toast { background: var(--bg-surface-raised); border: 1px solid var(--border-default); box-shadow: var(--shadow-raised); border-radius: var(--radius-sm); padding: var(--space-3) var(--space-4); font-size: 0.875rem; min-width: 260px; display: flex; align-items: center; gap: var(--space-2); animation: toast-in var(--duration-base) var(--ease); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.empty-state { text-align: center; padding: var(--space-12) var(--space-6); color: var(--text-muted); }
.empty-state svg { width: 40px; height: 40px; margin-bottom: var(--space-3); color: var(--text-disabled); }

.skeleton { background: linear-gradient(90deg, var(--bg-surface-raised) 25%, var(--bg-surface-hover) 50%, var(--bg-surface-raised) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.modal-overlay { position: fixed; inset: 0; background: rgba(2,6,23,0.7); z-index: var(--z-modal); display: flex; align-items: center; justify-content: center; padding: var(--space-4); }
[data-theme="light"] .modal-overlay { background: rgba(15,23,42,0.4); }
.modal { background: var(--bg-surface); border: 1px solid var(--border-default); border-radius: var(--radius-lg); box-shadow: var(--shadow-raised); max-width: 480px; width: 100%; padding: var(--space-6); }
.modal-title { font-size: var(--text-h3); font-weight: 700; margin-bottom: var(--space-2); }

/* ---------- AI components ---------- */
.ai-card { background: var(--ai-accent-bg); border: 1px solid rgba(167,139,250,0.3); border-radius: var(--radius-md); padding: var(--space-4); }
.ai-tag { display: inline-flex; align-items: center; gap: var(--space-1); color: var(--ai-accent); font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.ai-tag svg { width: 13px; height: 13px; }
.agent-status { display: flex; align-items: center; gap: var(--space-2); font-size: 0.8125rem; color: var(--text-secondary); }

/* ---------- Sparkline placeholder (svg drawn inline per instance) ---------- */
.sparkline { display: block; }

/* ---------- Utility ---------- */
.divider { height: 1px; background: var(--border-subtle); border: none; margin: var(--space-4) 0; }
.scroll-y { overflow-y: auto; }
.clickable { cursor: pointer; }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* ---------- Responsive grid collapse ---------- */
@media (max-width: 1024px) {
  .grid-12 > [class*="col-"] { grid-column: span 12 !important; }
}
[class^="col-"], [class*=" col-"] {}
.col-3 { grid-column: span 3; } .col-4 { grid-column: span 4; } .col-5 { grid-column: span 5; }
.col-6 { grid-column: span 6; } .col-7 { grid-column: span 7; } .col-8 { grid-column: span 8; }
.col-9 { grid-column: span 9; } .col-12 { grid-column: span 12; }

@media (max-width: 768px) {
  .table-wrap.stack-mobile table.data-table { min-width: 100%; }
  .table-wrap.stack-mobile table.data-table thead { display: none; }
  .table-wrap.stack-mobile table.data-table, .table-wrap.stack-mobile tbody, .table-wrap.stack-mobile tr, .table-wrap.stack-mobile td { display: block; width: 100%; }
  .table-wrap.stack-mobile tr { border-bottom: 1px solid var(--border-subtle); padding: var(--space-3) var(--space-4); }
  .table-wrap.stack-mobile td { border: none; padding: var(--space-1) 0; display: flex; justify-content: space-between; white-space: normal; }
  .table-wrap.stack-mobile td::before { content: attr(data-label); color: var(--text-muted); font-size: 0.75rem; }
}
