:root {
  --bg: #f3f5f7;
  --panel: #ffffff;
  --text: #101418;
  --muted: #54606f;
  --line: #d8dde6;
  --accent: #0a7f63;
  --accent-2: #07604b;
  --danger: #b22a2a;
  --overlay: rgba(14, 22, 40, 0.55);
  --toast-shadow: 0 10px 30px rgba(16, 20, 24, 0.18);
  --panel-shadow: 0 5px 15px rgba(22, 44, 70, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "SF Pro Text", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top right, #e9f7f2 0%, transparent 40%),
    radial-gradient(circle at bottom left, #eef3ff 0%, transparent 35%),
    var(--bg);
}

.container {
  width: min(1100px, 100% - 24px);
  margin: 20px auto 40px;
  display: grid;
  gap: 14px;
}

.header h1 {
  margin: 0;
  font-size: 28px;
}

.header {
  position: relative;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.help-btn {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: #10315a;
  border-color: #10315a;
  color: #ffffff;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  padding: 0;
}

.help-btn:hover {
  background: #0a2548;
}

.help-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 14px 30px rgba(13, 24, 44, 0.18);
  z-index: 30;
  padding: 12px;
}

.help-popover.is-hidden {
  display: none;
}

.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.help-head h3 {
  margin: 0;
  font-size: 15px;
}

.help-close-btn {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: #f1f5fc;
  border-color: #d5dfef;
  color: #2f3b4f;
  font-size: 17px;
  line-height: 1;
  padding: 0;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
}

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

.panel h2 {
  margin-top: 0;
}

.user-compact {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.user-main {
  min-width: 280px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  background: linear-gradient(135deg, #1d4ed8, #0f766e);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  background-size: cover;
  background-position: center;
}

.user-avatar.has-photo {
  color: transparent;
}

.user-meta {
  display: grid;
  gap: 4px;
}

.user-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-title-row strong {
  font-size: 14px;
}

.user-id-inline {
  font-size: 12px;
  color: #4e5d71;
}

.user-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  border: 1px solid #d7dfeb;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  color: #415166;
  background: #f7fafd;
  white-space: nowrap;
}

.user-chip-wallet {
  border-color: #c9d9f0;
  background: #f0f6ff;
}

.user-connect {
  display: flex;
  align-items: center;
}

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

label {
  display: grid;
  gap: 6px;
  font-size: 14px;
}

.field-head {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.info-tip {
  position: relative;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 1px solid #c9d5ea;
  background: #f2f6fd;
  color: #355078;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 0;
}

.info-tip:hover {
  background: #e7eefb;
  transform: none;
}

.info-tip::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  min-width: 180px;
  max-width: 220px;
  padding: 8px 9px;
  border-radius: 8px;
  background: #0f213d;
  color: #ffffff;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.35;
  text-align: left;
  box-shadow: 0 8px 20px rgba(7, 18, 35, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease;
  z-index: 35;
}

.info-tip:hover::after,
.info-tip:focus-visible::after,
.info-tip:focus::after {
  opacity: 1;
}

input,
select,
button {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
}

button {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  cursor: pointer;
  transition: transform 0.14s ease, background-color 0.14s ease;
}

button:hover {
  background: var(--accent-2);
  transform: translateY(-1px);
}

.actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  justify-content: flex-start;
  padding-top: 2px;
}

.actions button {
  min-width: 156px;
  font-weight: 600;
}

.btn-save {
  background: #0a7f63;
  border-color: #0a7f63;
}

.btn-save:hover {
  background: #07604b;
}

.btn-reset {
  background: #eef2f8;
  border-color: #cfd8e8;
  color: #31445f;
}

.btn-reset:hover {
  background: #e4ebf6;
}

.btn-analyze {
  background: #2f5eff;
  border-color: #2f5eff;
}

.btn-analyze:hover {
  background: #244bd1;
}

.btn-autopilot-start {
  background: #168f6c;
  border-color: #168f6c;
}

.btn-autopilot-start:hover {
  background: #0f7355;
}

.btn-autopilot-stop {
  background: #c14545;
  border-color: #c14545;
}

.btn-autopilot-stop:hover {
  background: #9f3131;
}

.btn-switching {
  background: #5f6d84;
  border-color: #5f6d84;
}

.btn-busy {
  opacity: 0.86;
}

button:disabled {
  opacity: 0.75;
  cursor: not-allowed;
  transform: none;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
}

.stat-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 20px;
  font-weight: 600;
}

.table-wrap {
  overflow-x: auto;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: 8px;
  font-size: 13px;
}

.feed {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  padding-bottom: 4px;
}

.feed li {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  font-size: 13px;
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 8px;
  background: #edf5f2;
  color: var(--accent-2);
  font-size: 11px;
  margin-right: 6px;
}

.badge.type-buy {
  background: #e8f6f0;
  color: #0a7f63;
}

.badge.type-sell {
  background: #ffeceb;
  color: #b22a2a;
}

.badge.type-other {
  background: #edf1f7;
  color: #445065;
}

.negative {
  color: var(--danger);
}

.positive {
  color: var(--accent-2);
}

.neutral {
  color: #516074;
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.8);
  position: sticky;
  top: 8px;
  z-index: 20;
  backdrop-filter: blur(8px);
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 10px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}

.tab-btn:hover {
  color: var(--text);
  background: #f2f6ff;
}

.tab-btn.is-active {
  background: #102543;
  color: #ffffff;
}

.tab-icon {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.12);
}

