/* Polytrader Web UI — Light Theme */

:root {
  --bg: #f4f6f9;
  --bg-card: #ffffff;
  --bg-hover: #edf2f7;
  --border: #e2e8f0;
  --text: #1a202c;
  --text-muted: #718096;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --green: #16a34a;
  --yellow: #d97706;
  --red: #dc2626;
  --gray: #718096;
  --font-mono: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  --radius: 6px;
  --shadow: 0 1px 4px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* ── Navbar ────────────────────────────────────────────────────────── */
.navbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  height: 52px;
  gap: 32px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.nav-brand {
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
  text-decoration: none;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.nav-links {
  list-style: none;
  display: flex;
  gap: 4px;
}

.nav-links a {
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: var(--radius);
  transition: color 0.15s, background 0.15s;
  text-decoration: none;
  font-size: 14px;
}

.nav-links a:hover {
  color: var(--text);
  background: var(--bg-hover);
}

/* Hamburger toggle — hidden on desktop */
.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius);
  margin-left: auto;
}

.nav-toggle span {
  display: block;
  height: 2px;
  background: var(--text-muted);
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}

.nav-toggle:hover span { background: var(--text); }

/* ── Layout ────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  padding: 24px;
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
}

.footer {
  text-align: center;
  padding: 12px;
  color: var(--text-muted);
  font-size: 12px;
  border-top: 1px solid var(--border);
}

/* ── Page Header ───────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.breadcrumb {
  color: var(--text-muted);
  font-size: 13px;
}

.breadcrumb a { color: var(--accent); }
.breadcrumb span { color: var(--text); }

/* ── Dashboard stat card (inside the HTMX polling wrapper) ─────────── */
.stat-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px;
  height: 100%;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.stat-value {
  font-size: 36px;
  font-weight: 700;
}

.stat-running .stat-value { color: var(--green); }
.stat-idle    .stat-value { color: var(--text-muted); }

/* ── Cards ─────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

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

.card-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}

.card-value {
  font-size: 36px;
  font-weight: 700;
  margin-bottom: 12px;
}

.card-value-sm {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  margin-bottom: 12px;
  word-break: break-all;
}

.card-link {
  font-size: 12px;
}

.status-running { color: var(--green); }
.status-idle    { color: var(--text-muted); }

#stats-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ── Section ───────────────────────────────────────────────────────── */
.section { margin-bottom: 32px; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.section-header h2 {
  font-size: 16px;
  font-weight: 600;
}

/* ── Quick Start ───────────────────────────────────────────────────── */
.quick-start-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.quick-start-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.quick-start-card h3 {
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-mono);
  margin-bottom: 6px;
}

.quick-start-card p {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* ── Forms ─────────────────────────────────────────────────────────── */
.form-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.form-row label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.form-row input,
.form-row select,
.form-row textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

/* ── Buttons ───────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s, background 0.15s;
  text-decoration: none;
  line-height: 1;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary   { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--bg-hover); color: var(--text); border: 1px solid var(--border); }
.btn-warning   { background: var(--yellow); color: #fff; }
.btn-danger    { background: var(--red); color: #fff; }

.btn-sm { padding: 5px 10px; font-size: 12px; }

.btn-primary:hover   { background: var(--accent-hover); opacity: 1; }
.btn-secondary:hover { background: #dce6f0; }
.btn-warning:hover   { opacity: 0.85; }
.btn-danger:hover    { opacity: 0.85; }

/* ── Tables ────────────────────────────────────────────────────────── */
.table-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  box-shadow: var(--shadow);
}

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

