:root {
  --bg: #eef2f6;
  --bg-image: none;
  --shell: #f8fafc;
  --panel: #ffffff;
  --panel-2: #edf3f7;
  --text: #122029;
  --muted: #667985;
  --line: #d8e1e7;
  --accent: #11b79a;
  --accent-text: #06120f;
  --accent-2: #f2b740;
  --danger: #de4d4f;
  --shadow: 0 12px 32px rgba(18, 32, 41, 0.08);
  --button-shadow: none;
}

[data-theme="dark"] {
  --bg: #101418;
  --bg-image: none;
  --shell: #0d1115;
  --panel: #171d23;
  --panel-2: #202830;
  --text: #eef4f6;
  --muted: #9fb0b8;
  --line: #2b353e;
  --accent-text: #06120f;
  --shadow: none;
  --button-shadow: none;
}

[data-theme="blue"] {
  --bg: #07182f;
  --bg-image:
    linear-gradient(135deg, rgba(10, 35, 72, 0.96) 0%, rgba(7, 24, 47, 0.88) 38%, rgba(12, 43, 81, 0.96) 100%),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  --shell: rgba(8, 26, 50, 0.88);
  --panel: rgba(248, 252, 255, 0.965);
  --panel-2: rgba(225, 236, 247, 0.78);
  --text: #0b2138;
  --muted: #5f7489;
  --line: rgba(122, 158, 191, 0.42);
  --accent: #2e7fe8;
  --accent-text: #ffffff;
  --accent-2: #c99a35;
  --danger: #c6475a;
  --shadow: 0 18px 46px rgba(5, 18, 36, 0.22);
  --button-shadow: 0 10px 22px rgba(46, 127, 232, 0.24);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-image), var(--bg);
  background-size: auto, 34px 34px, 34px 34px;
  color: var(--text);
  font-family: Inter, Segoe UI, Arial, sans-serif;
}
button, input, select {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}
button { cursor: pointer; }
button:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--accent) 42%, var(--line));
  box-shadow: var(--button-shadow);
}
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}
span, p, small { color: var(--muted); }
h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 28px; }
h2 { font-size: 18px; }

.shell { display: grid; grid-template-columns: 270px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--shell);
  border-right: 1px solid var(--line);
  padding: 20px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.brand strong, .brand span { display: block; }
.mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 900;
}
.sync-box {
  display: grid;
  gap: 8px;
  padding: 14px;
  margin-bottom: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
nav { display: grid; gap: 8px; }
.nav-item {
  text-align: left;
  background: transparent;
}
.nav-item.active, .primary {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 800;
  box-shadow: var(--button-shadow);
}
.secondary { background: var(--panel-2); }
.theme-picker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-top: 18px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.theme-choice {
  padding: 8px 6px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.theme-choice.active {
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: var(--button-shadow);
}

[data-theme="blue"] .sidebar,
[data-theme="blue"] .sync-box,
[data-theme="blue"] .status-pill,
[data-theme="blue"] .theme-picker {
  backdrop-filter: blur(14px);
}

[data-theme="blue"] .sidebar {
  color: #ecf6ff;
}

[data-theme="blue"] .brand strong,
[data-theme="blue"] .nav-item {
  color: #eef7ff;
}

[data-theme="blue"] .brand span,
[data-theme="blue"] .sync-box span {
  color: rgba(224, 238, 250, 0.74);
}

[data-theme="blue"] .sync-box,
[data-theme="blue"] .theme-picker {
  background: rgba(243, 249, 255, 0.1);
}

[data-theme="blue"] .nav-item {
  border-color: rgba(180, 210, 239, 0.14);
}

[data-theme="blue"] .nav-item.active {
  background: linear-gradient(135deg, #2e7fe8, #16b5a5);
}

[data-theme="blue"] main {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 220px);
}

[data-theme="blue"] .topbar h1 {
  color: #f6fbff;
}

[data-theme="blue"] .topbar p,
[data-theme="blue"] .freshness,
[data-theme="blue"] .action-stack small {
  color: rgba(225, 239, 252, 0.78);
}

main { padding: 24px; overflow: auto; }
.view { display: none; gap: 18px; }
.view.active { display: grid; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 2px;
}
.topbar p { margin: 6px 0 0; }
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.action-stack {
  display: grid;
  gap: 3px;
  justify-items: stretch;
}
.action-stack small {
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  text-align: center;
}
.status-pill {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.metric, .panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.metric { padding: 16px; }
.metric span { display: block; font-size: 12px; }
.metric strong { display: block; margin-top: 8px; font-size: 22px; }
.metric small, .stat-card small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}
.panel { padding: 16px; min-width: 0; }
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}
.legend { display: flex; flex-wrap: wrap; gap: 8px; }
.legend span {
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  font-size: 12px;
}
.legend i {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 5px;
  border-radius: 50%;
}
.deal, .positive { color: var(--accent); }
.buy-dot { color: var(--accent); }
.sell-dot { color: var(--danger); }
.pending-up, .warning, .warning-text { color: var(--accent-2); }
.shift-up { color: #6f7cff; }
.out-of-grid, .negative { color: var(--danger); }
.deal { background: var(--accent); }
.buy-dot { background: var(--accent); }
.sell-dot { background: var(--danger); }
.pending-up { background: var(--accent-2); }
.shift-up { background: #6f7cff; }
.out-of-grid { background: var(--danger); }
.counting-money-stats, .trade-timeline-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}
.allocation-panel-body {
  display: grid;
  grid-template-columns: minmax(250px, 320px) minmax(0, 1fr);
  align-items: center;
  gap: 22px;
  min-height: 0;
}
.allocation-chart-wrap {
  width: 100%;
  max-width: 320px;
  justify-self: center;
}
.allocation-chart-wrap canvas {
  display: block;
  width: 100%;
  height: 260px;
}
.allocation-legend {
  display: block;
  overflow-x: auto;
  overflow-y: auto;
  max-height: 230px;
  min-width: 0;
  padding-bottom: 4px;
}
.allocation-table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  font-size: 12px;
}
.allocation-table th,
.allocation-table td {
  padding: 6px 5px;
  white-space: nowrap;
}
.allocation-table th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.allocation-table td:first-child {
  font-weight: 800;
  color: var(--text);
}
.allocation-table th:not(:first-child),
.allocation-table td:not(:first-child) {
  text-align: right;
}
.allocation-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 7px;
  border-radius: 999px;
}
.stat-card, .coin-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
}
.stat-card strong, .coin-card strong { display: block; margin-top: 6px; }
.account-assets-table {
  grid-column: 1 / -1;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.account-assets-table table { min-width: 680px; }
.account-assets-table .empty-state { border: 0; }
.profit-withdraw-table-wrap table,
.profit-withdraw-table {
  min-width: 980px;
}
.profit-withdraw-table td {
  vertical-align: middle;
}
.withdraw-time {
  min-width: 145px;
  color: var(--muted);
}
.withdraw-amount {
  font-weight: 800;
  white-space: nowrap;
}
.withdraw-type {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 78px;
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 800;
}
.withdraw-type.auto {
  color: var(--accent);
  background: rgba(17, 183, 154, 0.13);
}
.withdraw-type.manual {
  color: #6f7cff;
  background: rgba(111, 124, 255, 0.13);
}
.withdraw-type.system {
  color: var(--accent-2);
  background: rgba(242, 183, 64, 0.16);
}
.profit-withdraw-total-row td {
  position: sticky;
  bottom: 0;
  border-top: 1px solid var(--line);
  background: var(--panel-2);
  box-shadow: 0 -8px 18px rgba(15, 23, 42, 0.06);
}
.profit-withdraw-total-row span {
  color: var(--muted);
  font-size: 12px;
}
.investment-days-panel,
.daily-attribution-panel {
  margin-top: 20px;
}
.investment-days-wrap,
.daily-attribution-wrap {
  max-height: 620px;
}
.investment-days-table,
.daily-attribution-table {
  min-width: 1120px;
}
.investment-days-table th,
.investment-days-table td,
.daily-attribution-table th,
.daily-attribution-table td {
  white-space: nowrap;
}
.investment-days-table td:first-child,
.investment-days-table th:first-child,
.daily-attribution-table td:first-child,
.daily-attribution-table th:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--panel);
}
.investment-days-detail {
  min-width: 520px;
  white-space: normal;
}
.investment-days-detail span {
  display: block;
  color: var(--muted);
  line-height: 1.45;
}
.investment-days-detail strong {
  color: var(--text);
}
.daily-attribution-table small {
  color: var(--muted);
}
.progress {
  height: 6px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--line);
}
.progress b {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.charts-row, .analytics-grid, .optimizer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.dashboard-portfolio-layout { grid-template-columns: minmax(260px, 1fr); }
.wide { min-width: 0; }
.chart-shell, canvas {
  width: 100%;
  background: linear-gradient(180deg, var(--panel-2), transparent);
  border-radius: 8px;
}
.operation-chart-shell { position: relative; }
.chart-tooltip {
  position: absolute;
  z-index: 5;
  max-width: min(520px, calc(100% - 16px));
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  box-shadow: 0 14px 38px rgba(20, 34, 48, 0.18);
  pointer-events: none;
}
.chart-tooltip strong,
.chart-tooltip span {
  display: block;
}
.chart-tooltip strong {
  color: var(--text);
  font-size: 13px;
}
.chart-tooltip span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}
.chart-tooltip .tooltip-row {
  padding-top: 5px;
  border-top: 1px solid var(--line);
  color: var(--text);
  white-space: normal;
}

