:root {
  --bg: #0a0f1d;
  --bg-elev: #10182b;
  --bg-soft: #141e35;
  --bg-panel: #0f172a;
  --border: #24314f;
  --text: #d8e1ff;
  --muted: #7f8aa8;
  --accent: #4ea1ff;
  --accent-2: #7ee787;
  --danger: #ef5350;
  --warning: #f59e0b;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.35);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 900px at 20% 0%, rgba(78, 161, 255, 0.14), transparent 50%), var(--bg);
}

a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.danger { color: #ff8c8c; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  padding: 0.6rem 0.9rem;
  border-radius: 10px;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.btn:hover { transform: translateY(-1px); border-color: #3f527d; background: rgba(255, 255, 255, 0.06); }
.btn-primary { background: linear-gradient(135deg, #2578ff, #4ea1ff); border-color: #4ea1ff; color: #fff; }
.btn-ghost { background: rgba(255, 255, 255, 0.02); }

.auth-body {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 24px;
}
.auth-shell { width: min(100%, 460px); }
.auth-panel {
  background: rgba(9, 14, 27, 0.82);
  border: 1px solid rgba(84, 104, 149, 0.35);
  border-radius: 22px;
  padding: 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}
.auth-form { display: grid; gap: 12px; margin-top: 18px; }
.auth-form label { font-size: 0.9rem; color: var(--muted); }
.auth-form input {
  width: 100%;
  background: #0d1527;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.9rem 1rem;
  border-radius: 12px;
  outline: none;
}
.auth-form input:focus { border-color: #4ea1ff; box-shadow: 0 0 0 3px rgba(78, 161, 255, 0.12); }
.notice {
  padding: 0.9rem 1rem;
  border-radius: 12px;
  margin-top: 14px;
  border: 1px solid transparent;
}
.notice.success { background: rgba(126, 231, 135, 0.08); border-color: rgba(126, 231, 135, 0.2); color: #d5ffe0; }
.notice.error { background: rgba(239, 83, 80, 0.08); border-color: rgba(239, 83, 80, 0.2); color: #ffd3d1; }

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}
.brand-lockup.compact { min-width: 230px; }
.brand-mark {
  width: 42px; height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #2b7cff, #6cb2ff);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.06em;
  box-shadow: 0 10px 22px rgba(43, 124, 255, 0.28);
}
.brand-title { font-size: 1rem; font-weight: 700; }
.brand-subtitle { font-size: 0.75rem; color: var(--muted); letter-spacing: 0.08em; margin-top: 2px; }

.dashboard-body { overflow: hidden; }
.app-shell {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  height: 100vh;
}
.top-header,
.toolbar-row,
.bottom-bar {
  border-bottom: 1px solid rgba(52, 67, 105, 0.8);
  background: rgba(8, 12, 24, 0.88);
  backdrop-filter: blur(16px);
}
.top-header {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 18px;
  padding: 12px 18px;
}
.search-wrap {
  display: grid;
  grid-template-columns: auto minmax(180px, 280px);
  gap: 10px;
  align-items: center;
  position: relative;
}
.search-wrap input {
  background: #0d1527;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.72rem 0.9rem;
  border-radius: 12px;
  outline: none;
}
.search-wrap input:focus { border-color: #4ea1ff; }
.dropdown-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: min(100%, 420px);
  max-height: 360px;
  overflow: auto;
  background: #0b1224;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  z-index: 35;
}
.dropdown-item {
  padding: 0.9rem 1rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  border-bottom: 1px solid rgba(37, 49, 79, 0.8);
}
.dropdown-item:hover { background: rgba(255,255,255,0.04); }
.dropdown-item strong { font-size: 0.95rem; }
.dropdown-item small { color: var(--muted); }

.header-metrics {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.metric {
  min-width: 120px;
  padding: 0.55rem 0.8rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(37, 49, 79, 0.8);
  border-radius: 12px;
}
.metric span { display: block; font-size: 1rem; font-weight: 700; }
.metric small { color: var(--muted); }
.metric.price span { font-size: 1.18rem; }
.price-flash-up { animation: flashUp 0.72s ease; }
.price-flash-down { animation: flashDown 0.72s ease; }

.toolbar-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
}
.toolbar-group { display: flex; gap: 8px; flex-wrap: wrap; }
.toolbar-group.right { margin-left: auto; }
.toolbar-button,
.timeframe-button,
.charttype-button {
  padding: 0.52rem 0.82rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
}
.toolbar-button.active,
.timeframe-button.active,
.charttype-button.active,
.tool-button.active { border-color: #4ea1ff; background: rgba(78, 161, 255, 0.14); }

.workspace {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 306px;
  min-height: 0;
  height: 100%;
}
.left-toolbox {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 10px;
  border-right: 1px solid rgba(52, 67, 105, 0.8);
  background: rgba(7, 11, 21, 0.92);
}
.tool-button {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
}
.tool-button.danger { color: #ffb4b4; }

.chart-panel {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
}
.chart-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px 10px;
  border-bottom: 1px solid rgba(37, 49, 79, 0.75);
  background: rgba(10, 15, 29, 0.7);
}
.chart-summary {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  color: var(--text);
}
.chart-summary span {
  padding: 0.36rem 0.65rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(37, 49, 79, 0.75);
  font-size: 0.88rem;
}

.chart-stage {
  position: relative;
  min-height: 0;
  height: 100%;
}
.chart-root {
  position: absolute;
  inset: 0;
}
.drawing-layer {
  position: absolute;
  inset: 0;
  pointer-events: auto;
}
.overlay-loader {
  position: absolute;
  inset: auto 18px 18px auto;
  padding: 0.7rem 0.95rem;
  background: rgba(10, 15, 29, 0.92);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 20;
}

.right-panel {
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 12px;
  padding: 12px;
  border-left: 1px solid rgba(52, 67, 105, 0.8);
  background: rgba(7, 11, 21, 0.92);
  overflow: auto;
}
.side-section {
  border: 1px solid rgba(37, 49, 79, 0.85);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.02);
  padding: 12px;
}
.section-title {
  font-size: 0.82rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.list-panel { display: grid; gap: 8px; }
.list-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 0.72rem 0.8rem;
  border: 1px solid rgba(37, 49, 79, 0.8);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
}
.list-row .symbol { font-weight: 700; }
.list-row .price { text-align: right; }
.list-row .change.up { color: #7ee787; }
.list-row .change.down { color: #ff8c8c; }

.system-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.system-grid div {
  padding: 0.72rem 0.8rem;
  border-radius: 12px;
  border: 1px solid rgba(37, 49, 79, 0.8);
  background: rgba(255, 255, 255, 0.02);
}
.system-grid span { display: block; color: var(--muted); font-size: 0.78rem; }
.system-grid strong { display: block; margin-top: 3px; }

.bottom-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  border-top: 1px solid rgba(52, 67, 105, 0.8);
  border-bottom: none;
}
.readout { color: var(--muted); font-size: 0.88rem; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 70;
}
.modal {
  width: min(100%, 980px);
  max-height: 92vh;
  overflow: auto;
  background: #0b1224;
  border: 1px solid rgba(90, 112, 163, 0.35);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.modal.compact { width: min(100%, 620px); }
.modal-header,
.modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid rgba(37, 49, 79, 0.8);
}
.modal-footer { border-top: 1px solid rgba(37, 49, 79, 0.8); border-bottom: none; }
.modal-body { padding: 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field label { color: var(--muted); font-size: 0.82rem; }
.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 0.82rem 0.9rem;
  background: #0d1527;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  outline: none;
}
.field textarea { min-height: 160px; resize: vertical; }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.tab-button { padding: 0.55rem 0.8rem; border-radius: 10px; border: 1px solid var(--border); background: rgba(255,255,255,0.03); color: var(--text); }
.tab-button.active { border-color: #4ea1ff; background: rgba(78,161,255,0.12); }

.toast-stack {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 10px;
  z-index: 90;
}
.toast {
  min-width: 240px;
  max-width: 360px;
  padding: 0.9rem 1rem;
  background: #0b1224;
  border: 1px solid rgba(37, 49, 79, 0.95);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.toast.success { border-color: rgba(126, 231, 135, 0.35); }
.toast.error { border-color: rgba(239, 83, 80, 0.35); }

@keyframes flashUp {
  0% { background-color: rgba(126, 231, 135, 0.0); }
  25% { background-color: rgba(126, 231, 135, 0.15); }
  100% { background-color: rgba(255,255,255,0.03); }
}
@keyframes flashDown {
  0% { background-color: rgba(239, 83, 80, 0.0); }
  25% { background-color: rgba(239, 83, 80, 0.15); }
  100% { background-color: rgba(255,255,255,0.03); }
}

@media (max-width: 1200px) {
  .workspace { grid-template-columns: 64px minmax(0, 1fr); }
  .right-panel { display: none; }
}

@media (max-width: 820px) {
  .top-header { grid-template-columns: 1fr; }
  .search-wrap { grid-template-columns: auto 1fr; }
  .header-metrics { justify-content: flex-start; }
  .workspace { grid-template-columns: 52px minmax(0, 1fr); }
  .left-toolbox { width: 52px; padding: 8px 6px; }
  .tool-button { width: 38px; height: 38px; }
  .toolbar-row { overflow-x: auto; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .bottom-bar { flex-direction: column; align-items: flex-start; }
}
