/* ═══════════════════════════════════════════════════════════════════════
   PalmSight Admin Dashboard — Design System
   Dark mode, glassmorphism, premium feel
   ═══════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.8);
  --bg-glass: rgba(255, 255, 255, 0.03);
  --border: rgba(255, 255, 255, 0.08);
  --border-accent: rgba(99, 102, 241, 0.3);
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --accent: #6366f1;
  --accent-light: #818cf8;
  --green: #10b981;
  --green-soft: rgba(16, 185, 129, 0.15);
  --blue: #3b82f6;
  --blue-soft: rgba(59, 130, 246, 0.15);
  --yellow: #f59e0b;
  --yellow-soft: rgba(245, 158, 11, 0.15);
  --orange: #f97316;
  --orange-soft: rgba(249, 115, 22, 0.15);
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, 0.15);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: all 0.2s ease;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ─── Layout ─────────────────────────────────────────────────────── */

.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.sidebar-brand h1 {
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-light), var(--green));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-brand .version {
  font-size: 0.7rem;
  color: var(--text-muted);
  background: var(--bg-glass);
  padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.sidebar-nav { flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: var(--transition);
  margin-bottom: 4px;
}

.nav-item:hover {
  background: var(--bg-glass);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(99, 102, 241, 0.12);
  color: var(--accent-light);
  border: 1px solid var(--border-accent);
}

.nav-item .icon { font-size: 1.1rem; width: 24px; text-align: center; }

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

.main {
  flex: 1;
  margin-left: 260px;
  padding: 32px;
  max-width: 1200px;
}

/* ─── Page Header ────────────────────────────────────────────────── */

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32px;
}

.page-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
}

.page-header .subtitle {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-top: 4px;
}

/* ─── Cards ──────────────────────────────────────────────────────── */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  backdrop-filter: blur(12px);
  transition: var(--transition);
}

.card:hover {
  border-color: var(--border-accent);
  box-shadow: var(--shadow);
}

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

.card-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.card-header .badge {
  font-size: 0.7rem;
  padding: 3px 10px;
  border-radius: 12px;
  font-weight: 600;
}

/* ─── Stat Cards Grid ────────────────────────────────────────────── */

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

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  backdrop-filter: blur(12px);
}

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

.stat-card .value {
  font-size: 1.75rem;
  font-weight: 700;
}

.stat-card .change {
  font-size: 0.8rem;
  margin-top: 4px;
}

.stat-card .change.positive { color: var(--green); }
.stat-card .change.negative { color: var(--red); }

/* ─── Table ──────────────────────────────────────────────────────── */

.table-container {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead {
  background: rgba(99, 102, 241, 0.06);
}

th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

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

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

/* ─── Rating Badges ──────────────────────────────────────────────── */

.rating {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.rating.strong-buy { background: var(--green-soft); color: var(--green); }
.rating.buy { background: var(--blue-soft); color: var(--blue); }
.rating.hold { background: var(--yellow-soft); color: var(--yellow); }
.rating.sell { background: var(--orange-soft); color: var(--orange); }
.rating.avoid { background: var(--red-soft); color: var(--red); }

/* ─── Score Bar ──────────────────────────────────────────────────── */

.score-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.score-bar .bar {
  flex: 1;
  height: 6px;
  background: var(--bg-glass);
  border-radius: 3px;
  overflow: hidden;
  max-width: 80px;
}

.score-bar .bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

.score-bar .bar-fill.high { background: var(--green); }
.score-bar .bar-fill.medium { background: var(--yellow); }
.score-bar .bar-fill.low { background: var(--red); }

.score-value {
  font-weight: 700;
  font-size: 0.9rem;
  min-width: 36px;
}

/* ─── Activity Log ───────────────────────────────────────────────── */

.activity-list {
  list-style: none;
}

.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

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

.activity-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}

.activity-dot.success { background: var(--green); }
.activity-dot.failed { background: var(--red); }
.activity-dot.partial { background: var(--yellow); }
.activity-dot.started { background: var(--blue); }

.activity-content { flex: 1; }

.activity-content .action {
  font-weight: 500;
  font-size: 0.875rem;
}

.activity-content .time {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ─── Buttons ────────────────────────────────────────────────────── */

.btn {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-light);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--bg-glass);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--red-soft);
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

/* ─── Decision Ledger ────────────────────────────────────────────── */

.decision-change {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
}

.decision-arrow { color: var(--text-muted); }

/* ─── Section layout ─────────────────────────────────────────────── */

.grid-2 {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

.grid-equal {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

/* ─── Engine Control ─────────────────────────────────────────────── */

.job-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.job-card:last-child { border-bottom: none; }

.job-info h4 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.job-info .schedule {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: 'SF Mono', monospace;
}

/* ─── HTMX Indicators ───────────────────────────────────────────── */

.htmx-indicator {
  display: none;
}

.htmx-request .htmx-indicator {
  display: inline-block;
}

.htmx-request.htmx-indicator {
  display: inline-block;
}

/* Loading spinner */
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ─── Responsive ─────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 16px; }
  .stats-grid { grid-template-columns: 1fr; }
  .grid-2, .grid-equal { grid-template-columns: 1fr; }
}

/* ─── Ticker link ────────────────────────────────────────────────── */

a.ticker-link {
  color: var(--accent-light);
  text-decoration: none;
  font-weight: 600;
  transition: var(--transition);
}

a.ticker-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* ─── Empty state ────────────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state .icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

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