:root {
  --bg: #0b0f17;
  --panel: #121826;
  --panel-2: #171f31;
  --border: #243049;
  --text: #e8edf7;
  --muted: #8b98b8;
  --accent: #5b8cff;
  --accent-2: #7c5cff;
  --up: #22c55e;
  --down: #ef4444;
  --forecast: #f59e0b;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #15213a 0%, var(--bg) 45%);
  color: var(--text);
  min-height: 100vh;
}

.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: rgba(18, 24, 38, 0.92);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: var(--shadow);
}

.brand h1 {
  margin: 0;
  font-size: 18px;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

#searchInput {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  margin-bottom: 12px;
}

.market-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.market-tab {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
}

.market-tab.active {
  color: white;
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.stock-list {
  list-style: none;
  margin: 0;
  padding: 12px;
  overflow: auto;
  flex: 1;
}

.stock-item {
  padding: 12px 14px;
  border: 1px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.02);
}

.stock-item:hover,
.stock-item.active {
  border-color: rgba(91, 140, 255, 0.45);
  background: rgba(91, 140, 255, 0.08);
}

.stock-item .code {
  font-weight: 600;
  font-size: 14px;
}

.stock-item .name {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.main {
  padding: 24px;
  overflow: auto;
}

.main-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.title-block h2 {
  margin: 0 0 8px;
  font-size: 28px;
}

.title-block p {
  margin: 0;
  color: var(--muted);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
}

.controls label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.controls select,
.controls input {
  min-width: 100px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}

.primary-btn {
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-weight: 600;
}

.primary-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

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

.summary-card .label {
  color: var(--muted);
  font-size: 12px;
}

.summary-card .value {
  margin-top: 8px;
  font-size: 24px;
  font-weight: 700;
}

.summary-card .value.up {
  color: var(--up);
}

.summary-card .value.down {
  color: var(--down);
}

.chart-panel,
.table-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.chart-panel {
  margin-bottom: 20px;
}

.chart-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}

.legend-item {
  font-size: 12px;
  color: var(--muted);
}

.legend-item::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  margin-right: 6px;
}

.legend-item.history::before {
  background: var(--accent);
}

.legend-item.forecast::before {
  background: var(--forecast);
}

.status-badge {
  margin-left: auto;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.06);
}

.status-badge.loading {
  color: #fbbf24;
}

.status-badge.ready {
  color: var(--up);
}

.status-badge.error {
  color: var(--down);
}

.chart-container {
  height: 460px;
}

.table-panel h3 {
  margin: 0 0 14px;
}

.table-wrap {
  overflow: auto;
}

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

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  font-size: 13px;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  color: var(--muted);
  font-weight: 500;
}

@media (max-width: 1100px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    max-height: 320px;
  }

  .summary-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .main-header {
    flex-direction: column;
  }
}