.table-tools { align-items: center; flex-wrap: wrap; }
.filter { display: grid; gap: 4px; min-width: 150px; }
.filter.search { min-width: 220px; }
.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}
table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}
th, td {
  padding: 10px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}
th { color: var(--muted); font-weight: 700; background: var(--panel-2); position: sticky; top: 0; }
.bots-table th, .bots-table td { font-size: 13px; }
.bots-table th[data-sort] { cursor: pointer; user-select: none; }
.bots-table th.sorted-asc::after { content: " ↑"; color: var(--accent); }
.bots-table th.sorted-desc::after { content: " ↓"; color: var(--accent); }
.bots-table tr.summary-row td {
  position: sticky;
  top: 37px;
  z-index: 4;
  border-bottom: 2px solid var(--line);
  background: var(--panel-2);
  font-weight: 800;
}
.bots-table tr.summary-row small {
  color: var(--muted);
  font-weight: 700;
}
.bots-table tfoot td {
  border-top: 2px solid var(--line);
  border-bottom: 0;
  background: var(--panel-2);
}
.bots-table tfoot strong { font-size: 14px; }
.equity-pct-filter {
  grid-template-columns: 1fr 72px 72px;
  align-items: end;
}
.range-compact {
  display: grid;
  grid-template-columns: 54px 52px;
  align-items: center;
  gap: 7px;
}
.range-compact .bar {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--line);
}
.range-compact .bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 12px;
  align-items: end;
}
label { display: grid; gap: 6px; color: var(--muted); }
input, select { width: 100%; }
.wide { grid-column: span 2; }
.optimizer-best, .empty-state {
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--panel-2);
}
.optimizer-best pre {
  margin: 0;
  white-space: pre-wrap;
  color: var(--text);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.45);
}
.modal-backdrop.hidden { display: none; }
.modal-card {
  width: min(920px, 100%);
  max-height: 90vh;
  overflow: auto;
  padding: 18px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.transfer-modal-card { width: min(560px, calc(100vw - 24px)); }
.clone-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}
.clone-info {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}
.clone-info strong { color: var(--text); }
.clone-error {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(222, 77, 79, 0.35);
  border-radius: 8px;
  color: var(--danger);
  background: rgba(222, 77, 79, 0.08);
}
.clone-error.hidden { display: none; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}
.pill {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--panel-2);
}
.pill.positive { background: rgba(17, 183, 154, 0.13); }
.pill.warning { background: rgba(242, 183, 64, 0.16); }
.pill.negative { background: rgba(222, 77, 79, 0.13); }
.danger-text { color: var(--danger); }

@media (max-width: 1100px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  nav { grid-template-columns: repeat(4, 1fr); }
  .metrics { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 760px) {
  main { padding: 14px; }
  nav, .topbar, .charts-row, .analytics-grid, .optimizer-grid, .dashboard-portfolio-layout, .form-grid, .metrics {
    grid-template-columns: 1fr;
  }
  .allocation-panel-body { grid-template-columns: 1fr; }
  .allocation-chart-wrap { max-width: 260px; }
  .allocation-chart-wrap canvas { height: 230px; }
  .topbar { display: grid; }
  .wide { grid-column: span 1; }
  .clone-grid { grid-template-columns: 1fr; }
  th, td { white-space: normal; }
}
