:root {
  --bg: #0f1419;
  --card: #1a2332;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #3d8bfd;
  --ok: #3ecf8e;
  --err: #f07178;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.nav {
  display: flex;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: var(--card);
  align-items: center;
}
.site-nav {
  display: flex;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: var(--card);
  align-items: center;
}
.site-nav a,
.nav a { color: var(--accent); text-decoration: none; }
.site-nav-logout,
.nav-logout { margin-left: auto; }
.main { padding: 1.5rem; max-width: 960px; margin: 0 auto; }
.muted { color: var(--muted); }
.ok { color: var(--ok); }
.error { color: var(--err); }
.status-card {
  background: var(--card);
  padding: 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}
.log-tail, .md-preview {
  background: #0a0e14;
  padding: 0.75rem;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.85rem;
  white-space: pre-wrap;
}
.actions { margin: 1.5rem 0; }
.actions .plan-profile-panel {
  width: 100%;
  max-width: none;
  margin-bottom: 1rem;
}
.plan-profile-panel {
  padding: 1rem;
  border-radius: 8px;
  background: var(--card);
  border: 1px solid #334;
}
.plan-profile-intro {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
}
.plan-profile-sliders {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.plan-slider {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.plan-slider-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.9rem;
}
.plan-slider-value {
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.plan-slider input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 1.35rem;
  margin: 0.15rem 0 0;
  background: transparent;
  cursor: pointer;
}
.plan-slider input[type="range"]::-webkit-slider-runnable-track {
  height: 0.55rem;
  border-radius: 0.3rem;
  background: linear-gradient(
    to right,
    #2e9e4f 0%,
    #7cb342 25%,
    #f9d423 50%,
    #f09819 75%,
    #d64545 100%
  );
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.plan-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 1.15rem;
  height: 1.15rem;
  margin-top: calc((0.55rem - 1.15rem) / 2);
  border-radius: 50%;
  background: #f4f6f8;
  border: 2px solid #5a6472;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
.plan-slider input[type="range"]::-moz-range-track {
  height: 0.55rem;
  border-radius: 0.3rem;
  background: linear-gradient(
    to right,
    #2e9e4f 0%,
    #7cb342 25%,
    #f9d423 50%,
    #f09819 75%,
    #d64545 100%
  );
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.plan-slider input[type="range"]::-moz-range-thumb {
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 50%;
  background: #f4f6f8;
  border: 2px solid #5a6472;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
.plan-slider-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  line-height: 1;
  padding: 0 0.1rem;
  user-select: none;
}
.plan-slider-ticks span {
  flex: 0 0 auto;
  width: 1.5rem;
  text-align: center;
}
.plan-slider-ticks span:first-child {
  text-align: left;
  width: auto;
}
.plan-slider-ticks span:last-child {
  text-align: right;
  width: auto;
}
.plan-slider-hints {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
}
.plan-profile-preview-wrap {
  margin-top: 0.75rem;
}
.plan-profile-preview {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1rem;
  margin-top: 0.5rem;
}
.plan-profile-param-list {
  list-style: none;
  padding: 0;
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
}
.plan-profile-param-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.2rem 0;
  border-bottom: 1px solid #2a3340;
}
.plan-profile-save-note {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--accent);
}
.plan-action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  min-height: 44px;
}
.plan-action-hint {
  margin: 0;
}
.inline-form { display: inline-block; margin-right: 0.5rem; }
button, .nav button, .site-nav button {
  background: var(--card);
  color: var(--text);
  border: 1px solid #334;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  min-height: 44px;
}
button.primary { background: var(--accent); border-color: var(--accent); }
button.danger { background: #5c2b2b; border-color: #7a3838; color: #ffd8d8; }
button.danger-sm { padding: 0.25rem 0.65rem; font-size: 0.85rem; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.plan-approval {
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid #3d5a80;
  border-radius: 8px;
  background: #121a26;
}
.plan-approval .inline-form { margin-top: 0.75rem; }
.plan-preview-loading {
  background: var(--card);
  padding: 1rem;
  border-radius: 8px;
  border: 1px dashed #3d5a80;
}
.plan-preview-loading p {
  margin: 0.5rem 0 0;
}
.log-panel {
  margin-top: 0.75rem;
}
.log-panel summary {
  cursor: pointer;
  color: var(--muted);
  user-select: none;
  padding: 0.35rem 0;
}
.log-panel[open] summary {
  margin-bottom: 0.5rem;
}
.plan-summary {
  margin: 1.5rem 0;
  padding: 1rem;
  border-radius: 8px;
  background: var(--card);
}
.plan-summary-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem 2rem;
  margin: 0.75rem 0 0;
}
.plan-summary-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.plan-summary-item strong {
  font-size: 1.15rem;
}
.stats-filter {
  margin: 1.25rem 0 1.5rem;
  padding: 1rem;
  border-radius: 8px;
  background: var(--card);
}
.stats-filter-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: flex-end;
}
.stats-filter-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.stats-filter-form input[type="date"] {
  padding: 0.45rem 0.55rem;
  background: #0a0e14;
  color: var(--text);
  border: 1px solid #334;
  border-radius: 6px;
}
.stats-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.85rem;
}
.stats-preset {
  display: inline-block;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid #334;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.875rem;
}
.stats-preset:hover {
  color: var(--text);
  border-color: var(--accent);
}
.stats-preset.is-active {
  color: var(--text);
  background: #121a26;
  border-color: var(--accent);
}
.stats-summary {
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 8px;
  background: var(--card);
}
.stats-summary-period {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  line-height: 1.45;
}
.stats-summary-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  list-style: none;
  margin: 0;
  padding: 0;
}
.stats-summary-metric {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}
.stats-summary-label {
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}
.stats-summary-value {
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
}
.stats-summary-value-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.65rem;
  align-items: baseline;
}
.stats-summary-metric-total {
  grid-column: 1 / -1;
  padding-top: 0.65rem;
  border-top: 1px solid #334;
}
@media (min-width: 768px) {
  .stats-summary-metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .stats-summary-metric-total {
    grid-column: auto;
    padding-top: 0;
    border-top: none;
  }
}
.stats-chart-wrap {
  position: relative;
  height: min(420px, 60vh);
  padding: 1rem;
  border-radius: 8px;
  background: var(--card);
}
.stats-chart-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.stats-mode-toggle {
  background: var(--card);
  color: var(--muted);
  border: 1px solid #334;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.875rem;
}
.stats-mode-toggle.is-active {
  color: var(--text);
  border-color: var(--accent);
  background: #121a26;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.data-table th, .data-table td {
  border-bottom: 1px solid #334;
  padding: 0.5rem;
  text-align: left;
}
.trade-reason {
  max-width: 14rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}
