:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --card-2: #fafbfc;
  --border: #e6e8ec;
  --text: #1a1d29;
  --text-dim: #6b7280;
  --text-faint: #9aa0ac;
  --blue-light: #5bc0eb;
  --blue-dark: #1b4f8c;
  --teal: #1b5fa8;
  --teal-dim: #1b5fa815;
  --teal-hover: #164d89;
  --red: #e5484d;
  --red-dim: #e5484d17;
  --green: #16a34a;
  --green-dim: #16a34a17;
  --radius: 10px;
  --radius-sm: 8px;
  --font-body: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
}

body { display: flex; min-height: 100vh; }

a { color: inherit; text-decoration: none; }

/* Sidebar */

.sidebar {
  width: 224px;
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 22px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  padding: 4px 10px 26px;
}

.brand-mark {
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-mark img, .brand-mark svg { display: block; height: 24px; width: auto; }

.brand span { color: var(--teal); }

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text-dim);
  font-weight: 500;
}

.nav a svg { flex-shrink: 0; opacity: 0.8; }

.nav a:hover { background: var(--card-2); color: var(--text); }
.nav a.active { background: var(--teal-dim); color: var(--teal); font-weight: 600; }
.nav a.active svg { opacity: 1; }

.nav-group-label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px 3px;
  font-size: 13.5px;
  color: var(--text);
  font-weight: 600;
}

.nav-group-label svg { opacity: 0.8; flex-shrink: 0; }

.nav-sub { display: flex; flex-direction: column; gap: 2px; padding-left: 22px; margin-bottom: 4px; }

.nav-sub a {
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 500;
  border-left: 2px solid var(--border);
  margin-left: 4px;
  padding-left: 12px;
}

.nav-sub a:hover { background: var(--card-2); color: var(--text); }
.nav-sub a.active { color: var(--teal); font-weight: 600; border-left-color: var(--teal); background: var(--teal-dim); }

.sidebar-bottom {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.mode-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 0 8px 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.mode-badge.paper { background: var(--card-2); color: var(--text-faint); border: 1px solid var(--border); }
.mode-badge.live { background: #e5484d17; color: var(--red); border: 1px solid #e5484d40; animation: mode-badge-pulse 2s ease-in-out infinite; }

@keyframes mode-badge-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .6; }
}

.run-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-dim);
  padding: 8px;
  font-weight: 500;
}

.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}

.dot.on { background: var(--teal); box-shadow: 0 0 0 3px var(--teal-dim); }
.dot.off { background: var(--text-faint); }

.run-buttons { display: flex; gap: 6px; padding: 4px 8px 0; }

/* Main */

.main {
  flex: 1;
  padding: 26px 36px 60px;
  max-width: 1120px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 4px;
}

.page-title {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
}

.page-sub {
  font-size: 13px;
  color: var(--text-dim);
  margin: 0 0 26px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 18px 20px;
  overflow-x: auto;
}

/* Icon stat cards (3Commas "Overall stats" pattern) */

.stat-grid, .hero-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  gap: 12px;
  margin-bottom: 26px;
}

.stat-card, .hero-stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 16px 18px;
}

.stat-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--teal-dim);
  color: var(--teal);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.stat-icon.neg { background: var(--red-dim); color: var(--red); }
.stat-icon.pos { background: var(--green-dim); color: var(--green); }

.stat-label {
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  margin-bottom: 5px;
}

.stat-value, .hero-stat-value {
  font-family: var(--font-mono);
  font-size: 19px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.pos { color: var(--green); }
.neg { color: var(--red); }
.stat-value.amber, .hero-stat-value.amber { color: var(--teal); }

.section-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 28px 0 10px;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 28px 0 10px;
}

.section-title-row .section-title { margin: 0; }

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

th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--card-2);
}

th:first-child { border-top-left-radius: 8px; }
th:last-child { border-top-right-radius: 8px; }

td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  color: var(--text);
}

tr:last-child td { border-bottom: none; }
tr.pending td { color: var(--text-faint); }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-body);
}

.badge.filled, .badge.sold, .badge.completed { background: var(--teal-dim); color: var(--teal); }
.badge.pending { background: #eef0f3; color: var(--text-faint); }
.badge.kept { background: #eef0f3; color: var(--text-dim); }

.empty-state {
  color: var(--text-faint);
  font-size: 13px;
  padding: 22px 4px;
  text-align: center;
}

.events-panel {
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column-reverse;
  gap: 2px;
  padding: 2px;
}

.event-row {
  display: flex;
  gap: 10px;
  font-size: 12.5px;
  padding: 7px 10px;
  border-radius: 7px;
}

.event-row:hover { background: var(--card-2); }

.event-time {
  font-family: var(--font-mono);
  color: var(--text-faint);
  flex-shrink: 0;
  width: 58px;
}

.event-msg { color: var(--text-dim); }

/* Buttons */

button, .btn {
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 8px 15px;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}

button:hover { border-color: var(--text-faint); background: var(--card-2); }

button.primary {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

button.primary:hover { background: var(--teal-hover); border-color: var(--teal-hover); }

button.danger { color: var(--red); border-color: var(--red-dim); }
button.danger:hover { border-color: var(--red); background: var(--red-dim); }

button:disabled { opacity: .4; cursor: default; }

/* Forms */

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px 20px;
  margin-bottom: 20px;
}

.field label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
}

.field input:focus {
  outline: none;
  border-color: var(--teal);
  background: var(--card);
}

.field .hint {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 4px;
}

.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 4px; }

