/* ============================================================
   Apex OpenClaw Dashboard — Premium Dark Theme
   Inspired by Linear.app / Vercel dashboard aesthetic
   ============================================================ */

/* ---------- CSS Variables ---------- */
:root {
  --bg-base: #0a0f1a;
  --bg-surface: #111827;
  --bg-elevated: #1a2332;
  --bg-hover: #1f2937;
  --bg-input: #0d1424;
  --border-subtle: #1f2937;
  --border-muted: rgba(148, 163, 184, 0.08);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-faint: #475569;
  --accent-blue: #3b82f6;
  --accent-blue-hover: #2563eb;
  --accent-blue-muted: rgba(59, 130, 246, 0.12);
  --accent-green: #22c55e;
  --accent-green-muted: rgba(34, 197, 94, 0.12);
  --accent-amber: #f59e0b;
  --accent-amber-muted: rgba(245, 158, 11, 0.12);
  --accent-red: #ef4444;
  --accent-red-muted: rgba(239, 68, 68, 0.12);
  --accent-purple: #a78bfa;
  --accent-purple-muted: rgba(167, 139, 250, 0.12);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --shadow-card: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --shadow-elevated: 0 4px 12px rgba(0,0,0,0.4), 0 2px 4px rgba(0,0,0,0.3);
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- Layout ---------- */
.container {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 220px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  padding: 20px 12px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar h2 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  padding: 0 10px;
  margin-bottom: 24px;
  background: linear-gradient(135deg, #60a5fa, #3b82f6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

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

.sidebar a,
.sidebar a.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
}

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

.sidebar a.active {
  background: var(--accent-blue-muted);
  color: var(--accent-blue);
  font-weight: 600;
}

.sidebar a.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: var(--accent-blue);
  border-radius: 0 3px 3px 0;
}

.sidebar .mt-8 {
  margin-top: auto;
  padding: 12px 10px;
  border-top: 1px solid var(--border-subtle);
}

.sidebar .mt-8 p {
  font-size: 11px;
  color: var(--text-faint);
}

.sidebar .mt-8 .mt-1 {
  margin-top: 4px;
}

/* ---------- Main Content ---------- */
.main {
  flex: 1;
  padding: 28px 32px;
  overflow-y: auto;
  max-width: 1400px;
}

.main > .space-y-6 > * + * {
  margin-top: 24px;
}

/* ---------- Header ---------- */
.main > header,
header.flex {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-subtle);
}

header h1,
#page-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

header p,
#page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.card:hover {
  border-color: rgba(148, 163, 184, 0.15);
}

.card.p-4 { padding: 20px; }
.card.p-6 { padding: 24px; }
.card.p-8 { padding: 32px; }

/* ---------- Stat Cards (overview top row) ---------- */
.grid .card > p:first-child {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.grid .card .text-2xl,
.grid .card p.text-2xl {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  line-height: 1.2;
}

.grid .card .font-mono {
  font-family: 'JetBrains Mono', 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
}

.grid .card .text-xs {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Gradient accent on stat cards */
.grid.grid-cols-1.md\:grid-cols-2.lg\:grid-cols-4 > .card:nth-child(1) {
  border-top: 2px solid var(--accent-blue);
}
.grid.grid-cols-1.md\:grid-cols-2.lg\:grid-cols-4 > .card:nth-child(2) {
  border-top: 2px solid var(--accent-green);
}
.grid.grid-cols-1.md\:grid-cols-2.lg\:grid-cols-4 > .card:nth-child(3) {
  border-top: 2px solid var(--accent-amber);
}
.grid.grid-cols-1.md\:grid-cols-2.lg\:grid-cols-4 > .card:nth-child(4) {
  border-top: 2px solid var(--accent-purple);
}

/* Cost cards gradient accents */
.grid.grid-cols-1.md\:grid-cols-3 > .card:nth-child(1) {
  border-top: 2px solid var(--accent-green);
}
.grid.grid-cols-1.md\:grid-cols-3 > .card:nth-child(2) {
  border-top: 2px solid var(--accent-blue);
}
.grid.grid-cols-1.md\:grid-cols-3 > .card:nth-child(3) {
  border-top: 2px solid var(--accent-amber);
}

/* ---------- Grid System ---------- */
.grid { display: grid; }
.grid-cols-1 { grid-template-columns: 1fr; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.gap-6 { gap: 24px; }

@media (min-width: 768px) {
  .md\:grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
  .md\:grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1024px) {
  .lg\:grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
  .lg\:grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
  .lg\:grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- Sections ---------- */
.section { display: none; }
.section.active { display: block; }

/* ---------- Tables ---------- */
table {
  width: 100%;
  border-collapse: collapse;
}

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

thead th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 10px 16px;
  text-align: left;
}

thead.bg-slate-800 {
  background: var(--bg-elevated);
}

thead.text-slate-400 th {
  color: var(--text-muted);
}

tbody tr {
  border-bottom: 1px solid var(--border-muted);
  transition: background var(--transition-fast);
}

tbody tr:hover,
tr.hover\:bg-slate-800\/30:hover {
  background: rgba(59, 130, 246, 0.04);
}

tbody td {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-secondary);
}

tbody td:first-child {
  color: var(--text-primary);
}

.border-b.border-slate-700\/50 {
  border-bottom: 1px solid var(--border-muted);
}

.border-t.border-slate-700 {
  border-top: 1px solid var(--border-muted);
}

/* ---------- Status Dots ---------- */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  position: relative;
}

.status-active, .status-online {
  background: var(--accent-green);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.4);
}

