:root {
  --bg: #0b1324;
  --surface: #111a2e;
  --surface-2: #16213c;
  --text: #e8ecf2;
  --muted: #9fb1cf;
  --accent: #3fa9f5;
  --success: #31c48d;
  --danger: #f05252;
  --border: #1e2a44;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(circle at 20% 20%, rgba(63, 169, 245, 0.15), transparent 25%), radial-gradient(circle at 80% 10%, rgba(49, 196, 141, 0.15), transparent 20%), var(--bg);
  color: var(--text);
  padding: 24px;
}

h1, h3 { margin: 0; }

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.sub {
  color: var(--muted);
  margin-top: 4px;
}

.actions {
  display: flex;
  gap: 8px;
}

button {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  box-shadow: var(--shadow);
}

button.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

button:hover { opacity: 0.9; }

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  font-size: 1.2rem;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: rgba(255,255,255,0.05);
  border-color: var(--accent);
}

/* Sync Indicator */
.sync-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(255,213,79,0.15);
  border: 1px solid rgba(255,213,79,0.3);
  border-radius: 20px;
  font-size: 0.85rem;
  color: #ffd54f;
}
.sync-spinner {
  animation: spin 1.5s linear infinite;
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
.sync-indicator.completed {
  background: rgba(0,200,83,0.15);
  border-color: rgba(0,200,83,0.3);
  color: #00c853;
}
.sync-indicator.error {
  background: rgba(255,68,68,0.15);
  border-color: rgba(255,68,68,0.3);
  color: #ff6b6b;
}
.sync-indicator.syncing .sync-spinner {
  animation: spin 1.5s linear infinite;
}
.sync-indicator.completed .sync-spinner,
.sync-indicator.error .sync-spinner {
  animation: none;
}
.sync-progress-mini {
  width: 60px;
  height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  overflow: hidden;
  margin-left: 4px;
}
.sync-progress-mini .sync-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #00e5ff, #00b8d4);
  transition: width 0.3s ease;
  border-radius: 2px;
}

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  background: var(--surface);
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.filter label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.filter input, .filter select {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.card {
  background: var(--surface);
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.card .label { color: var(--muted); margin: 0 0 6px; font-size: 13px; }
.card .value { font-size: 24px; font-weight: 700; margin: 0; }

.chart-section {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.chart-card {
  background: var(--surface);
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: relative;
  min-height: 420px;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.badge {
  background: var(--surface-2);
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.best-worst {
  display: grid;
  gap: 8px;
}

.bw-item {
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.bw-item .title { margin: 0 0 4px; font-weight: 700; }
.bw-item .meta { margin: 0; color: var(--muted); font-size: 13px; }

.table-section {
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 12px;
  box-shadow: var(--shadow);
}

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.table-wrapper {
  overflow: auto;
  max-height: 600px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

th {
  background: var(--surface-2);
  position: sticky;
  top: 0;
  z-index: 1;
  cursor: pointer;
}

tr:hover td { background: rgba(63, 169, 245, 0.05); }

.row-negative td {
  background: rgba(240, 82, 82, 0.14);
  border-left: 3px solid #f05252;
}
.row-positive td {
  background: rgba(49, 196, 141, 0.14);
  border-left: 3px solid #31c48d;
}

.symbol-cell .symbol-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.symbol-wrapper img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.symbol-main { font-weight: 700; }
.symbol-sub { color: var(--muted); font-size: 12px; }

.detail-header { margin-bottom: 10px; }
.detail-kpis { margin-top: 8px; }

.btn-link {
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 8px;
}

.info-card {
  margin-top: 16px;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 8px;
}

.chart-status {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--muted);
  pointer-events: none;
  font-size: 14px;
  display: none;
}

.chart-container {
  position: relative;
  width: 100%;
  height: 420px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chart-pane {
  width: 100%;
  position: relative;
}

.price-pane { height: 70%; }
.volume-pane { height: 30%; }

/* OHLCV Legend */
.ohlcv-legend {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 12px;
  background: rgba(11, 19, 36, 0.9);
  border-radius: 6px;
  font-size: 13px;
  font-family: 'SF Mono', 'Consolas', monospace;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.legend-time {
  color: var(--muted);
  font-weight: 500;
}
.legend-item {
  color: var(--muted);
}
.legend-item span {
  color: var(--text-primary);
  font-weight: 500;
}
.legend-change {
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 12px;
}
.legend-change.positive {
  background: rgba(0, 200, 83, 0.15);
  color: #00c853;
}
.legend-change.negative {
  background: rgba(255, 68, 68, 0.15);
  color: #ff6b6b;
}

.pill {
  padding: 4px 8px;
  border-radius: 6px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
}

.pill.long { background: rgba(63, 169, 245, 0.15); color: #7bd7ff; }
.pill.short { background: rgba(240, 82, 82, 0.15); color: #ff9b9b; }

.positive { color: var(--success); }
.negative { color: var(--danger); }

/* Risk Analysis Section */
.risk-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px dashed var(--border);
}
.section-title {
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 12px 0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.risk-kpis {
  margin-top: 0;
}
.risk-kpis .card {
  background: linear-gradient(135deg, var(--surface) 0%, rgba(63, 169, 245, 0.05) 100%);
  position: relative;
}
.risk-kpis .value { font-size: 20px; }
.risk-kpis .hint {
  color: var(--muted);
  font-size: 11px;
  margin: 4px 0 0 0;
  opacity: 0.7;
}

/* Chart actions container */
.chart-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Recalc markers button */
.btn-recalc {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s ease;
}
.btn-recalc:hover {
  background: rgba(255, 193, 7, 0.1);
  border-color: rgba(255, 193, 7, 0.4);
  color: #ffc107;
}
.btn-recalc:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-recalc.loading {
  color: #ffc107;
}

/* Timeframe selector */
.tf-selector {
  display: flex;
  gap: 4px;
}
.tf-btn {
  background: rgba(159, 177, 207, 0.1);
  border: 1px solid rgba(159, 177, 207, 0.25);
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s ease;
}
.tf-btn:hover {
  background: rgba(159, 177, 207, 0.2);
  color: var(--text);
}
.tf-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.tf-btn.cached:not(.active) {
  border-color: rgba(0, 200, 83, 0.4);
  position: relative;
}
.tf-btn.cached:not(.active)::after {
  content: '';
  position: absolute;
  top: 2px;
  right: 2px;
  width: 4px;
  height: 4px;
  background: #00c853;
  border-radius: 50%;
}

.footer {
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
}

/* Info Card Header */
.info-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.info-card-header h3 {
  margin: 0;
}

/* Feature Button */
.btn-feature {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: linear-gradient(135deg, rgba(138, 43, 226, 0.2) 0%, rgba(75, 0, 130, 0.3) 100%);
  border: 1px solid rgba(138, 43, 226, 0.4);
  border-radius: 8px;
  color: #d8b4fe;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.btn-feature:hover {
  background: linear-gradient(135deg, rgba(138, 43, 226, 0.35) 0%, rgba(75, 0, 130, 0.45) 100%);
  border-color: rgba(138, 43, 226, 0.6);
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(138, 43, 226, 0.3);
}
.btn-feature:active {
  transform: translateY(0);
}
.btn-feature .feature-icon {
  font-size: 14px;
}

/* Modal Overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s ease;
}
.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* Modal Content */
.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  max-width: 700px;
  width: 95%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  transform: translateY(20px) scale(0.95);
  transition: transform 0.25s ease;
}
.modal-overlay.active .modal-content {
  transform: translateY(0) scale(1);
}

.feature-modal {
  max-width: 800px;
}

/* Modal Header */
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(138, 43, 226, 0.1) 0%, transparent 100%);
  border-radius: 16px 16px 0 0;
}
.modal-header h3 {
  margin: 0;
  font-size: 18px;
  color: var(--text);
}
.modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.15s ease;
}
.modal-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

/* Modal Body */
.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

/* Feature Loading */
.feature-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--muted);
}
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(138, 43, 226, 0.2);
  border-top-color: #8b5cf6;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 16px;
}

/* Feature Error */
.feature-error {
  padding: 20px;
  background: rgba(240, 82, 82, 0.1);
  border: 1px solid rgba(240, 82, 82, 0.3);
  border-radius: 8px;
  text-align: center;
}
.feature-error .error-text {
  color: #f87171;
  margin: 0;
}

/* Feature Meta */
.feature-meta {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: rgba(138, 43, 226, 0.08);
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 13px;
}
.feature-meta-item {
  display: flex;
  align-items: center;
  gap: 6px;
}
.feature-meta-item .meta-label {
  color: var(--muted);
}
.feature-meta-item .meta-value {
  font-weight: 600;
  color: var(--text);
}
.feature-meta-item .meta-value.win {
  color: var(--success);
}
.feature-meta-item .meta-value.loss {
  color: var(--danger);
}

/* Feature Table */
.feature-table-wrapper {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.feature-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.feature-table th {
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
  padding: 10px 12px;
  text-align: left;
  position: sticky;
  top: 0;
}
.feature-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.feature-table tr:last-child td {
  border-bottom: none;
}
.feature-table tr:hover td {
  background: rgba(138, 43, 226, 0.05);
}

/* Feature Categories */
.feature-category {
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
}
.feature-category.price-action {
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
}
.feature-category.volatility {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
}
.feature-category.momentum {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}
.feature-category.trend {
  background: rgba(139, 92, 246, 0.15);
  color: #a78bfa;
}
.feature-category.volume {
  background: rgba(236, 72, 153, 0.15);
  color: #f472b6;
}
.feature-category.context {
  background: rgba(107, 114, 128, 0.15);
  color: #9ca3af;
}
.feature-category.time {
  background: rgba(6, 182, 212, 0.15);
  color: #22d3ee;
}
.feature-category.regime {
  background: rgba(249, 115, 22, 0.15);
  color: #fb923c;
}
.feature-category.price-series {
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
}

/* Feature Values */
.feature-value {
  font-family: 'SF Mono', 'Consolas', monospace;
  font-weight: 600;
}
.feature-value.positive {
  color: var(--success);
}
.feature-value.negative {
  color: var(--danger);
}
.feature-value.neutral {
  color: var(--muted);
}

.feature-desc {
  color: var(--muted);
  font-size: 12px;
  max-width: 200px;
}

@media (max-width: 960px) {
  body { padding: 16px; }
  .chart-section { grid-template-columns: 1fr; }
  
  .modal-content {
    max-height: 90vh;
    margin: 16px;
    width: calc(100% - 32px);
  }
  
  .feature-table-wrapper {
    overflow-x: auto;
  }
  
  .feature-desc {
    display: none;
  }
}

