/* ===== OpenClaw Shared Design System ===== */

/* Reset */
* { box-sizing: border-box; }

/* ===== Theme Variables (Dark - Default) ===== */
:root {
  /* Background Layers */
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-secondary-flat: #1c2128;
  --bg-input: #21262d;
  --bg-hover: #21262d;
  --bg-surface: #1c2128;

  /* Text - WCAG AA compliant */
  --text-primary: #f0f6fc;
  --text-secondary: #8b949e;
  --text-tertiary: #6e7681;

  /* 5-Core Accent Palette */
  --accent-blue: #58a6ff;
  --accent-green: #3fb950;
  --accent-red: #f85149;
  --accent-orange: #f0883e;
  --accent-gold: #e3b341;

  /* Legacy mappings for compatibility */
  --accent-primary: var(--accent-blue);
  --accent-purple: var(--accent-blue);

  /* Semantic Backgrounds (0.15 opacity for consistency) */
  --bg-success: rgba(63, 185, 80, 0.15);
  --bg-warning: rgba(240, 136, 62, 0.15);
  --bg-danger: rgba(248, 81, 73, 0.15);
  --bg-info: rgba(88, 166, 255, 0.15);
  --bg-gold: rgba(227, 179, 65, 0.10);

  /* Legacy mappings */
  --bg-card-local: var(--bg-success);
  --bg-card-gold: var(--bg-gold);

  /* Status colors */
  --accent-success: #238636;
  --accent-success-hover: #2ea043;

  /* Borders */
  --border-color: #30363d;
  --border-subtle: #21262d;
  --border-local: rgba(63, 185, 80, 0.3);
  --border-gold: rgba(227, 179, 65, 0.3);
  --grid-color: #2a2a2a;

  /* Legacy compatibility */
  --hover-bg: var(--bg-hover);
  --selected-bg: var(--bg-surface);

  /* ===== Spacing Tokens (4px base) ===== */
  --space-0: 0;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* ===== Typography Tokens ===== */
  --font-display: 32px;
  --font-h1: 24px;
  --font-h2: 16px;
  --font-h3: 14px;
  --font-h4: 12px;
  --font-h5: 10px;
  --font-body: 14px;
  --font-small: 12px;
  --font-xs: 11px;
  --font-tiny: 10px;
  --font-value: 24px;
  --font-mono: 12px;

  /* Font Weights */
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;
}

/* ===== Theme Variables (Light) ===== */
[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f6f8fa;
  --bg-secondary-flat: #f6f8fa;
  --bg-input: #f3f4f6;
  --bg-hover: #f3f4f6;
  --bg-surface: #ffffff;

  --text-primary: #1f2328;
  --text-secondary: #57606a;
  --text-tertiary: #6e7781;

  /* 5-Core Accent Palette (Light) */
  --accent-blue: #0969da;
  --accent-green: #1a7f37;
  --accent-red: #cf222e;
  --accent-orange: #bc4c00;
  --accent-gold: #9a6700;

  /* Legacy mappings */
  --accent-primary: var(--accent-blue);
  --accent-purple: var(--accent-blue);

  /* Semantic Backgrounds (light theme) */
  --bg-success: rgba(26, 127, 55, 0.10);
  --bg-warning: rgba(188, 76, 0, 0.10);
  --bg-danger: rgba(207, 34, 46, 0.10);
  --bg-info: rgba(9, 105, 218, 0.10);
  --bg-gold: rgba(154, 103, 0, 0.08);

  /* Legacy mappings */
  --bg-card-local: var(--bg-success);
  --bg-card-gold: var(--bg-gold);

  --accent-success: #1a7f37;
  --accent-success-hover: #238636;

  --border-color: #d0d7de;
  --border-subtle: #eaeef2;
  --border-local: rgba(26, 127, 55, 0.3);
  --border-gold: rgba(154, 103, 0, 0.3);
  --grid-color: #e0e0e0;

  /* Legacy compatibility */
  --hover-bg: var(--bg-hover);
  --selected-bg: var(--bg-surface);
}