.tab-icon-control {
  background: #66d3b6;
}

.tab-icon-dashboard {
  background: #7fa7ff;
}

.tab-icon-activity {
  background: #f4af65;
}

.tab-panel.hidden {
  display: none;
}

.quick-start {
  display: grid;
  gap: 8px;
}

.quick-step {
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: start;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #fbfdff;
}

.quick-step-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: #1d4ed8;
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
}

.quick-step h3 {
  margin: 0 0 4px;
  font-size: 14px;
}

.quick-step p {
  margin: 0;
  color: #4b596d;
  font-size: 13px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 60;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-card {
  width: min(500px, 100%);
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #ffffff;
  box-shadow: 0 20px 50px rgba(9, 20, 38, 0.22);
  overflow: hidden;
}

.modal-card-sm {
  width: min(420px, 100%);
}

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

.modal-head h3 {
  margin: 0;
  font-size: 18px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #f4f7fb;
  border-color: #d4dbe6;
  color: #243043;
  font-size: 20px;
  line-height: 1;
  padding: 0;
}

.modal-body {
  padding: 16px;
  display: grid;
  gap: 10px;
}

.confirm-message {
  margin: 0;
  color: #445164;
  font-size: 14px;
  line-height: 1.4;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.btn-cancel {
  background: #f6f7fa;
  border-color: #d6dbe6;
  color: #334256;
}

.btn-cancel:hover {
  background: #eceff5;
}

.analysis-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.analysis-symbol {
  font-size: 24px;
  font-weight: 700;
}

.analysis-badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.analysis-badge.good {
  background: #e9f8f3;
  color: #0b6e56;
}

.analysis-badge.bad {
  background: #feecec;
  color: #9f1d1d;
}

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.analysis-metric {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.analysis-metric .stat-label {
  margin: 0;
}

.analysis-metric .stat-value {
  font-size: 16px;
  margin-top: 3px;
}

.toast-stack {
  position: fixed;
  right: 12px;
  bottom: 12px;
  display: grid;
  gap: 8px;
  z-index: 80;
  width: min(360px, calc(100% - 24px));
}

.toast {
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #ffffff;
  box-shadow: var(--toast-shadow);
  padding: 10px 12px;
  display: grid;
  gap: 2px;
}

.toast-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
}

.toast-text {
  margin: 0;
  font-size: 13px;
  color: #3c4a5f;
}

.toast.success {
  border-color: #9fd8c9;
}

.toast.success .toast-title {
  color: #0b6e56;
}

.toast.error {
  border-color: #f0b8b8;
}

.toast.error .toast-title {
  color: #9f1d1d;
}

.skeleton {
  position: relative;
  overflow: hidden;
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.65), transparent);
  animation: skeleton-wave 1.4s infinite;
}

.skeleton-block {
  height: 14px;
  border-radius: 8px;
  background: #e8edf5;
}

.skeleton-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.skeleton-line-sm {
  width: 46%;
}

.skeleton-line-lg {
  width: 82%;
}

.skeleton-row td {
  padding: 10px 8px;
}

@keyframes skeleton-wave {
  to {
    transform: translateX(100%);
  }
}

@media (max-width: 700px) {
  .container {
    width: calc(100% - 16px);
    margin-top: 10px;
    margin-bottom: calc(20px + env(safe-area-inset-bottom));
  }

  .panel {
    padding: 12px;
  }

  .tabs {
    top: 4px;
  }

  .user-main {
    min-width: 0;
  }

  .help-popover {
    width: min(360px, calc(100vw - 16px));
    right: 0;
  }

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

  .feed {
    max-height: none;
    overflow: visible;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  .toast-stack {
    bottom: calc(10px + env(safe-area-inset-bottom));
  }
}