.session-badge-active {
  color: #3ecf8e;
  background: rgba(62, 207, 142, 0.12);
  border: 1px solid rgba(62, 207, 142, 0.35);
}
.session-badge-done {
  color: var(--muted);
  background: rgba(139, 156, 179, 0.1);
  border: 1px solid #334;
}
.pnl-note {
  font-size: 0.875rem;
  line-height: 1.45;
  max-width: 720px;
}
.trades-total-row td {
  border-top: 1px solid #445;
  font-size: 0.9rem;
}
.settings-form label {
  display: block;
  margin-bottom: 0.75rem;
}
.settings-block {
  margin-bottom: 2rem;
}
.settings-section {
  padding: 1.25rem 1.35rem;
  background: #1a2332;
  border: 1px solid #2a3544;
  border-radius: 10px;
}
.settings-section-header {
  margin-bottom: 1.25rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid #2a3544;
}
.settings-section-header h2 {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
}
.settings-section-desc {
  margin: 0;
  max-width: 640px;
  line-height: 1.45;
}
.settings-section-fields {
  display: grid;
  gap: 0;
}
.settings-form-actions {
  margin-top: 0.5rem;
  padding-top: 0.25rem;
}
.settings-form .field-group {
  margin-bottom: 1.25rem;
  padding-bottom: 1.15rem;
  border-bottom: 1px solid #243041;
}
.settings-form .field-group.is-hidden {
  display: none;
}
.settings-form .settings-section-fields .field-group:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}
.settings-form .field-group:last-of-type {
  border-bottom: none;
}
.settings-form .field-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1rem;
  margin-bottom: 0.35rem;
}
.settings-form .field-label {
  font-weight: 600;
}
.settings-form .field-key {
  color: var(--muted);
  font-size: 0.8rem;
}
.settings-form .field-hint {
  margin: 0 0 0.65rem;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.45;
  max-width: 540px;
}
.settings-form .field-input,
.settings-form .field-select {
  display: block;
  width: 100%;
  max-width: 540px;
  padding: 0.45rem 0.55rem;
  background: #0a0e14;
  color: var(--text);
  border: 1px solid #334;
  border-radius: 6px;
}
.settings-form input[type="number"] {
  max-width: 200px;
}
.settings-form .toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  user-select: none;
}
.settings-form .toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.settings-form .toggle-track {
  position: relative;
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: #334;
  transition: background 0.2s;
  flex-shrink: 0;
}
.settings-form .toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 0.2s;
}
.settings-form .toggle input:checked + .toggle-track {
  background: var(--accent);
}
.settings-form .toggle input:checked + .toggle-track .toggle-thumb {
  transform: translateX(20px);
}
.settings-form .toggle-state {
  min-width: 2.5rem;
  color: var(--muted);
  font-size: 0.875rem;
}
.settings-form input {
  display: block;
  width: 100%;
  max-width: 420px;
  margin-top: 0.25rem;
  padding: 0.4rem;
}
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-card {
  background: var(--card);
  padding: 2rem;
  border-radius: 12px;
  width: 100%;
  max-width: 360px;
}
.login-card input {
  width: 100%;
  padding: 0.5rem;
  margin: 0.5rem 0 1rem;
}

