: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;
}

.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;
}

/* 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;
}

@media (max-width: 960px) {
  body { padding: 16px; }
  .chart-section { grid-template-columns: 1fr; }
}

