:root {
  --bg-primary: #131722;
  --bg-secondary: #1e222d;
  --bg-tertiary: #2a2e39;
  --bg-hover: #222838;
  --border: #2a3142;
  --text-primary: #e8eaed;
  --text-secondary: #8b93a7;
  --text-muted: #5c6370;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --green: #26a69a;
  --green-bg: rgba(38, 166, 154, 0.15);
  --red: #ef5350;
  --red-bg: rgba(239, 83, 80, 0.15);
  --radius: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'JetBrains Mono', monospace;
}

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

html { font-size: 14px; }

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }

.app { display: flex; flex-direction: column; min-height: 100vh; }

.header {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header__brand { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
.header__logo { width: 28px; height: 28px; color: var(--accent); }
.header__title { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.02em; }

.header__search { flex: 1; max-width: 400px; position: relative; }

.header__search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.header__search-input {
  width: 100%;
  padding: 0.5rem 0.75rem 0.5rem 2.25rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}

.header__search-input:focus { border-color: var(--accent); }
.header__search-input::placeholder { color: var(--text-muted); }

.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 320px;
  overflow-y: auto;
  z-index: 200;
}

.search-results__item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  transition: background 0.1s;
}

.search-results__item:hover { background: var(--bg-hover); }
.search-results__item img { width: 20px; height: 20px; border-radius: 50%; }
.search-results__name { flex: 1; font-size: 0.9rem; }
.search-results__symbol { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; }

.header__status { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; flex-shrink: 0; }
.header__updated { font-size: 0.8rem; color: var(--text-muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.4rem 0.75rem;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  background: transparent;
  color: var(--text-secondary);
}

.btn--ghost { padding: 0.4rem; }
.btn--ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-hover); }
.btn--tab { padding: 0.35rem 0.7rem; border-radius: 6px; font-size: 0.8rem; }
.btn--tab:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn--tab.active { background: var(--accent); color: #fff; }

.main { display: flex; flex: 1; overflow: hidden; }

.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar__header { padding: 1rem 1rem 0.5rem; }
.sidebar__title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.coin-list { list-style: none; overflow-y: auto; flex: 1; padding: 0.25rem 0.5rem 0.5rem; }
.coin-list__loading { padding: 1rem; color: var(--text-muted); font-size: 0.85rem; }

.coin-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.6rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.1s;
}

.coin-item:hover { background: var(--bg-hover); }
.coin-item.active { background: var(--bg-tertiary); border: 1px solid var(--border); }
.coin-item__rank { font-size: 0.75rem; color: var(--text-muted); width: 1.2rem; text-align: center; flex-shrink: 0; }
.coin-item__icon { width: 24px; height: 24px; border-radius: 50%; flex-shrink: 0; }
.coin-item__icon--placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-hover);
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-muted);
}
.coin-item__info { flex: 1; min-width: 0; }
.coin-item__name { font-size: 0.85rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.coin-item__symbol { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; }
.coin-item__price-col { text-align: right; flex-shrink: 0; }
.coin-item__price { font-family: var(--mono); font-size: 0.8rem; }
.coin-item__change { font-family: var(--mono); font-size: 0.7rem; }
.coin-item__change.positive { color: var(--green); }
.coin-item__change.negative { color: var(--red); }

.chart-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

.coin-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.5rem;
}

.coin-header__info { display: flex; align-items: center; gap: 0.75rem; }
.coin-header__icon { width: 40px; height: 40px; border-radius: 50%; }
.coin-header__name { font-size: 1.25rem; font-weight: 700; }
.coin-header__symbol { font-size: 0.85rem; color: var(--text-muted); text-transform: uppercase; }
.coin-header__price { display: flex; align-items: baseline; gap: 0.75rem; }
.coin-header__current { font-family: var(--mono); font-size: 1.75rem; font-weight: 600; }
.coin-header__change { font-family: var(--mono); font-size: 0.95rem; padding: 0.2rem 0.5rem; border-radius: 6px; }
.coin-header__change.positive { color: var(--green); background: var(--green-bg); }
.coin-header__change.negative { color: var(--red); background: var(--red-bg); }
.coin-header__stats { display: flex; gap: 2rem; margin-left: auto; }
.stat { display: flex; flex-direction: column; gap: 0.15rem; }
.stat__label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat__value { font-family: var(--mono); font-size: 0.85rem; }