/* --- Mobile layout --- */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1rem 0;
}
.table-scroll .data-table {
  min-width: 640px;
}
.table-scroll .data-table th:first-child,
.table-scroll .data-table td:first-child {
  position: sticky;
  left: 0;
  background: var(--bg);
  z-index: 1;
}

.desktop-only { display: block; }
.mobile-only { display: none; }

.session-cards {
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 0.75rem;
}
.session-cards.mobile-only {
  display: none;
}
.session-card {
  display: block;
  padding: 1rem;
  border-radius: 8px;
  background: var(--card);
  border: 1px solid #2a3544;
  color: inherit;
  text-decoration: none;
}
.session-card:hover {
  border-color: var(--accent);
}
.session-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}
.session-card-meta {
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}
.session-card-pnl {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  font-size: 0.95rem;
}
.session-card-footer {
  margin-top: 0.65rem;
  font-size: 0.85rem;
}

@media (max-width: 767px) {
  body {
    padding-bottom: calc(4.25rem + env(safe-area-inset-bottom, 0px));
  }
  .main {
    padding: 1rem 1rem 0.5rem;
  }
  h1 {
    font-size: 1.35rem;
  }
  .site-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    z-index: 100;
    margin: 0;
    gap: 0.25rem;
    padding: 0.35rem 0.5rem calc(0.35rem + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid #334;
    justify-content: space-around;
  }
  .site-nav-link {
    flex: 1;
    text-align: center;
    font-size: 0.72rem;
    line-height: 1.2;
    padding: 0.35rem 0.15rem;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .site-nav-logout {
    margin-left: 0;
    flex: 0 0 auto;
  }
  .site-nav-logout button {
    min-height: 44px;
    padding: 0.35rem 0.65rem;
    font-size: 0.72rem;
  }
  .desktop-only { display: none !important; }
  .mobile-only { display: block; }
  .session-cards.mobile-only {
    display: grid;
  }
  .actions .inline-form {
    display: block;
    margin: 0 0 0.65rem;
    width: 100%;
  }
  .plan-action-row {
    flex-direction: column;
  }
  .plan-action-buttons {
    width: 100%;
    flex-direction: column;
  }
  .plan-action-buttons .inline-form {
    width: 100%;
  }
  .plan-profile-preview {
    grid-template-columns: 1fr;
  }
  .actions .inline-form button {
    width: 100%;
  }
  .plan-approval .inline-form {
    display: block;
    margin-right: 0;
    margin-bottom: 0.65rem;
  }
  .plan-approval .inline-form button {
    width: 100%;
  }
  .session-stop-form {
    display: block;
    width: 100%;
    margin-top: 0.5rem;
  }
  .session-stop-form button {
    width: 100%;
  }
  .stats-filter-form label {
    flex: 1 1 40%;
    min-width: 8rem;
  }
  .stats-filter-form button[type="submit"] {
    flex: 1 1 100%;
    width: 100%;
  }
  .status-card {
    padding: 0.85rem;
  }
  .settings-section {
    padding: 1rem;
  }
  .settings-form .field-input,
  .settings-form .field-select,
  .settings-form input {
    max-width: none;
  }
  .settings-form input[type="number"] {
    max-width: none;
  }
  .settings-form-actions {
    position: sticky;
    bottom: calc(4.25rem + env(safe-area-inset-bottom, 0px));
    z-index: 50;
    margin: 0 -1rem;
    padding: 0.75rem 1rem;
    background: linear-gradient(transparent, var(--bg) 25%);
  }
  .settings-form-actions button {
    width: 100%;
  }
  .login-card {
    margin: 1rem;
    padding: 1.5rem;
  }
  .stats-chart-wrap {
    height: min(360px, 52vh);
  }
}

@media (max-width: 480px) {
  .stats-presets {
    gap: 0.35rem;
  }
  .stats-preset {
    font-size: 0.8rem;
    padding: 0.3rem 0.55rem;
  }
}
