/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }

:root {
  --bg:       #0b1220;
  --surface:  #111827;
  --surface2: #1a2540;
  --line:     #1f2e50;
  --accent:   #3b6ef5;
  --accent2:  #2554d4;
  --success:  #16a34a;
  --danger:   #dc2626;
  --warning:  #d97706;
  --text:     #e8eeff;
  --muted:    #6b7aad;
  --sidebar-w: 240px;
  --topbar-h:  56px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── App shell ────────────────────────────────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; }

/* ── Backdrop ─────────────────────────────────────────────────────────────── */
.backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 90;
  backdrop-filter: blur(2px);
}
.backdrop.show { display: block; }

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transform: translateX(0);
  transition: transform .25s ease;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  min-height: var(--topbar-h);
  gap: 8px;
}
.sidebar-top strong { font-size: 1rem; color: #fff; }

.nav { padding: 10px 0 20px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  color: var(--muted);
  text-decoration: none;
  font-size: .88rem;
  border-left: 3px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--surface2); color: #fff; border-left-color: var(--accent); }

/* ── Main content ─────────────────────────────────────────────────────────── */
.content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ── Topbar ───────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
}
.topbar h1 { font-size: 1rem; font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

/* icon button */
.icon-btn {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 1.1rem; padding: 6px; border-radius: 8px;
  line-height: 1; transition: color .15s, background .15s;
  display: flex; align-items: center; justify-content: center;
  min-width: 34px; min-height: 34px;
}
.icon-btn:hover { background: var(--surface2); color: var(--text); }
#menuOpen { display: none; }

/* ── Page body ────────────────────────────────────────────────────────────── */
.page-body { padding: 20px; flex: 1; max-width: 1400px; width: 100%; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 20px;
}
.card h3 { font-size: .95rem; font-weight: 600; margin-bottom: 14px; color: #c5d0ff; }
.card h4 { font-size: .88rem; font-weight: 600; margin: 14px 0 10px; color: #a8b4e8; }
.card h5 { font-size: .82rem; font-weight: 600; margin: 10px 0 8px; color: #8090c8; text-transform: uppercase; letter-spacing: .05em; }

/* ── Grids ────────────────────────────────────────────────────────────────── */
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ── Alerts ───────────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px; border-radius: 10px; margin: 0 20px 16px;
  font-size: .88rem; display: flex; align-items: flex-start; gap: 8px;
}
.alert.success { background: rgba(22,163,74,.12); border: 1px solid rgba(22,163,74,.3); color: #86efac; }
.alert.error   { background: rgba(220,38,38,.12);  border: 1px solid rgba(220,38,38,.3);  color: #fca5a5; }
.alert.warning { background: rgba(217,119,6,.12);  border: 1px solid rgba(217,119,6,.3);  color: #fcd34d; }
.alert.info    { background: rgba(59,110,245,.12); border: 1px solid rgba(59,110,245,.3); color: #93c5fd; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid transparent;
  font-size: .85rem; font-weight: 500; cursor: pointer;
  background: var(--accent); color: #fff;
  transition: background .15s, opacity .15s, transform .1s;
  text-decoration: none; white-space: nowrap;
  line-height: 1.3;
}
.btn:hover { background: var(--accent2); }
.btn:active { transform: scale(.97); }
.btn.secondary { background: var(--surface2); border-color: var(--line); color: var(--text); }
.btn.secondary:hover { background: #223060; }
.btn.success { background: var(--success); }
.btn.success:hover { background: #15803d; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #b91c1c; }
.btn.warning { background: var(--warning); }
.btn.sm { padding: 6px 12px; font-size: .8rem; border-radius: 8px; }
.btn.xs { padding: 4px 9px; font-size: .76rem; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
label { display: block; font-size: .85rem; color: #b0bde0; margin-bottom: 4px; }
label span.req { color: var(--danger); margin-left: 2px; }

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="search"], input[type="url"],
input[type="date"], input[type="datetime-local"],
select, textarea {
  width: 100%;
  background: #0d1526;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  font-size: .85rem;
  padding: 9px 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,110,245,.15);
}
textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
select { cursor: pointer; }
input[type="checkbox"] { width: auto; cursor: pointer; accent-color: var(--accent); }
input[type="file"] { padding: 7px 10px; font-size: .82rem; color: var(--muted); }

/* form label wrapping an input */
label > input, label > select, label > textarea {
  display: block; margin-top: 6px;
}

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: .84rem; }
th {
  text-align: left; padding: 10px 12px;
  color: var(--muted); font-weight: 500; font-size: .8rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap; background: var(--surface);
}
td { padding: 10px 12px; border-bottom: 1px solid #111f38; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(30,48,90,.35); }

/* ── Badges & chips ───────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px;
  font-size: .75rem; font-weight: 500;
  background: var(--surface2); border: 1px solid var(--line); color: #a8b8e0;
  white-space: nowrap;
}
.badge.green  { background: rgba(22,163,74,.15);  border-color: rgba(22,163,74,.3);  color: #86efac; }
.badge.red    { background: rgba(220,38,38,.15);   border-color: rgba(220,38,38,.3);   color: #fca5a5; }
.badge.yellow { background: rgba(217,119,6,.15);  border-color: rgba(217,119,6,.3);  color: #fcd34d; }
.badge.blue   { background: rgba(59,110,245,.15); border-color: rgba(59,110,245,.3); color: #93c5fd; }
.badge.purple { background: rgba(139,92,246,.15); border-color: rgba(139,92,246,.3); color: #c4b5fd; }

.stat-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 10px;
  background: var(--surface2); border: 1px solid var(--line);
  font-size: .82rem; color: var(--text);
}
.stat-chip .label { color: var(--muted); font-size: .76rem; }

/* ── KPI ──────────────────────────────────────────────────────────────────── */
.kpi { font-size: 2rem; font-weight: 700; color: #fff; line-height: 1.1; margin: 6px 0 4px; }
.kpi-label { font-size: .8rem; color: var(--muted); }
.kpi-card { display: flex; align-items: center; gap: 14px; }
.kpi-icon { font-size: 1.6rem; opacity: .7; }

/* ── Inline flex row ──────────────────────────────────────────────────────── */
.inline { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.muted { color: var(--muted); font-size: .82rem; }

/* ── Tab bar ──────────────────────────────────────────────────────────────── */
.tab-bar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.tab-bar a {
  padding: 8px 14px; border-radius: 10px;
  background: var(--surface2); border: 1px solid var(--line);
  color: var(--muted); font-size: .84rem; text-decoration: none;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.tab-bar a:hover, .tab-bar a.active { background: #263570; border-color: var(--accent); color: #fff; }

/* ── Section anchor scroll margin ────────────────────────────────────────── */
.section-anchor { scroll-margin-top: 70px; }

/* ── User list pane ───────────────────────────────────────────────────────── */
.list-pane { display: grid; grid-template-columns: 260px 1fr; gap: 18px; align-items: start; }
.user-list { overflow-y: auto; max-height: calc(100vh - 160px); }
.user-list a {
  display: block; padding: 11px 14px; border-radius: 10px;
  color: var(--text); text-decoration: none; margin-bottom: 4px;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s;
}
.user-list a:hover { background: var(--surface2); border-color: var(--line); }
.user-list a.active { background: #1d2f5e; border-color: var(--accent); }

/* ── Conversation feed ────────────────────────────────────────────────────── */
.conversation { display: flex; flex-direction: column; gap: 10px; max-height: 420px; overflow-y: auto; padding-right: 4px; }
.msg { padding: 10px 14px; border-radius: 12px; max-width: 80%; font-size: .84rem; line-height: 1.5; }
.msg.in  { background: var(--surface2); border: 1px solid var(--line); align-self: flex-start; }
.msg.out { background: rgba(59,110,245,.18); border: 1px solid rgba(59,110,245,.3); align-self: flex-end; }

/* ── Trading status indicators ────────────────────────────────────────────── */
.status-dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; margin-right: 5px;
}
.status-dot.on  { background: #22c55e; box-shadow: 0 0 6px #22c55e; }
.status-dot.off { background: #475569; }
.status-dot.compound { background: #a78bfa; box-shadow: 0 0 6px #a78bfa; }

/* ── Toggle switch ────────────────────────────────────────────────────────── */
.toggle-wrap { display: flex; align-items: center; gap: 8px; }
.toggle {
  position: relative; display: inline-block;
  width: 42px; height: 24px; flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0; cursor: pointer;
  background: #2d3a60; border-radius: 24px;
  transition: background .2s;
}
.toggle-slider::before {
  content: ''; position: absolute;
  width: 18px; height: 18px; border-radius: 50%;
  left: 3px; bottom: 3px;
  background: #fff; transition: transform .2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ── Code ─────────────────────────────────────────────────────────────────── */
code {
  background: #1b2444; padding: 2px 7px; border-radius: 6px;
  font-size: .82rem; color: #a8b4e8; font-family: 'SF Mono', 'Fira Code', monospace;
}
pre { white-space: pre-wrap; word-break: break-all; font-size: .8rem; color: #b0bde0; line-height: 1.6; }

/* ── Dividers ─────────────────────────────────────────────────────────────── */
hr { border: none; border-top: 1px solid var(--line); margin: 18px 0; }

/* ── PM2 log output ───────────────────────────────────────────────────────── */
.log-output {
  background: #060d18; border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 16px; font-family: monospace; font-size: .78rem;
  color: #8aff80; line-height: 1.6; max-height: 400px; overflow-y: auto;
  white-space: pre-wrap; word-break: break-all;
}

/* ── Env path pill ────────────────────────────────────────────────────────── */
.env-path {
  font-size: .78rem; background: #0d1526;
  border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 12px; color: var(--muted); margin-bottom: 14px;
  display: inline-block;
}

/* ── Scrollbars ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #3a4f80; }

/* ── Mobile: ≤ 900px ──────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  :root { --sidebar-w: 260px; }

  .sidebar {
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0,0,0,.5);
  }
  .sidebar.open { transform: translateX(0); }

  .content { margin-left: 0; }

  #menuOpen { display: flex; }

  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }

  .list-pane { grid-template-columns: 1fr; }
  .user-list { max-height: 260px; }

  .topbar { padding: 0 14px; }
  .topbar h1 { font-size: .9rem; }

  .page-body { padding: 14px; }

  .card { padding: 14px; }

  table { font-size: .8rem; }
  th, td { padding: 8px 10px; }

  .inline { gap: 6px; }

  .btn { padding: 8px 13px; font-size: .82rem; }

  .tab-bar { gap: 5px; }
  .tab-bar a { padding: 7px 11px; font-size: .8rem; }

  .kpi { font-size: 1.6rem; }
}

@media (max-width: 520px) {
  .topbar-right .muted { display: none; }
  .card { padding: 12px; }
  .grid-2 { grid-template-columns: 1fr; }
  .btn.sm { padding: 5px 10px; font-size: .78rem; }
}