.status-inactive, .status-offline {
  background: var(--accent-red);
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.4);
}

.status-unknown {
  background: var(--accent-amber);
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.4);
}

/* Pulse animation for active status */
.status-active::after, .status-online::after {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  border: 1px solid var(--accent-green);
  animation: pulse-ring 2s ease-out infinite;
  opacity: 0;
}

@keyframes pulse-ring {
  0% { transform: scale(1); opacity: 0.5; }
  100% { transform: scale(2); opacity: 0; }
}

/* ---------- Buttons ---------- */
.btn {
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  color: #fff;
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1.4;
}

.btn:active {
  transform: scale(0.97);
}

.btn-blue {
  background: var(--accent-blue);
  box-shadow: 0 1px 3px rgba(59, 130, 246, 0.3);
}

.btn-blue:hover {
  background: var(--accent-blue-hover);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
}

.btn-slate {
  background: var(--bg-hover);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.btn-slate:hover {
  background: rgba(148, 163, 184, 0.12);
  color: var(--text-primary);
  border-color: rgba(148, 163, 184, 0.2);
}

/* ---------- Form Inputs ---------- */
select, input[type="text"], input[type="number"], input[type="email"] {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text-primary);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
  font-family: inherit;
}

select:focus, input:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px var(--accent-blue-muted);
}

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* ---------- Chat Section ---------- */
#chat-messages {
  height: 440px;
  overflow-y: auto;
  scroll-behavior: smooth;
  padding: 16px;
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}

#chat-messages::-webkit-scrollbar {
  width: 6px;
}

#chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

#chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 3px;
}

.chat-msg {
  padding: 10px 14px;
  margin: 6px 0;
  border-radius: var(--radius-lg);
  max-width: 75%;
  word-wrap: break-word;
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.5;
  animation: msg-in 0.2s ease-out;
}

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

.chat-user {
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  color: #fff;
  margin-left: auto;
  text-align: right;
  border-bottom-right-radius: 4px;
}

.chat-assistant {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.chat-system {
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  text-align: center;
  max-width: 100%;
  padding: 6px 12px;
  font-style: italic;
}

/* ---------- Upload Zone ---------- */
.upload-zone {
  border: 2px dashed var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-normal);
  background: transparent;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent-blue);
  background: var(--accent-blue-muted);
}

.upload-zone p {
  color: var(--text-muted);
}

.upload-zone:hover p,
.upload-zone.dragover p {
  color: var(--text-secondary);
}

/* ---------- Badges ---------- */
.nav-badge {
  background: var(--accent-red);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  border-radius: 9999px;
  padding: 1px 7px;
  margin-left: 8px;
  line-height: 1.4;
  animation: badge-pulse 2s ease-in-out infinite;
}

@keyframes badge-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Inline badges (file types, statuses) */
.bg-slate-700 {
  background: var(--bg-hover);
}

.bg-blue-500\/20 {
  background: var(--accent-blue-muted);
}

.bg-purple-500\/20 {
  background: var(--accent-purple-muted);
}

.text-blue-400 {
  color: var(--accent-blue);
}

.text-purple-400 {
  color: var(--accent-purple);
}

.text-red-400 {
  color: var(--accent-red);
}

.text-blue-400:hover,
.hover\:text-blue-300:hover {
  color: #60a5fa;
}

/* ---------- Alert Cards ---------- */
.border-l-4 {
  border-left-width: 4px;
  border-left-style: solid;
}