/* ===== Base Styles ===== */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  margin: 0;
  padding: 0;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  transition: background-color 0.3s ease, color 0.3s ease;
}

h1 {
  color: var(--accent-primary);
  margin: 0 0 24px 0;
  font-size: 28px;
  font-weight: 600;
}
h1 span {
  font-size: 32px;
}

/* ===== Top Navigation Bar ===== */
.top-nav {
  display: flex;
  align-items: center;
  padding: 0 24px;
  height: 56px;
  background: var(--bg-secondary-flat);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.nav-brand {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin-right: 32px;
  white-space: nowrap;
}

.nav-links {
  display: flex;
  gap: 4px;
}

.nav-link {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.nav-link:hover {
  background: var(--hover-bg);
  color: var(--text-primary);
}
.nav-link.active {
  background: var(--hover-bg);
  color: var(--accent-primary);
  font-weight: 600;
}

.top-nav .theme-toggle {
  margin-left: auto;
}

@media (max-width: 600px) {
  .top-nav {
    padding: 0 12px;
    height: 48px;
  }
  .nav-brand {
    font-size: 15px;
    margin-right: 12px;
  }
  .nav-link {
    padding: 6px 10px;
    font-size: 13px;
  }
}

/* ===== Card Component ===== */
.card {
  background: var(--bg-secondary);
  padding: 20px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
}

.card h3 {
  margin: 0 0 12px 0;
  color: var(--accent-primary);
  font-size: 14px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card--local {
  background: var(--bg-card-local);
  border-color: var(--border-local);
}
.card--local h3 {
  color: var(--accent-green);
}

.card--gold {
  background: var(--bg-card-gold);
  border-color: var(--border-gold);
}
.card--gold h3 {
  color: var(--accent-gold);
}

/* ===== Dashboard Grid ===== */
.dashboard {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.dashboard--3col {
  grid-template-columns: repeat(3, 1fr);
}

@media (max-width: 1024px) {
  .dashboard {
    grid-template-columns: repeat(2, 1fr);
  }
  .dashboard--3col {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .dashboard,
  .dashboard--3col {
    grid-template-columns: 1fr;
  }
}

/* ===== Chart Container ===== */
.chart-container {
  background: var(--bg-secondary);
  padding: 20px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  margin-bottom: 24px;
}

.chart-container h2 {
  margin: 0 0 16px 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.chart-wrapper {
  position: relative;
  height: 280px;
}

canvas {
  width: 100% !important;
}

/* ===== Two-column chart layout ===== */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
.charts-row .chart-container {
  margin-bottom: 0;
}
@media (max-width: 1024px) {
  .charts-row {
    grid-template-columns: 1fr;
  }
  .charts-row .chart-container {
    margin-bottom: 24px;
  }
}

/* ===== Button Styles ===== */
button {
  cursor: pointer;
}

.export-btn {
  background: var(--accent-success);
  border: 1px solid var(--accent-success-hover);
  color: white;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
}
.export-btn:hover {
  background: var(--accent-success-hover);
}

/* ===== Theme Toggle Button ===== */
.theme-toggle {
  background: var(--bg-secondary-flat);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
  padding: 0;
}
.theme-toggle:hover {
  transform: scale(1.1);
}

/* ===== Refresh Note ===== */
.refresh-note {
  text-align: center;
  color: var(--text-secondary);
  font-size: 12px;
  margin-top: 16px;
}

/* ===== Scrollbar Styling ===== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* ===== Empty/Loading States ===== */
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: var(--text-secondary);
  gap: 12px;
}
.loading-spinner::before {
  content: '';
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-color);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
  font-size: 15px;
}
.empty-state a {
  color: var(--accent-primary);
  cursor: pointer;
  text-decoration: underline;
}
