/* ================================================================
   Previdor — Unified Stylesheet
   Mobile-first, dark theme, Pico CSS v2 base
   ================================================================ */

/* ── 1. CSS VARIABLES & PICO OVERRIDES ─────────────────────────── */
:root {
  --bg: #0a0b0f;
  --card: #12141c;
  --card-hover: #181b27;
  --border: #1e2030;
  --accent: #f59e0b;
  --accent2: #8b5cf6;
  --green: #22c55e;
  --red: #ef4444;
  --text: #e2e8f0;
  --muted: #64748b;
  --nav-height: 60px;
  --sidebar-width: 200px;
  --sidebar-collapsed: 56px;

  --pico-font-family: 'Inter', system-ui, -apple-system, sans-serif;
  --pico-font-family-monospace: 'JetBrains Mono', 'Fira Mono', monospace;
  --pico-border-radius: 10px;
  --pico-background-color: var(--bg);
}

[data-theme="dark"] {
  --pico-background-color: var(--bg);
  --pico-color: var(--text);
  --pico-card-background-color: var(--card);
  --pico-card-border-color: var(--border);
  --pico-muted-color: var(--muted);
  --pico-primary: var(--accent);
  --pico-primary-hover: #d97706;
  --pico-form-element-background-color: var(--card);
  --pico-form-element-border-color: var(--border);
  --pico-form-element-color: var(--text);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  color-scheme: dark;
}

input[type="date"] {
  -webkit-appearance: auto !important;
  appearance: auto !important;
}

body {
  background-color: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-family: var(--pico-font-family);
  position: relative;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at 20% 10%, rgba(245, 158, 11, 0.04) 0%, transparent 50%),
              radial-gradient(ellipse at 80% 80%, rgba(139, 92, 246, 0.04) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ── 2. NAVIGATION ──────────────────────────────────────────────── */
.main-content {
  padding: 16px;
  padding-bottom: calc(var(--nav-height) + 16px);
  position: relative;
  z-index: 1;
}

/* Bottom nav — mobile default */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: rgba(18, 20, 28, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  z-index: 100;
}

.bottom-nav .nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  transition: color 0.2s;
  padding: 6px 0;
}

.bottom-nav .nav-item.active,
.bottom-nav .nav-item:hover {
  color: var(--accent);
}

.bottom-nav .nav-icon {
  font-size: 20px;
  line-height: 1;
}

.bottom-nav .nav-item span:last-child {
  font-size: 10px;
}

/* Side nav — desktop */
.side-nav {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-collapsed);
  background: rgba(18, 20, 28, 0.96);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-right: 1px solid var(--border);
  flex-direction: column;
  align-items: flex-start;
  padding: 16px 0;
  z-index: 100;
  overflow: hidden;
  transition: width 0.25s ease;
}

.side-nav:hover {
  width: var(--sidebar-width);
}

.side-nav .logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px 20px;
  font-weight: 700;
  font-size: 15px;
  color: var(--accent);
  white-space: nowrap;
  text-decoration: none;
  overflow: hidden;
}

.side-nav .logo-icon {
  font-size: 22px;
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}

.side-nav .nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  width: 100%;
  text-decoration: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: color 0.2s, background 0.2s;
  border-radius: 0;
  overflow: hidden;
}

.side-nav .nav-item.active,
.side-nav .nav-item:hover {
  color: var(--text);
  background: rgba(245, 158, 11, 0.08);
}

.side-nav .nav-item.active {
  color: var(--accent);
}

.side-nav .nav-icon {
  font-size: 18px;
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}

.side-nav .nav-label {
  opacity: 0;
  transition: opacity 0.2s ease;
}

.side-nav:hover .nav-label {
  opacity: 1;
}

/* Desktop layout */
@media (min-width: 768px) {
  .bottom-nav {
    display: none;
  }

  .side-nav {
    display: flex;
  }

  .main-content {
    margin-left: var(--sidebar-collapsed);
    padding-bottom: 24px;
    transition: margin-left 0.25s ease;
  }
}

/* ── 3. P&L BANNER ──────────────────────────────────────────────── */
.pnl-banner {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.12) 0%, rgba(139, 92, 246, 0.08) 100%);
  border: 1px solid rgba(245, 158, 11, 0.2);
  border-radius: var(--pico-border-radius);
  padding: 20px;
  text-align: center;
  margin-bottom: 16px;
}

.pnl-value {
  font-size: 28px;
  font-family: var(--pico-font-family-monospace);
  font-weight: 700;
  line-height: 1.1;
}