.data-table th {
  background: var(--bg);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tr:hover td { background: var(--bg-hover); }

.data-table .path-cell {
  font-family: var(--font-mono);
  font-size: 12px;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.data-table .actions-cell {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
}

.mono { font-family: var(--font-mono); font-size: 12px; }

/* ── Badges ────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-green { background: rgba(22,163,74,0.12); color: var(--green); }
.badge-gray  { background: rgba(113,128,150,0.12); color: var(--gray); }
.badge-red   { background: rgba(220,38,38,0.12); color: var(--red); }

/* ── Row states ────────────────────────────────────────────────────── */
.row-running { border-left: 3px solid var(--green); }
.row-stopped { opacity: 0.7; }

/* ── Log viewer ────────────────────────────────────────────────────── */
.log-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.log-meta code {
  font-family: var(--font-mono);
  background: var(--bg-hover);
  padding: 2px 6px;
  border-radius: 3px;
  color: var(--text);
}

.log-container {
  background: #1e293b;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  height: calc(100vh - 220px);
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
}

.log-line {
  padding: 1px 0;
  color: #cbd5e1;
}

.log-line:hover { background: rgba(255,255,255,0.04); }
.log-error      { color: #fca5a5; }

/* ── Code editor ───────────────────────────────────────────────────── */
.code-editor {
  width: 100%;
  background: #1e293b;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: #e2e8f0;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  padding: 16px;
  resize: vertical;
  min-height: 200px;
}

.editor-wrapper .code-editor {
  height: calc(100vh - 200px);
  resize: none;
}

/* ── Alerts ────────────────────────────────────────────────────────── */
.alert {
  padding: 10px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13px;
}

.alert-success { background: rgba(22,163,74,0.08);  color: #15803d; border: 1px solid rgba(22,163,74,0.3); }
.alert-error   { background: rgba(220,38,38,0.08);  color: #b91c1c; border: 1px solid rgba(220,38,38,0.3); }
.alert-info    { background: rgba(59,130,246,0.08); color: #1d4ed8; border: 1px solid rgba(59,130,246,0.3); }

/* ── Empty state ───────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ── Toggle ────────────────────────────────────────────────────────── */
.toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

/* ── Spawn form ────────────────────────────────────────────────────── */
.spawn-form { display: flex; flex-direction: column; }

/* ── Accounts page ─────────────────────────────────────────────────── */

/* Full-bleed split layout — overrides the main-content padding */
.main-content:has(.accounts-layout) {
  padding: 0;
  max-width: 100%;
}

.accounts-layout {
  display: flex;
  height: calc(100vh - 52px - 38px); /* subtract navbar + footer */
  overflow: hidden;
}

/* Left sidebar */
.accounts-sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.accounts-sidebar-header {
  padding: 16px 16px 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.account-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 8px 0;
}

.account-item {
  padding: 10px 14px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}

.account-item:hover {
  background: var(--bg-hover);
}

.account-item.active {
  background: rgba(59,130,246,0.08);
  border-left-color: var(--accent);
}

.account-source-badge {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 1px 5px;
  border-radius: 3px;
  display: inline-block;
  margin-bottom: 4px;
}

.account-item-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-item-addr {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  margin-top: 2px;
}

.account-empty {
  padding: 20px 14px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* Right main panel */
.accounts-main {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: var(--bg);
}

/* Historical chart */
.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  height: 260px;
  position: relative;
  box-shadow: var(--shadow);
}

/* Period selector buttons */
.period-selector {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.period-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Colour helpers used by the portfolio JS */
.text-green { color: var(--green); }
.text-red   { color: var(--red); }
.text-muted { color: var(--text-muted); font-size: 12px; }

/* ── Responsive: Tablet (≤ 900px) ──────────────────────────────────── */
@media (max-width: 900px) {
  .quick-start-grid { grid-template-columns: 1fr; }
}

/* ── Responsive: Mobile (≤ 640px) ──────────────────────────────────── */
@media (max-width: 640px) {
  /* Navbar collapses to hamburger */
  .navbar {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 16px;
    gap: 0;
  }

  .nav-brand { padding: 6px 0; }

  .nav-toggle {
    display: flex;
    margin-left: auto;
  }

  .nav-links {
    display: none;
    width: 100%;
    flex-direction: column;
    gap: 2px;
    padding: 8px 0 4px;
    border-top: 1px solid var(--border);
    margin-top: 8px;
  }

  .nav-links.open { display: flex; }

  .nav-links a {
    padding: 10px 8px;
    font-size: 15px;
  }

  /* Main content */
  .main-content { padding: 16px 12px; }

  .page-header h1 { font-size: 18px; }

  /* Cards */
  .card-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .card-value { font-size: 26px; }
  .stat-value { font-size: 26px; }

  /* Log viewer */
  .log-container { height: calc(100vh - 200px); }

  /* Accounts: stack vertically */
  .accounts-layout {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  .accounts-sidebar {
    width: 100%;
    min-width: unset;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 200px;
  }

  .accounts-main {
    padding: 16px 12px;
    overflow-y: visible;
  }

  .chart-container { height: 200px; }

  /* Tables */
  .data-table th,
  .data-table td { padding: 8px 10px; }
}