.chart-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
  flex-wrap: wrap;
}

.chart-controls__type,
.chart-controls__range,
.chart-controls__tools {
  display: flex;
  gap: 0.25rem;
  background: var(--bg-tertiary);
  padding: 0.2rem;
  border-radius: var(--radius);
  align-items: center;
}

.chart-controls__range {
  flex-wrap: wrap;
}

.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: 0.5rem;
  padding: 0.2rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--green);
  letter-spacing: 0.05em;
}

.live-indicator__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

.chart-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  min-height: 420px;
  overflow: hidden;
}

.chart-workspace {
  flex: 0 0 auto;
  height: clamp(200px, 30vh, 280px);
  min-height: 200px;
  max-height: 280px;
  display: flex;
  min-width: 0;
  position: relative;
  border-bottom: 1px solid var(--border);
}

.chart-main {
  flex: 1;
  position: relative;
  min-height: 0;
  height: 100%;
}

.drawing-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.4rem;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  z-index: 6;
}

.drawing-toolbar.hidden { display: none; }

.drawing-tool {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.drawing-tool svg {
  width: 16px;
  height: 16px;
  display: block;
}

.drawing-tool:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.drawing-tool.active { background: rgba(41, 98, 255, 0.2); color: #5b9cf6; }
.drawing-tool--clear { margin-top: 0.5rem; color: var(--red); }
.drawing-tool--magnet.active { color: #f0b90b; }

.drawing-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

.drawing-overlay.drawing-overlay--active {
  pointer-events: auto;
  cursor: crosshair;
}

.drawing-overlay.hidden { display: none; }

.chart-area {
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.chart-area--dragging { cursor: grabbing; }
.chart-area--drawing { cursor: crosshair; }

.btn--tool {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  padding: 0.35rem 0.65rem;
}

.indicator-dropdown { position: relative; }

.indicator-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 100;
  min-width: 260px;
  max-height: 420px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  padding: 0.5rem 0;
}

.indicator-menu__search {
  margin: 0 0.5rem 0.5rem;
  padding: 0.45rem 0.6rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.8rem;
}

#indicatorMenuList {
  overflow-y: auto;
  flex: 1;
}

.indicator-menu.hidden { display: none; }

.indicator-menu__empty {
  padding: 1rem 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

.indicator-menu__group { padding: 0.25rem 0; }
.indicator-menu__title {
  padding: 0.35rem 0.75rem;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.indicator-menu__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.indicator-menu__item:hover { background: var(--bg-tertiary); }

.indicator-menu__check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  flex: 1;
}

.indicator-menu__gear {
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem 0.35rem;
  border-radius: 4px;
  font-size: 0.75rem;
  line-height: 1;
}

.indicator-menu__gear:hover {
  background: var(--bg-primary);
  color: var(--text-primary);
}

.indicator-tag__gear,
.indicator-tag__remove {
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  padding: 0;
  font-size: 0.75rem;
  line-height: 1;
  opacity: 0.85;
}

.indicator-tag__gear:hover,
.indicator-tag__remove:hover { opacity: 1; }

.indicator-settings {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.indicator-settings.hidden { display: none; }

.indicator-settings__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.indicator-settings__panel {
  position: relative;
  width: min(360px, calc(100vw - 2rem));
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  padding: 1rem;
}

.indicator-settings__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.indicator-settings__header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.indicator-settings__close {
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  line-height: 1;
}

.indicator-settings__form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.indicator-settings__field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.85rem;
}

.indicator-settings__field span {
  color: var(--text-muted);
  min-width: 100px;
}

.indicator-settings__field input[type="number"] {
  flex: 1;
  max-width: 140px;
  padding: 0.4rem 0.5rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: var(--mono);
  font-size: 0.85rem;
}

.indicator-settings__field input[type="color"] {
  width: 48px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-tertiary);
  cursor: pointer;
}

.indicator-settings__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.active-indicators {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex: 1;
  min-width: 120px;
}

.indicator-section {
  flex: 1;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  overflow: hidden;
}

.indicator-overview {
  flex-shrink: 0;
  padding: 0.55rem 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.indicator-overview.hidden { display: none; }

.indicator-overview__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.45rem;
}

.indicator-overview__count {
  color: #5b9cf6;
  font-family: var(--mono);
}

.indicator-overview__groups {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1.5rem;
}

.indicator-overview__group-title {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.indicator-overview__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.indicator-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 5px;
}

.indicator-tag__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.indicator-tag__name {
  font-family: var(--mono);
  font-size: 0.72rem;
}

.indicator-tag button {
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  padding: 0;
  font-size: 0.85rem;
  line-height: 1;
}

.indicator-tag .indicator-tag__gear,
.indicator-tag .indicator-tag__remove {
  font-size: 0.75rem;
}

.indicator-panes {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  border-top: none;
}

.indicator-pane {
  position: relative;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
}

.indicator-pane__label {
  position: absolute;
  left: 10px;
  top: 6px;
  z-index: 2;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-primary);
  background: rgba(19, 23, 34, 0.85);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  pointer-events: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.6rem;
  max-width: calc(100% - 20px);
}

.indicator-pane__values {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.55rem;
  font-weight: 500;
  font-size: 0.68rem;
}

.indicator-pane--macd .indicator-pane__label {
  font-size: 0.68rem;
}

.indicator-pane__chart { width: 100%; height: 88px; }

.go-realtime-btn {
  position: absolute;
  bottom: 2.5rem;
  right: 5rem;
  z-index: 10;
  padding: 0.45rem 0.85rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  transition: background 0.15s, transform 0.15s;
}
.go-realtime-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.chart-loading,
.chart-error {
  pointer-events: none;
}
.chart-error .btn { pointer-events: auto; }

.chart-loading,
.chart-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: var(--bg-primary);
  color: var(--text-muted);
  font-size: 0.9rem;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.price-flash-up {
  animation: flashUp 0.6s ease;
}
.price-flash-down {
  animation: flashDown 0.6s ease;
}

@keyframes flashUp {
  0% { color: #fff; }
  30% { color: var(--green); }
  100% { color: inherit; }
}

@keyframes flashDown {
  0% { color: #fff; }
  30% { color: var(--red); }
  100% { color: inherit; }
}

.chart-live-ohlc {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 4;
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 0.85rem;
  padding: 0.35rem 0.55rem;
  border-radius: var(--radius);
  background: rgba(19, 23, 34, 0.82);
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  pointer-events: none;
  user-select: none;
  backdrop-filter: blur(4px);
}

.chart-live-ohlc b {
  color: var(--text-primary);
  font-weight: 600;
}

.chart-live-ohlc--up b,
.chart-live-ohlc--up .chart-live-ohlc__chg {
  color: var(--green);
}

.chart-live-ohlc--down b,
.chart-live-ohlc--down .chart-live-ohlc__chg {
  color: var(--red);
}

.chart-live-ohlc__chg {
  font-weight: 600;
}

.chart-data-source {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 4;
  padding: 0.2rem 0.45rem;
  border-radius: var(--radius);
  background: rgba(19, 23, 34, 0.72);
  border: 1px solid var(--border);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  pointer-events: none;
  user-select: none;
}

/* Binance position-projection style labels on held-position dashed lines */
.chart-position-labels {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  display: none;
}

.pos-projection-label {
  position: absolute;
  left: 4px;
  transform: translate(0, -50%);
  z-index: 2;
  padding: 0.15rem 0.45rem;
  border-radius: 3px;
  border: 1px dashed;
  background: rgba(19, 23, 34, 0.92);
  font-size: 0.68rem;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: 0.01em;
  user-select: none;
}

.pos-projection-lines {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: visible;
  pointer-events: none;
}

.pos-projection-line {
  shape-rendering: crispEdges;
}

.pos-projection-label--tp {
  color: #26a69a;
  border-color: #26a69a;
}

.pos-projection-label--sl {
  color: #ef5350;
  border-color: #ef5350;
}

.pos-projection-label--entry {
  color: #2962ff;
  border-color: #2962ff;
}

.pos-projection-label--entry.pos-projection-label--short {
  color: #f7931a;
  border-color: #f7931a;
}

.pos-projection-hit {
  position: absolute;
  left: 0;
  height: 16px;
  transform: translateY(-50%);
  cursor: ns-resize;
  pointer-events: auto;
  z-index: 1;
  background: transparent;
}

.pos-projection-label[data-drag-role] {
  cursor: ns-resize;
}

body.pos-sl-tp-dragging {
  cursor: ns-resize !important;
  user-select: none;
}

body.pos-sl-tp-dragging .chart-main {
  cursor: ns-resize !important;
}

.footer {
  padding: 0.75rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  text-align: center;
}

.footer p { font-size: 0.75rem; color: var(--text-muted); }

.footer__biz {
  margin-top: 0.45rem;
  line-height: 1.55;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.footer__biz a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ── AI Assistant Panel ─────────────────────────────────────── */
.ai-toggle-btn--active { color: var(--accent) !important; background: rgba(59, 130, 246, 0.15) !important; }

.ai-panel {
  width: 0;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-left: 1px solid transparent;
  transition: width 0.25s ease, min-width 0.25s ease;
}

.ai-panel--open {
  width: 360px;
  min-width: 360px;
  border-left-color: var(--border);
}

.ai-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.ai-panel__title-wrap { display: flex; align-items: center; gap: 0.5rem; }
.ai-panel__title { font-size: 0.9rem; font-weight: 600; }
.ai-panel__badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: rgba(240, 185, 11, 0.15);
  color: #f0b90b;
}

.ai-panel__close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
}
.ai-panel__close:hover { color: var(--text-primary); background: var(--bg-hover); }

.ai-panel__messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-height: 0;
}

.ai-msg {
  max-width: 95%;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  font-size: 0.8rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-msg--user {
  align-self: flex-end;
  background: rgba(59, 130, 246, 0.2);
  color: var(--text-primary);
  border-bottom-right-radius: 3px;
}

.ai-msg--assistant {
  align-self: flex-start;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-bottom-left-radius: 3px;
}

.ai-msg--thinking { opacity: 0.6; font-style: italic; }

.ai-panel__quick {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.ai-quick-btn {
  font-size: 0.68rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.ai-quick-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.ai-panel__input {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.65rem 0.75rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.ai-panel__text {
  flex: 1;
  min-width: 0;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 0.45rem 0.65rem;
  font-size: 0.8rem;
  font-family: var(--font);
}
.ai-panel__text:focus { outline: none; border-color: var(--accent); }

.ai-voice-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-primary);
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}
.ai-voice-btn:hover { background: var(--bg-hover); }
.ai-voice--active { border-color: var(--red); background: var(--red-bg); animation: ai-pulse 1s infinite; }

@keyframes ai-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.ai-send-btn { flex-shrink: 0; padding: 0.4rem 0.85rem !important; font-size: 0.78rem !important; }

@media (max-width: 900px) {
  .main { flex-direction: column; }
  .ai-panel--open {
    width: 100%;
    min-width: 100%;
    max-height: 45vh;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .sidebar { width: 100%; max-height: 200px; border-right: none; border-bottom: 1px solid var(--border); }
  .coin-header__stats { margin-left: 0; width: 100%; flex-wrap: wrap; gap: 1rem; }
  .header { flex-wrap: wrap; }
  .header__search { order: 3; max-width: 100%; width: 100%; }
}

@media (max-width: 600px) {
  .coin-header__current { font-size: 1.35rem; }
  .chart-controls { flex-direction: column; align-items: stretch; }
  .chart-controls__type, .chart-controls__range, .chart-controls__tools { justify-content: center; }
}

/* ── Trading page ─────────────────────────────────────────── */

.header__brand-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: inherit;
  text-decoration: none;
}
.header__brand-link:hover { text-decoration: none; }

.header__plan-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.2;
  color: #ddd6fe;
  background: rgba(167, 139, 250, 0.18);
  border: 1px solid rgba(167, 139, 250, 0.45);
  text-transform: uppercase;
}
.header__plan-badge.hidden { display: none; }

/* Shared notice / confirm modal */
.ui-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 1.25rem;
}
.ui-modal.hidden { display: none; }
.ui-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 8, 14, 0.62);
  backdrop-filter: blur(2px);
}
.ui-modal__panel {
  position: relative;
  width: min(420px, 100%);
  background: var(--bg-secondary, #121826);
  border: 1px solid var(--border, rgba(148, 163, 184, 0.22));
  border-radius: 14px;
  padding: 1.35rem 1.35rem 1.15rem;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
}
.ui-modal__title {
  margin: 0 0 0.55rem;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.ui-modal__body {
  margin: 0 0 1.15rem;
  color: var(--text-secondary, #94a3b8);
  font-size: 0.92rem;
  line-height: 1.55;
  white-space: pre-line;
}
.ui-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.ui-modal__btn { min-width: 5.5rem; }
.ui-modal__btn--danger {
  background: #dc2626 !important;
  border-color: transparent !important;
}
body.ui-modal-open { overflow: hidden; }

.trading-page--guest .bot-control-panel .control-section--primary,
.trading-page--guest .control-accordions > details:not(#authSection),
.trading-page--guest .chart-ai-panel,
.trading-page--guest #backtestPopup,
.trading-page--guest #backtestToggleBtn {
  opacity: 0.45;
  filter: grayscale(0.2);
}
.trading-page--guest #authSection {
  outline: 1px solid rgba(59, 130, 246, 0.35);
  border-radius: var(--radius);
}

.ai-toggle-btn--locked {
  opacity: 0.55;
}
.chart-page--guest #aiPanel {
  opacity: 0.5;
  pointer-events: none;
}

.header__nav {
  display: flex;
  gap: 0.25rem;
  margin-left: 1rem;
}

.header__nav-link {
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.header__nav-link:hover { background: var(--bg-hover); color: var(--text-primary); text-decoration: none; }
.header__nav-link--active { background: var(--bg-tertiary); color: var(--accent); }

.header__price {
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}

.paper-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: var(--green-bg);
  color: var(--green);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.trading-main {
  display: grid;
  grid-template-columns: 260px 1fr 280px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.trading-panel {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.trading-panel--status { border-right: none; border-left: 1px solid var(--border); }

.trading-panel__title {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.trading-panel__subtitle {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

.form-group { display: flex; flex-direction: column; gap: 0.3rem; flex: 1; }
.form-group label { font-size: 0.8rem; color: var(--text-secondary); }
.form-group input[type="number"] {
  padding: 0.45rem 0.6rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--mono);
  font-size: 0.85rem;
  outline: none;
}
.form-group input[type="number"]:focus { border-color: var(--accent); }
.form-group input[type="number"]:disabled,
.form-group input[type="number"].input--disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.form-group select {
  padding: 0.45rem 0.6rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.85rem;
  outline: none;
}
.form-group select:focus { border-color: var(--accent); }
.form-group select:disabled,
.form-group select.input--disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.form-group--check label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; font-size: 0.85rem; }

.form-row { display: flex; gap: 0.5rem; }

.trading-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.25rem 0;
}

.trading-actions { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.25rem; }
.bot-interval-picker {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.35rem;
}
.bot-interval-picker__label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.bot-interval-picker__buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.bot-interval-picker__buttons .btn--tab {
  flex: 1 1 calc(25% - 0.35rem);
  min-width: 2.6rem;
  padding: 0.38rem 0.2rem;
  font-size: 0.75rem;
  text-align: center;
}
.trading-actions--manual { flex-direction: row; }
.trading-actions--manual .btn { flex: 1; }
.btn--short { background: var(--red); color: #fff; }
.btn--short:hover { filter: brightness(1.08); }
.btn--block { width: 100%; }

.trading-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-top: auto;
}
.trading-hint code {
  font-family: var(--mono);
  background: var(--bg-tertiary);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
}

.trading-center {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--bg-primary);
}

.trading-page .chart-panel--embedded {
  flex: 1;
  min-width: 0;
  border: none;
}

.trading-page .coin-header--compact {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
}

.trading-page .coin-header--compact .coin-header__stats {
  gap: 0.75rem;
}

.trading-page .chart-container {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.trading-page .chart-workspace {
  flex: 1;
  min-height: 280px;
}

.trading-page .chart-main {
  min-height: 280px;
}

.trading-page .chart-area {
  min-height: 280px;
}

.trading-indicators--inline {
  display: flex;
  gap: 1rem;
  font-size: 0.8rem;
  border: none;
  padding: 0;
  background: none;
}

.trading-chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.trading-signal { font-size: 0.85rem; color: var(--text-secondary); margin: 0; }

.trading-indicators {
  display: flex;
  gap: 1.5rem;
  padding: 0.5rem 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.trading-indicators strong { color: var(--text-primary); font-family: var(--mono); }

.status-card, .position-card {
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  padding: 0.75rem;
}

.status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  padding: 0.3rem 0;
  color: var(--text-secondary);
}
.status-row strong { font-family: var(--mono); color: var(--text-primary); }

.bot-status {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
}
.bot-status--on { background: var(--green-bg); color: var(--green); }
.bot-status--off { background: var(--bg-hover); color: var(--text-muted); }

.position-card__info { font-size: 0.85rem; line-height: 1.6; }
.position-card__pnl { font-family: var(--mono); font-size: 1rem; font-weight: 600; margin-top: 0.5rem; }

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

.trade-log {
  flex: 1;
  min-height: 120px;
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-family: var(--mono);
}

.trade-log__item {
  padding: 0.35rem 0.5rem;
  background: var(--bg-tertiary);
  border-radius: 4px;
  line-height: 1.4;
  color: var(--text-secondary);
}
.trade-log__item--win { border-left: 3px solid var(--green); }
.trade-log__item--loss { border-left: 3px solid var(--red); }
.trade-log__item--info { border-left: 3px solid var(--accent); }

.footer__warn { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.25rem; }

.api-hint { font-size: 0.75rem; color: var(--text-muted); line-height: 1.5; }
.api-hint a { color: var(--accent); }

.api-status {
  font-size: 0.75rem;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius);
  font-weight: 500;
}
.api-status--offline { background: var(--red-bg); color: var(--red); }
.api-status--online { background: rgba(59, 130, 246, 0.15); color: var(--accent); }
.api-status--connected { background: var(--green-bg); color: var(--green); }

.strategy-ai-status {
  font-size: 0.75rem;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
}
.strategy-ai-status--checking { background: var(--bg-tertiary); color: var(--text-muted); }
.strategy-ai-status--ready { background: var(--green-bg); color: var(--green); }
.strategy-ai-status--offline { background: var(--red-bg); color: var(--red); }

.strategy-ai-messages {
  max-height: 140px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
  padding: 0.35rem;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.strategy-ai-messages .ai-msg {
  font-size: 0.72rem;
  line-height: 1.45;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  max-width: 100%;
  word-break: break-word;
}

.strategy-ai-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

/* ── 진입 조건 슬롯 패널 ─────────────────────────────────────── */
.strategy-slots {
  margin: 0.6rem 0;
}

.strategy-slots__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.strategy-slots__title {
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0;
  color: var(--text-primary);
}

.strategy-slots__list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.strategy-slot {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
}

.strategy-slot--off {
  opacity: 0.55;
}

.strategy-slot__toggle {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  cursor: pointer;
}

.strategy-slot__name {
  width: 92px;
  flex-shrink: 0;
  padding: 0.2rem 0.35rem;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--text-primary);
  font-size: 0.8rem;
  font-weight: 600;
}

.strategy-slot__name:hover,
.strategy-slot__name:focus {
  border-color: var(--border);
  background: var(--bg-secondary);
  outline: none;
}

.strategy-slot__summary {
  flex: 1;
  min-width: 0;
  font-size: 0.72rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.strategy-slot__delete {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0.15rem 0.3rem;
  border-radius: 4px;
}

.strategy-slot__delete:hover {
  color: var(--red, #ef5350);
  background: var(--bg-secondary);
}

.strategy-slot-empty {
  font-size: 0.75rem;
  color: var(--text-secondary);
  padding: 0.4rem 0.2rem;
}

.strategy-ai-target {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.strategy-ai-target select {
  flex: 1;
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.78rem;
}

.strategy-ai-input {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.strategy-ai-text {
  width: 100%;
  resize: vertical;
  min-height: 52px;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.8rem;
  line-height: 1.4;
}
.strategy-ai-text:focus {
  outline: none;
  border-color: var(--accent);
}

.strategy-ai-details {
  display: grid;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
  padding: 0.45rem 0.55rem;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.72rem;
}

.strategy-ai-detail-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  color: var(--text-secondary);
}
.strategy-ai-detail-row strong {
  color: var(--text-primary);
  font-family: var(--mono);
  font-size: 0.68rem;
  text-align: right;
  word-break: break-all;
}

.strategy-ai-note {
  font-size: 0.72rem;
  line-height: 1.45;
  margin: 0 0 0.5rem;
  padding: 0.4rem 0.5rem;
  border-radius: var(--radius);
}
.strategy-ai-note--ok { background: var(--green-bg); color: var(--green); }
.strategy-ai-note--warn { background: rgba(245, 158, 11, 0.12); color: #f59e0b; }
.strategy-ai-note--muted { background: var(--bg-tertiary); color: var(--text-muted); }

.strategy-ai-actions {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.strategy-ai-key-group.strategy-ai-key--saved input[type="password"] {
  border-color: var(--green);
  opacity: 0.85;
}

.testnet-badge { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }

.form-group input[type="text"],
.form-group input[type="password"] {
  padding: 0.45rem 0.6rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--mono);
  font-size: 0.85rem;
  outline: none;
  width: 100%;
}
.form-group input[type="text"]:focus,
.form-group input[type="password"]:focus { border-color: var(--accent); }

.backtest-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  padding: 0.5rem 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--bg-secondary);
}

.backtest-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  user-select: none;
}

.backtest-count-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: default;
  user-select: none;
}

.backtest-count-input {
  width: 4.25rem;
  padding: 0.2rem 0.35rem;
  font-size: 0.75rem;
  font-family: var(--mono);
  color: var(--text-primary);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.backtest-count-input:focus {
  outline: none;
  border-color: var(--accent);
}

.btn--sm {
  padding: 0.25rem 0.65rem;
  font-size: 0.75rem;
}

.backtest-stats {
  flex: 1;
  min-width: 12rem;
}

.backtest-stats strong, .backtest-stats .positive, .backtest-stats .negative {
  font-family: var(--mono);
  font-weight: 600;
}

.backtest-legend {
  display: flex;
  gap: 0.75rem;
  margin-left: auto;
}

.legend-item { font-size: 0.75rem; }
.legend-item--long { color: var(--green); }
.legend-item--short { color: var(--red); }
.legend-item--close { color: var(--text-muted); }
.legend-item--high { color: #ef5350; }
.legend-item--low { color: #26a69a; }
.legend-item--stop { color: #ff9800; }
.legend-item--bt-sl { color: #ef5350; }
.legend-item--bt-tp { color: #26a69a; }

.indicator-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.ind-toggle {
  flex: 1;
  min-width: 4.5rem;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.ind-toggle--on {
  background: rgba(59, 130, 246, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

.ind-toggle--unused {
  opacity: 0.65;
  border-style: dashed;
}

.ind-toggle:hover {
  border-color: var(--accent);
}

@media (max-width: 1100px) {
  .trading-main { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  .trading-panel { border: none; border-bottom: 1px solid var(--border); max-height: none; }
  .trading-panel--status { border-left: none; }
  .futures-chart { min-height: 350px; }
}

@media (max-width: 600px) {
  .header__nav { display: none; }
  .trading-chart-header { flex-direction: column; align-items: flex-start; }
}