.pnl-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
}

.pnl-sub {
  font-size: 13px;
  color: var(--muted);
  margin-top: 8px;
}

/* ── 4. STAT GRID ───────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

@media (min-width: 640px) {
  .stat-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--pico-border-radius);
  padding: 14px 16px;
}

.stat-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
  font-family: var(--pico-font-family-monospace);
  line-height: 1.1;
}

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

/* ── 5. BOT CARD ────────────────────────────────────────────────── */
.bot-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--pico-border-radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.1s;
}

.bot-card:hover {
  background: var(--card-hover);
  transform: translateY(-1px);
}

.bot-card.running {
  border-left-color: var(--green);
}

.bot-card.stopped {
  opacity: 0.7;
}

.bot-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}

.bot-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}

.bot-metrics {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

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

.metric-label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.metric-value {
  font-size: 14px;
  font-family: var(--pico-font-family-monospace);
  font-weight: 600;
}

@media (max-width: 480px) {
  .bot-header {
    flex-direction: column;
    gap: 8px;
  }

  .bot-metrics {
    gap: 12px;
  }
}

/* ── 6. STATUS DOT ──────────────────────────────────────────────── */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}

.status-dot.running {
  background: var(--green);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5); }
  50% { box-shadow: 0 0 0 5px rgba(34, 197, 94, 0); }
}

/* ── 7. BADGES ──────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  border: 1px solid transparent;
}

.badge-green {
  background: rgba(34, 197, 94, 0.12);
  color: var(--green);
  border-color: rgba(34, 197, 94, 0.25);
}

.badge-red {
  background: rgba(239, 68, 68, 0.12);
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.25);
}

.badge-accent {
  background: rgba(245, 158, 11, 0.12);
  color: var(--accent);
  border-color: rgba(245, 158, 11, 0.25);
}

.badge-purple {
  background: rgba(139, 92, 246, 0.12);
  color: var(--accent2);
  border-color: rgba(139, 92, 246, 0.25);
}

/* ── 8. COLOR / TEXT UTILITIES ──────────────────────────────────── */
.text-green { color: var(--green) !important; }
.text-red   { color: var(--red) !important; }
.text-accent { color: var(--accent) !important; }
.text-muted  { color: var(--muted) !important; }
.mono { font-family: var(--pico-font-family-monospace) !important; }

/* ── 9. SECTION LABEL ───────────────────────────────────────────── */
.section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 10px;
  margin-top: 20px;
}

/* ── 10. TAB GROUP ──────────────────────────────────────────────── */
.tab-group {
  display: flex;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--pico-border-radius);
  padding: 4px;
  gap: 2px;
  margin-bottom: 16px;
  overflow-x: auto;
}

.tab-btn {
  flex-shrink: 0;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
  color: var(--bg);
  background: var(--accent);
  font-weight: 600;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* ── 11. MARKET ROW / LIST ──────────────────────────────────────── */
.market-list {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--pico-border-radius);
  overflow: hidden;
}

.market-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.market-row:last-child {
  border-bottom: none;
}

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

/* ── 12. BOT SCROLL ─────────────────────────────────────────────── */
.bot-scroll {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.bot-scroll::-webkit-scrollbar {
  height: 4px;
}

.bot-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.bot-scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.bot-mini {
  flex-shrink: 0;
  min-width: 140px;
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--green);
  border-radius: var(--pico-border-radius);
  padding: 12px 14px;
  cursor: pointer;
  transition: background 0.2s;
}

.bot-mini:hover {
  background: var(--card-hover);
}

.bot-mini.negative {
  border-left-color: var(--red);
}

.bot-mini-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bot-mini-pnl {
  font-size: 16px;
  font-family: var(--pico-font-family-monospace);
  font-weight: 700;
  line-height: 1.1;
}

