/* autox-engine dashboard — dark theme */

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-card: #1c2128;
  --border: #30363d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --accent: #6c5ce7;
  --accent-light: #a29bfe;
  --won: #3fb950;
  --lost: #f85149;
  --testing: #d29922;
  --stock: #8b949e;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  padding-top: 56px;
}

/* ===== Navigation ===== */
.top-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  height: 56px;
}

.nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  height: 100%;
  gap: 2rem;
}

.nav-brand {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent-light);
  text-decoration: none;
  white-space: nowrap;
}

.nav-brand:hover {
  color: var(--text-primary);
}

.nav-links {
  display: flex;
  list-style: none;
  gap: 0.25rem;
  margin-left: auto;
}

.nav-links a {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.85rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  border-radius: 6px;
  transition: all 0.15s ease;
  white-space: nowrap;
}

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

.nav-links a.active {
  color: var(--accent-light);
  background: var(--accent) + '22';
  background: rgba(108, 92, 231, 0.15);
}

.nav-icon {
  font-size: 1rem;
}

.nav-toggle {
  display: none;
  flex-direction: column;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  margin-left: auto;
}

.nav-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text-secondary);
  border-radius: 2px;
  transition: all 0.2s ease;
}

/* ===== Header (page title area) ===== */
header {
  padding: 1.5rem 2rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

header h1 {
  font-size: 1.5rem;
  color: var(--accent-light);
}

.subtitle {
  color: var(--text-secondary);
  margin-top: 0.3rem;
  font-size: 0.9rem;
}

/* ===== Main Content ===== */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ===== Grid layouts ===== */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1.5rem;
}

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
}

.card h2 {
  font-size: 1.2rem;
  margin-bottom: 1rem;
  color: var(--accent-light);
}

.card h3 {
  font-size: 1rem;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

.card-compact {
  padding: 1rem;
}

/* ===== Stats Grid ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.8rem;
  background: var(--bg-secondary);
  border-radius: 6px;
  border: 1px solid var(--border);
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 0.3rem;
}

.stat-value.won { color: var(--won); }
.stat-value.lost { color: var(--lost); }
.stat-value.testing { color: var(--testing); }
.stat-value.accent { color: var(--accent-light); }

.stat-delta {
  font-size: 0.75rem;
  margin-top: 0.2rem;
}
.stat-delta.up { color: var(--won); }
.stat-delta.down { color: var(--lost); }

/* ===== Tables ===== */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

thead {
  border-bottom: 2px solid var(--border);
}

th {
  text-align: left;
  padding: 0.6rem;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th:hover {
  color: var(--text-primary);
}

th .sort-arrow {
  font-size: 0.65rem;
  margin-left: 0.2rem;
  opacity: 0.5;
}

th.sorted .sort-arrow {
  opacity: 1;
  color: var(--accent-light);
}

td {
  padding: 0.6rem;
  border-bottom: 1px solid var(--border);
}

tr:hover {
  background: var(--bg-secondary);
}

.table-wrapper {
  overflow-x: auto;
}

/* ===== Charts ===== */
.chart-container {
  position: relative;
  height: 280px;
  width: 100%;
}

.chart-container-sm {
  position: relative;
  height: 200px;
  width: 100%;
}

.chart-placeholder {
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  border: 1px dashed var(--border);
  border-radius: 6px;
}

/* ===== Status badges ===== */
.status {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}

.status-stock { background: var(--stock); color: var(--bg-primary); }
.status-testing { background: var(--testing); color: var(--bg-primary); }
.status-won { background: var(--won); color: var(--bg-primary); }
.status-lost { background: var(--lost); color: var(--bg-primary); }
.status-active { background: var(--accent); color: white; }
.status-retired { background: #484f58; color: var(--text-secondary); }

/* ===== Filter tabs ===== */
.filter-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.filter-tab {
  padding: 0.4rem 0.9rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.filter-tab:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.filter-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* ===== Progress bar ===== */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-primary);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}

.progress-fill.accent { background: var(--accent); }
.progress-fill.won { background: var(--won); }
.progress-fill.lost { background: var(--lost); }
.progress-fill.testing { background: var(--testing); }

/* ===== Mini bar (for metric ratios) ===== */
.mini-bars {
  display: flex;
  gap: 2px;
  align-items: flex-end;
  height: 24px;
}

.mini-bar {
  width: 6px;
  border-radius: 2px;
  min-height: 2px;
}

/* ===== Hypothesis detail row ===== */
.detail-row td {
  padding: 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.detail-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  font-size: 0.85rem;
}

.detail-content dt {
  color: var(--text-secondary);
}

.detail-content dd {
  color: var(--text-primary);
}

.detail-content a {
  color: var(--accent-light);
  text-decoration: none;
}

.detail-content a:hover {
  text-decoration: underline;
}

/* ===== Cycle cards ===== */
.cycle-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  display: flex;
  gap: 1.25rem;
  align-items: flex-start;
}

.cycle-number {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--accent-light);
  min-width: 3rem;
  text-align: center;
}

.cycle-body {
  flex: 1;
}

.cycle-meta {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.cycle-meta strong {
  color: var(--text-primary);
}

.cycle-stats {
  display: flex;
  gap: 0.75rem;
  margin: 0.5rem 0;
  font-size: 0.85rem;
}

.cycle-stats .won { color: var(--won); }
.cycle-stats .lost { color: var(--lost); }
.cycle-stats .testing { color: var(--testing); }

.cycle-notes {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.baseline-change {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-weight: 600;
  font-size: 0.9rem;
}

.baseline-change.up { color: var(--won); }
.baseline-change.down { color: var(--lost); }
.baseline-change.neutral { color: var(--text-secondary); }

/* ===== Date range selector ===== */
.date-range {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.date-btn {
  padding: 0.4rem 1rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.date-btn:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.date-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* ===== KPI Table ===== */
.kpi-achievement {
  font-weight: 700;
  font-size: 0.9rem;
}

.kpi-achievement.good { color: var(--won); }
.kpi-achievement.warn { color: var(--testing); }
.kpi-achievement.bad { color: var(--lost); }

/* ===== Hypothesis mini cards (dashboard) ===== */
.hyp-mini-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.75rem;
}

.hyp-mini-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
}

.hyp-mini-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.hyp-mini-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  margin-right: 0.5rem;
}

.hyp-mini-progress {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* ===== Sparkline area ===== */
.sparkline-container {
  position: relative;
  height: 60px;
  width: 100%;
}

/* ===== Links ===== */
a {
  color: var(--accent-light);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ===== Footer ===== */
footer {
  text-align: center;
  padding: 2rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

footer a {
  color: var(--accent-light);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-secondary);
}

.empty-state p {
  margin-top: 0.5rem;
  font-size: 0.9rem;
}

/* ===== Loading ===== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--text-secondary);
}

.loading::after {
  content: '';
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin-left: 0.75rem;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  table {
    font-size: 0.8rem;
  }

  .nav-links {
    display: none;
    position: absolute;
    top: 56px;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    padding: 0.5rem;
    gap: 0.25rem;
  }

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

  .nav-toggle {
    display: flex;
  }

  .cycle-card {
    flex-direction: column;
    gap: 0.75rem;
  }

  .detail-content {
    grid-template-columns: 1fr;
  }

  .hyp-mini-cards {
    grid-template-columns: 1fr;
  }

  header h1 {
    font-size: 1.2rem;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .filter-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .nav-inner {
    padding: 0 1rem;
  }

  main {
    padding: 1rem;
  }
}
