:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text-secondary: #7d8590;
  --accent: #4cc9f0;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  overflow: hidden;
}

/* ---- Header ---- */
.header {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  z-index: 10;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  font-weight: 700;
  font-size: 16px;
}

.header-logo svg { stroke: var(--accent); }

.header-title { font-size: 16px; font-weight: 700; }

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ws-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.ws-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-secondary);
}

.ws-dot.connected { background: var(--green); }
.ws-dot.disconnected { background: var(--red); }

.btn-logout {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
  transition: color 0.15s, border-color 0.15s;
}
.btn-logout:hover { color: var(--text); border-color: var(--text-secondary); }

/* ---- Layout ---- */
.layout {
  display: flex;
  flex-direction: row;
  height: calc(100vh - 56px - 32px);
  overflow: hidden;
}

/* ---- Sidebar ---- */
.bot-sidebar {
  width: 220px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

.bot-list {
  flex-grow: 1;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bot-item {
  padding: 10px 12px;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  border-left: 3px solid transparent;
  transition: background 0.15s;
}

.bot-item:hover { background: var(--surface2); }
.bot-item.active { background: var(--surface2); }

.bot-item-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.bot-item-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.bot-item-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bot-item-status {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 1px;
}

.bot-item-status.running { color: var(--green); }
.bot-item-status.stopped { color: var(--text-secondary); }

.bot-item-balance {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.bot-item-edit {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s;
  flex-shrink: 0;
}
.bot-item:hover .bot-item-edit { opacity: 1; }
.bot-item-edit:hover { color: var(--accent); background: var(--surface2); }

.btn-add-bot {
  margin: 8px;
  padding: 8px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
  text-align: center;
  transition: color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.btn-add-bot:hover { color: var(--accent); border-color: var(--accent); }

/* ---- Main area ---- */
.main-area {
  flex-grow: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.no-bot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 16px;
  color: var(--text-secondary);
  font-size: 15px;
  height: 100%;
}

/* ---- Bot Header ---- */
.bot-header {
  padding: 12px 16px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.bot-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.bot-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.bot-title {
  font-weight: 700;
  font-size: 15px;
}

.symbol-badge, .timeframe-badge {
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--surface2);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.bot-header-center {
  display: flex;
  align-items: center;
  gap: 6px;
}

.price-label { font-size: 11px; color: var(--text-secondary); }
.price-value { font-size: 15px; font-weight: 600; color: var(--accent); }

.bot-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.mode-badge {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  background: rgba(76, 201, 240, 0.15);
  color: var(--accent);
}

.mode-badge.live {
  background: rgba(248, 81, 73, 0.15);
  color: var(--red);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-secondary);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.dot.running { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot.stopped { background: var(--text-secondary); }

.btn-start, .btn-stop {
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-start { background: var(--green); color: #0d1117; }
.btn-stop { background: var(--red); color: #fff; }
.btn-start:hover, .btn-stop:hover { opacity: 0.8; }

/* ---- Content Tabs ---- */
.content-tabs {
  display: flex;
  flex-direction: row;
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  gap: 0;
  overflow-x: auto;
  flex-shrink: 0;
  background: var(--surface);
}

.tab-btn {
  padding: 10px 16px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  font-size: 13px;
  transition: color 0.15s;
}

.tab-btn svg { stroke: currentColor; fill: none; flex-shrink: 0; }
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---- Tab Panes ---- */
.tab-pane { display: none; padding: 16px; }
.tab-pane.active { display: block; }

/* ---- Cards ---- */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }

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

.card-label {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.card-value {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 4px;
}

.card-sub {
  font-size: 12px;
  color: var(--text-secondary);
}

.cards-3 {
  grid-template-columns: repeat(3, 1fr);
}

.card-breakdown {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
}

.breakdown-item {
  white-space: nowrap;
}

@media (max-width: 600px) {
  .cards-3 { grid-template-columns: 1fr; }
  .card-breakdown { flex-direction: column; gap: 4px; }
}

/* ---- Indicator Card ---- */
.indicator-card .card-value { font-size: 18px; }

/* ---- Gauge ---- */
.indicator-gauge { margin: 8px 0; }

.gauge-bar {
  position: relative;
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: visible;
}

.gauge-fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
  transition: width 0.3s;
}

.gauge-marker {
  position: absolute;
  top: -3px;
  width: 12px;
  height: 12px;
  background: var(--accent);
  border-radius: 50%;
  transform: translateX(-50%);
  transition: left 0.3s;
}

.gauge-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ---- Signal Badge ---- */
.signal-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 700;
  background: var(--surface2);
  color: var(--text-secondary);
  margin-top: 6px;
}

.signal-badge.BUY { background: rgba(63,185,80,0.2); color: var(--green); }
.signal-badge.SELL { background: rgba(248,81,73,0.2); color: var(--red); }
.signal-badge.HOLD { background: var(--surface2); color: var(--text-secondary); }

/* ---- Section Header ---- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-header h2 { font-size: 14px; font-weight: 600; }

.info-badge {
  font-size: 11px;
  color: var(--yellow);
  padding: 2px 8px;
  background: rgba(210,153,34,0.15);
  border-radius: 4px;
}

/* ---- Buttons ---- */
.btn-primary {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #0d1117;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.85; }

.btn-secondary {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: color 0.15s;
}
.btn-secondary:hover { color: var(--text); }

.btn-manual-buy {
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  background: rgba(63,185,80,0.2);
  color: var(--green);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-manual-buy:hover { background: rgba(63,185,80,0.35); }

.btn-manual-sell {
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  background: rgba(248,81,73,0.2);
  color: var(--red);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-manual-sell:hover { background: rgba(248,81,73,0.35); }

/* ---- Tables ---- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  padding: 10px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  white-space: nowrap;
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface2); }

.empty-row {
  text-align: center;
  color: var(--text-secondary);
  padding: 24px !important;
}

.pnl-pos { color: var(--green); }
.pnl-neg { color: var(--red); }

.status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.status-pill.open { background: rgba(76,201,240,0.15); color: var(--accent); }
.status-pill.closed { background: var(--surface2); color: var(--text-secondary); }
.status-pill.tp { background: rgba(63,185,80,0.15); color: var(--green); }
.status-pill.sl { background: rgba(248,81,73,0.15); color: var(--red); }

/* ---- Pagination ---- */
.pagination {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  justify-content: center;
}

.page-btn {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
  transition: background 0.15s;
}
.page-btn:hover { background: var(--surface2); }
.page-btn.active { background: var(--accent); color: #0d1117; border-color: var(--accent); }

/* ---- Filter Row ---- */
.filter-row {
  display: flex;
  gap: 6px;
}

.filter-btn {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
  transition: background 0.15s, color 0.15s;
}
.filter-btn.active { background: var(--surface2); color: var(--text); border-color: var(--text-secondary); }
.filter-btn:hover { background: var(--surface2); }

/* ---- Chart ---- */
.chart-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.chart-symbol {
  font-size: 14px;
  font-weight: 700;
}

.chart-timeframe {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 2px 8px;
  background: var(--surface2);
  border-radius: 4px;
}

.chart-main {
  width: 100%;
  height: 340px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.chart-indicator {
  width: 100%;
  height: 120px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.chart-panel-label {
  font-size: 11px;
  color: var(--text-secondary);
  margin: 8px 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ind-value {
  color: var(--accent);
  font-weight: 600;
}

/* ---- Settings ---- */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 16px;
}

.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

.settings-section h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  gap: 8px;
}

.form-row label:first-child {
  font-size: 13px;
  color: var(--text-secondary);
  flex: 1;
}

.form-row input[type="text"],
.form-row input[type="number"],
.form-row select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 13px;
  padding: 5px 8px;
  width: 120px;
  outline: none;
  transition: border-color 0.15s;
}

.form-row input:focus,
.form-row select:focus { border-color: var(--accent); }

/* ---- Toggle ---- */
.toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  cursor: pointer;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  inset: 0;
  background: var(--surface2);
  border-radius: 22px;
  border: 1px solid var(--border);
  transition: background 0.2s;
}

.slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  top: 2px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}

.toggle input:checked + .slider { background: rgba(76,201,240,0.2); border-color: var(--accent); }
.toggle input:checked + .slider::before { transform: translateX(18px); background: var(--accent); }

/* ---- Form Actions ---- */
.form-actions { margin-top: 4px; }

.settings-msg {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
}
.settings-msg.success { background: rgba(63,185,80,0.15); color: var(--green); border: 1px solid var(--green); }
.settings-msg.error { background: rgba(248,81,73,0.15); color: var(--red); border: 1px solid var(--red); }

/* ---- Logs ---- */
#logs-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  max-height: 500px;
  overflow-y: auto;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 12px;
}

.log-entry {
  padding: 3px 0;
  border-bottom: 1px solid rgba(48,54,61,0.4);
  line-height: 1.5;
}

.log-entry:last-child { border-bottom: none; }
.log-entry.info { color: var(--text); }
.log-entry.warning { color: var(--yellow); }
.log-entry.error { color: var(--red); }
.log-entry.debug { color: var(--text-secondary); }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 100%;
  max-width: 420px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 15px; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}
.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 20px;
}

.modal-info {
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--surface2);
  border-radius: 6px;
  padding: 10px 12px;
}

.modal-body .form-row {
  padding: 8px 0;
}

.modal-body .form-row label:first-child {
  min-width: 100px;
}

.modal-body input[type="text"],
.modal-body input[type="number"],
.modal-body input[type="color"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 13px;
  padding: 7px 10px;
  flex: 1;
  outline: none;
  transition: border-color 0.15s;
}

.modal-body input[type="color"] {
  padding: 2px 4px;
  height: 34px;
  width: 60px;
  cursor: pointer;
}

.modal-body input:focus { border-color: var(--accent); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* ---- Statusbar ---- */
.statusbar {
  height: 32px;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  font-size: 12px;
  color: var(--text-secondary);
  flex-shrink: 0;
  overflow: hidden;
}

/* ---- Utility ---- */
.hidden { display: none !important; }

.positive { color: var(--green); }
.negative { color: var(--red); }

/* ---- Mobile ---- */
@media (max-width: 768px) {
  .layout {
    flex-direction: column;
    height: calc(100vh - 56px - 32px);
  }

  .bot-sidebar {
    width: 100%;
    max-height: 60px;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: none;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    padding: 0;
  }

  .bot-list {
    flex-direction: row;
    padding: 0 4px;
    flex-grow: 0;
    gap: 0;
    align-items: center;
  }

  .bot-item {
    flex-shrink: 0;
    border-left: none !important;
    border-bottom: 3px solid transparent;
    border-radius: 0;
    padding: 8px 12px;
    height: 60px;
  }

  .bot-item.active { background: transparent; }

  .bot-item-balance { display: none; }

  .btn-add-bot {
    flex-shrink: 0;
    align-self: center;
    margin: 0 8px;
    white-space: nowrap;
    height: 32px;
  }

  .main-area { flex-grow: 1; overflow-y: auto; }

  .bot-header { flex-wrap: wrap; gap: 8px; }

  .content-tabs { padding: 0 8px; }

  .tab-btn span { display: none; }

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

  .statusbar { font-size: 11px; flex-wrap: wrap; height: auto; padding: 4px 8px; gap: 8px; }

  .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .bot-header-center { display: none; }
  .cards-grid { grid-template-columns: 1fr; }
}