.bot-mini-session {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

/* ── 13. TOAST ──────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: calc(var(--nav-height) + 12px);
  right: 12px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

@media (min-width: 768px) {
  .toast-container {
    bottom: 20px;
  }
}

.toast {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--pico-border-radius);
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  max-width: 300px;
  pointer-events: auto;
  animation: toast-in 0.25s ease;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.toast.success {
  border-left: 3px solid var(--green);
  color: var(--green);
}

.toast.error {
  border-left: 3px solid var(--red);
  color: var(--red);
}

/* ── 14. MODAL ──────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 150;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  animation: modal-in 0.2s ease;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

@media (max-width: 480px) {
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    max-height: 85vh;
    padding-bottom: 32px;
  }
}

.modal-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 16px;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
}

/* ── 15. BUTTONS ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: transform 0.15s, opacity 0.15s, background 0.15s;
  white-space: nowrap;
}

.btn:hover {
  transform: translateY(-1px);
  opacity: 0.92;
}

.btn:active {
  transform: translateY(0);
}

.btn-accent {
  background: linear-gradient(135deg, var(--accent) 0%, #d97706 100%);
  color: #000;
  border-color: transparent;
}

.btn-green {
  background: rgba(34, 197, 94, 0.15);
  color: var(--green);
  border-color: rgba(34, 197, 94, 0.3);
}

.btn-red {
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}

.btn-ghost:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

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

/* ── 16. TABLE WRAP ─────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--pico-border-radius);
  border: 1px solid var(--border);
}

.table-wrap table,
table.styled {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table-wrap th,
table.styled th {
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table-wrap td,
table.styled td {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(30, 32, 48, 0.6);
  color: var(--text);
  vertical-align: middle;
}

.table-wrap tr:last-child td,
table.styled tr:last-child td {
  border-bottom: none;
}

.table-wrap tr:hover td,
table.styled tr:hover td {
  background: var(--card-hover);
}

/* ── 17. CHART BOX ──────────────────────────────────────────────── */
.chart-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--pico-border-radius);
  padding: 16px;
  margin-bottom: 16px;
}

.chart-box canvas {
  width: 100% !important;
  max-height: 300px;
}

/* ── 18. SUMMARY BAR ────────────────────────────────────────────── */
.summary-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--pico-border-radius);
  margin-bottom: 16px;
}

/* ── 19. PAGE HEADER ────────────────────────────────────────────── */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding-top: 8px;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.2s;
}

.back-link:hover {
  color: var(--text);
}

/* ── 20. ACCORDION ──────────────────────────────────────────────── */
.accordion-item {
  border: 1px solid var(--border);
  border-radius: var(--pico-border-radius);
  margin-bottom: 8px;
  overflow: hidden;
}

.accordion-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  background: var(--card);
  user-select: none;
  transition: background 0.15s;
}

.accordion-header:hover {
  background: var(--card-hover);
}

.accordion-header::after {
  content: '▸';
  color: var(--muted);
  font-size: 12px;
  transition: transform 0.2s;
}

.accordion-item.open .accordion-header::after {
  transform: rotate(90deg);
}

.accordion-body {
  display: none;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: rgba(18, 20, 28, 0.5);
  font-size: 14px;
}

.accordion-item.open .accordion-body {
  display: block;
}

/* ── 21. FILTER BAR ─────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 16px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  flex-wrap: wrap;
  position: relative;
  z-index: 10;
}

.filter-bar::-webkit-scrollbar {
  display: none;
}

.filter-bar select,
.filter-bar input {
  flex-shrink: 0;
  background: var(--card) !important;
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  color: var(--text) !important;
  color-scheme: dark;
  font-size: 13px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
  min-height: 44px;
  min-width: 100px;
  margin: 0 !important;
}

.filter-bar input[type="date"] {
  -webkit-appearance: auto;
  appearance: auto;
}

.filter-bar select:focus,
.filter-bar input:focus {
  border-color: var(--accent);
}

/* ── 22. MORE PAGE MENU ─────────────────────────────────────────── */
.menu-list {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--pico-border-radius);
  overflow: hidden;
  margin-bottom: 16px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  text-decoration: none;
  color: var(--text);
  font-size: 15px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
  cursor: pointer;
}

.menu-item:last-child {
  border-bottom: none;
}

.menu-item:hover {
  background: var(--card-hover);
}

.menu-item .menu-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.menu-item .menu-arrow {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
}

.menu-item.danger {
  color: var(--red);
}

/* ── 23. AUTH PAGES ─────────────────────────────────────────────── */
.auth-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.auth-page .bottom-nav,
.auth-page .side-nav {
  display: none !important;
}

.auth-page .main-content {
  margin-left: 0;
  padding-bottom: 20px;
}

.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  width: 100%;
  max-width: 400px;
}

.brand {
  text-align: center;
  margin-bottom: 28px;
}

.brand-icon {
  font-size: 40px;
  line-height: 1;
  margin-bottom: 10px;
}

.brand h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 6px;
}

.brand p {
  font-size: 14px;
  color: var(--muted);
  margin: 0;
}