.border-red-500 {
  border-left-color: var(--accent-red) !important;
}

.border-yellow-500 {
  border-left-color: var(--accent-amber) !important;
}

/* ---------- Progress Bars ---------- */
.h-2 {
  height: 8px;
}

.bg-slate-800 {
  background: var(--bg-elevated);
}

.bg-blue-600 {
  background: var(--accent-blue);
}

.w-full {
  width: 100%;
}

.rounded {
  border-radius: var(--radius-sm);
}

/* ---------- Hidden Utility ---------- */
.hidden { display: none !important; }

/* ---------- Spacing Utilities ---------- */
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-8 { margin-top: 32px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.ml-4 { margin-left: 16px; }
.mr-2 { margin-right: 8px; }
.p-3 { padding: 12px; }
.px-2 { padding-left: 8px; padding-right: 8px; }
.px-3 { padding-left: 12px; padding-right: 12px; }
.px-4 { padding-left: 16px; padding-right: 16px; }
.py-0\.5 { padding-top: 2px; padding-bottom: 2px; }
.py-2 { padding-top: 8px; padding-bottom: 8px; }
.py-4 { padding-top: 16px; padding-bottom: 16px; }
.pr-4 { padding-right: 16px; }

/* ---------- Flex Utilities ---------- */
.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.items-start { align-items: start; }
.justify-between { justify-content: space-between; }
.self-center { align-self: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

/* ---------- Text Utilities ---------- */
.text-xs { font-size: 12px; }
.text-sm { font-size: 13px; }
.text-lg { font-size: 18px; }
.text-xl { font-size: 20px; }
.text-2xl { font-size: 28px; }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-medium { font-weight: 500; }
.font-mono { font-family: 'JetBrains Mono', 'SF Mono', 'Cascadia Code', monospace; }
.text-left { text-align: left; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.underline { text-decoration: underline; }
.text-slate-300 { color: var(--text-primary); }
.text-slate-400 { color: var(--text-secondary); }
.text-slate-500 { color: var(--text-muted); }
.text-slate-600 { color: var(--text-faint); }

/* ---------- Size Utilities ---------- */
.w-64 { width: 256px; }
.w-1\/2 { width: 50%; }
.min-w-full { min-width: 100%; }
.max-w-2xl { max-width: 672px; }

/* ---------- Overflow & Layout ---------- */
.overflow-auto { overflow: auto; }
.space-y-2 > * + * { margin-top: 8px; }
.space-y-3 > * + * { margin-top: 12px; }
.space-y-4 > * + * { margin-top: 16px; }
.space-y-6 > * + * { margin-top: 24px; }
.block { display: block; }
.inline-block { display: inline-block; }

/* ---------- Transition Utility ---------- */
.transition-all { transition: all var(--transition-fast); }

/* ---------- Border Radius ---------- */
.rounded-lg { border-radius: var(--radius-md); }
.rounded-xl { border-radius: var(--radius-lg); }

/* ---------- Scrollbar Styling ---------- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

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

::-webkit-scrollbar-thumb:hover {
  background: var(--text-faint);
}

/* ---------- Canvas Charts ---------- */
canvas {
  width: 100% !important;
}

/* ---------- Links ---------- */
a {
  transition: color var(--transition-fast);
}

/* ---------- Nav Item Icons (via ::before pseudo-elements) ---------- */
.nav-item[data-section="overview"]::before { content: ''; }
.nav-item[data-section="agents"]::before { content: ''; }
.nav-item[data-section="wordpress"]::before { content: ''; }
.nav-item[data-section="files"]::before { content: ''; }
.nav-item[data-section="notion"]::before { content: ''; }
.nav-item[data-section="chat"]::before { content: ''; }
.nav-item[data-section="tasks"]::before { content: ''; }
.nav-item[data-section="alerts"]::before { content: ''; }
.nav-item[data-section="settings"]::before { content: ''; }

/* Override for active state — icons use different pseudo */
.sidebar a.active::before {
  content: '';
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .sidebar {
    width: 60px;
    padding: 12px 6px;
  }
  .sidebar h2 {
    font-size: 0;
    height: 24px;
  }
  .sidebar a {
    justify-content: center;
    font-size: 0;
    padding: 10px;
  }
  .sidebar .nav-icon {
    font-size: 18px;
  }
  .sidebar .nav-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    margin: 0;
    font-size: 8px;
    padding: 0 4px;
  }
  .sidebar .mt-8 {
    display: none;
  }
  .main {
    padding: 16px;
  }
}