.form-msg { font-size: 12.5px; font-weight: 600; }
.form-msg.error { color: var(--red); }
.form-msg.ok { color: var(--teal); }

.tg-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.tg-status-text { font-size: 13px; color: var(--text-dim); }
.tg-status-text b { color: var(--text); font-weight: 700; }

.close-choice {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Filter bar (Closed Trades page) */

.filter-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.filter-bar select {
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 8px 12px;
}

/* Collapsible sections (Edit DCA Bot layout) */

.edit-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 20px;
  align-items: start;
}

.edit-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  margin-bottom: 14px;
  overflow: hidden;
}

.edit-section summary {
  padding: 15px 20px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.edit-section summary::-webkit-details-marker { display: none; }

.edit-section summary::before {
  content: '▸';
  color: var(--text-faint);
  font-size: 11px;
  transition: transform .15s;
}

.edit-section[open] summary::before { transform: rotate(90deg); }

.edit-section summary:hover { background: var(--card-2); }

.edit-section-body {
  padding: 4px 20px 20px;
  border-top: 1px solid var(--border);
}

.summary-panel {
  position: sticky;
  top: 26px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 9px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 12.5px;
}

.summary-row:last-child { border-bottom: none; }
.summary-row .label { color: var(--text-dim); }
.summary-row .value { font-family: var(--font-mono); font-weight: 700; color: var(--text); }

@media (max-width: 900px) {
  .edit-layout { grid-template-columns: 1fr; }
  .summary-panel { position: static; }
}

/* Portfolio chart */

.chart-wrap { width: 100%; overflow-x: auto; }
.chart-wrap svg { display: block; width: 100%; height: auto; }

.big-number {
  font-family: var(--font-mono);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

/* Copy feedback */

button.copied { background: var(--teal-dim); border-color: var(--teal); color: var(--teal); }

.nav-preview-list { display: flex; flex-direction: column; gap: 0; }
.nav-preview-row {
  display: flex;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.nav-preview-row:last-child { border-bottom: none; }

/* Edit DCA Bot layout extras */

.pill-tabs { display: flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; width: fit-content; }
.pill-tabs button { border: none; border-radius: 0; background: var(--card); color: var(--text-dim); padding: 9px 16px; font-size: 12.5px; font-weight: 600; cursor: default; }
.pill-tabs button.active { background: var(--teal); color: #fff; }
.pill-tabs button.disabled-tab { color: var(--text-faint); cursor: not-allowed; background: var(--card-2); }
.pill-tabs button + button { border-left: 1px solid var(--border); }

.field-group { border-left: 3px solid var(--teal); padding-left: 16px; margin-bottom: 22px; }
.field-group.disabled { border-left-color: var(--border); }
.field-group.disabled .field-group-title { color: var(--text-faint); }
.field-group.disabled .field label { color: var(--text-faint); }

.field-group-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-soon {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--text-faint);
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 2px 8px;
}

.static-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-2);
  font-size: 13px;
  color: var(--text-dim);
  width: 100%;
}

.toggle-visual {
  width: 34px;
  height: 19px;
  border-radius: 100px;
  background: var(--border);
  position: relative;
  flex-shrink: 0;
  display: inline-block;
}

.toggle-visual::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #fff;
}

.toggle-visual.on { background: var(--teal); }
.toggle-visual.on::after { left: 17px; }

.warning-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #f5a62317;
  border: 1px solid #f5a62340;
  color: #8a5a10;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12.5px;
  margin-bottom: 14px;
}

input.readonly-field {
  background: var(--card-2) !important;
  color: var(--text-faint) !important;
}

.unsupported-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  font-size: 13px;
  color: var(--text-faint);
}

/* Mobile topbar + off-canvas sidebar */

.mobile-topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 60;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.mobile-topbar img { height: 20px; display: block; }

.mobile-topbar .brand-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.mobile-topbar .brand-title span { color: var(--teal); }

.hamburger-btn {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  color: var(--text);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 20, 0.45);
  z-index: 90;
}

@media (max-width: 860px) {
  body { flex-direction: column; }

  .mobile-topbar { display: flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100vh;
    width: 260px;
    max-width: 82vw;
    transform: translateX(-100%);
    transition: transform .2s ease;
    z-index: 100;
    box-shadow: 8px 0 24px rgba(0, 0, 0, .18);
  }

  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }

  .main { padding: 18px 16px 60px; max-width: 100%; }

  .page-header { flex-direction: column; align-items: stretch; gap: 10px; }
  .page-header button, .page-header .btn { align-self: flex-start; }

  .edit-layout { grid-template-columns: 1fr; }
  .summary-panel { position: static; }

  .stat-grid, .hero-stat-grid {
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 8px;
  }

  .hero-stat-value { font-size: 20px; }
  .stat-value { font-size: 16px; }

  table { font-size: 12px; }
  th, td { padding: 8px 8px; }
}
