:root {
  --bg-main: #f8f6f3;
  --bg-card: #ffffff;
  --bg-sidebar: #2d2a26;
  --bg-sidebar-hover: #3d3a36;
  --bg-sidebar-active: #4d4a46;

  --text-primary: #2d2a26;
  --text-secondary: #6b6560;
  --text-muted: #9b9590;
  --text-sidebar: #d4cfc8;
  --text-sidebar-active: #ffffff;

  --primary: #8b7355;
  --primary-light: #a89070;
  --primary-bg: rgba(139, 115, 85, 0.08);

  --success: #5a8f5a;
  --success-bg: rgba(90, 143, 90, 0.1);
  --warning: #c9a35c;
  --warning-bg: rgba(201, 163, 92, 0.1);
  --danger: #c47058;
  --danger-bg: rgba(196, 112, 88, 0.1);
  --info: #5a7f9f;
  --info-bg: rgba(90, 127, 159, 0.1);

  --border-color: #e8e4df;
  --border-light: #f0ece7;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.10);

  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 20px;

  --sidebar-width: 260px;
  --transition: 0.2s ease;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ───────────────────────────── */

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 10;
}

.sidebar-header {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: var(--primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.5px;
}

.logo-title {
  display: block;
  color: #fff;
  font-weight: 600;
  font-size: 15px;
}

.logo-subtitle {
  display: block;
  color: var(--text-sidebar);
  font-size: 11px;
  font-weight: 400;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-sidebar);
  text-decoration: none;
  font-size: 13px;
  font-weight: 400;
  transition: background var(--transition), color var(--transition);
  white-space: normal;
}

.nav-item:hover {
  background: var(--bg-sidebar-hover);
  color: #fff;
}

.nav-item.active {
  background: var(--bg-sidebar-active);
  color: var(--text-sidebar-active);
  font-weight: 500;
}

.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  display: none;
}

.nav-badge:not(:empty) {
  display: inline-block;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.agent-status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-sidebar);
  font-size: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-dot.running {
  background: var(--success);
  box-shadow: 0 0 6px rgba(90, 143, 90, 0.5);
}

.status-dot.stopped {
  background: var(--danger);
}

/* ── Content ───────────────────────────── */

.content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 32px;
  min-height: 100vh;
}

.content-view {
  display: none;
}

.content-view.active {
  display: block;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.view-header h1 {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
}

.view-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.last-update {
  color: var(--text-muted);
  font-size: 12px;
}

.filter-select {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-card);
  cursor: pointer;
}

/* ── Stats Grid ────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.stat-card .stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: none;
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.stat-card .stat-detail {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.stat-card.critical .stat-value { color: var(--danger); }
.stat-card.warning .stat-value { color: var(--warning); }
.stat-card.success .stat-value { color: var(--success); }
.stat-card.info .stat-value { color: var(--info); }

/* ── Section ───────────────────────────── */

.section {
  margin-bottom: 32px;
}

.section h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}

/* ── Health Grid ───────────────────────── */

.health-grid, .health-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.health-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 14px;
}

.health-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.health-indicator.healthy { background: var(--success); box-shadow: 0 0 6px rgba(90, 143, 90, 0.4); }
.health-indicator.degraded { background: var(--warning); box-shadow: 0 0 6px rgba(201, 163, 92, 0.4); }
.health-indicator.unhealthy { background: var(--danger); box-shadow: 0 0 6px rgba(196, 112, 88, 0.4); }
.health-indicator.unknown { background: var(--text-muted); }

.health-info {
  flex: 1;
}

.health-system {
  font-weight: 500;
  font-size: 14px;
  color: var(--text-primary);
}

.health-status {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ── Events List ───────────────────────── */

.events-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.event-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition);
}

.event-item:hover {
  box-shadow: var(--shadow-md);
}

.event-severity {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}

.event-severity.critical { background: var(--danger); }
.event-severity.high { background: var(--warning); }
.event-severity.medium { background: var(--info); }
.event-severity.low { background: var(--text-muted); }

.event-body {
  flex: 1;
  min-width: 0;
}

.event-summary {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: normal;
}

.event-meta {
  display: flex;
  gap: 16px;
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.event-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 500;
}

.event-badge.domain {
  background: var(--primary-bg);
  color: var(--primary);
}

.event-badge.sensor {
  background: var(--info-bg);
  color: var(--info);
}

.event-actions {
  flex-shrink: 0;
}

.btn-resolve {
  padding: 6px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-resolve:hover {
  background: var(--success-bg);
  color: var(--success);
  border-color: var(--success);
}

/* ── Intelligence ──────────────────────── */

.intel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.intel-grid .section:last-child {
  grid-column: 1 / -1;
}

.skills-list, .patterns-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.skill-item, .pattern-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}

.skill-header, .pattern-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.skill-id, .pattern-id {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
}

.confidence-bar {
  width: 60px;
  height: 4px;
  background: var(--border-color);
  border-radius: 2px;
  overflow: hidden;
}

.confidence-fill {
  height: 100%;
  border-radius: 2px;
  transition: width var(--transition);
}

.confidence-fill.high { background: var(--success); }
.confidence-fill.medium { background: var(--warning); }
.confidence-fill.low { background: var(--danger); }

.skill-desc, .pattern-desc {
  font-size: 13px;
  color: var(--text-secondary);
}

.skill-meta, .pattern-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ── AI Usage ──────────────────────────── */

.ai-usage {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.ai-stat-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-light);
}

.ai-stat-row:last-child {
  border-bottom: none;
}

.ai-stat-label {
  color: var(--text-secondary);
  font-size: 13px;
}

.ai-stat-value {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-primary);
}

/* ── Logs ──────────────────────────────── */

.logs-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.log-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.log-time {
  color: var(--text-muted);
  white-space: nowrap;
  font-size: 11px;
}

.log-action {
  color: var(--primary);
  font-weight: 500;
  white-space: normal;
}

.log-domain {
  color: var(--text-secondary);
}

.log-result {
  margin-left: auto;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 10px;
  font-weight: 600;
}

.log-result.success { background: var(--success-bg); color: var(--success); }
.log-result.failure { background: var(--danger-bg); color: var(--danger); }
.log-result.skipped { background: var(--info-bg); color: var(--info); }

/* ── Empty State ───────────────────────── */

.empty-state {
  text-align: center;
  padding: 48px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ── Responsive ────────────────────────── */

@media (max-width: 1024px) {
  .intel-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .sidebar {
    width: 60px;
  }

  .sidebar .logo-text,
  .sidebar .nav-item span,
  .sidebar .agent-status span {
    display: none;
  }

  .sidebar .nav-item {
    justify-content: center;
    padding: 12px;
  }

  .content {
    margin-left: 60px;
    padding: 20px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
