:root {
  --bg-dark: #0f172a;
  --bg-card: rgba(15, 23, 42, 0.85);
  --border-color: rgba(148, 163, 184, 0.15);
  --text-primary: #f8fafc;
  --text-secondary: rgba(226, 232, 240, 0.88);
  --accent-blue: #6366f1;
  --accent-green: #22c55e;
  --accent-yellow: #eab308;
  --accent-red: #ef4444;
  --accent-purple: #a855f7;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", system-ui, sans-serif;
  background: linear-gradient(180deg, #0f172a 0%, #111827 100%);
  color: var(--text-primary);
  min-height: 100vh;
}

/* Header */
.header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}

.header h1 {
  margin: 0;
  font-size: 1.5rem;
}

.header-subtitle {
  margin: 0 0 1rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.status {
  display: inline-block;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.8rem;
  background: rgba(14, 165, 233, 0.18);
  border: 1px solid rgba(14, 165, 233, 0.4);
  color: #e0f2fe;
}

.status.status--success {
  background: rgba(34, 197, 94, 0.18);
  border-color: rgba(74, 222, 128, 0.4);
  color: #bbf7d0;
}

.status.status--error {
  background: rgba(239, 68, 68, 0.16);
  border-color: rgba(248, 113, 113, 0.35);
  color: #fecaca;
}

/* Web Vitals Bar */
.vitals-bar {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

.vital {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  transition: border-color 0.3s, background 0.3s;
}

.vital--good {
  border-color: rgba(34, 197, 94, 0.5);
  background: rgba(34, 197, 94, 0.1);
}

.vital--needs-improvement {
  border-color: rgba(234, 179, 8, 0.5);
  background: rgba(234, 179, 8, 0.1);
}

.vital--poor {
  border-color: rgba(239, 68, 68, 0.5);
  background: rgba(239, 68, 68, 0.1);
}

.vital-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.vital-value {
  font-size: 1.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.vital-unit {
  font-size: 0.7rem;
  color: var(--text-secondary);
}

/* Main Layout */
.main {
  display: flex;
  min-height: calc(100vh - 180px);
}

/* Sidebar */
.sidebar {
  width: 320px;
  min-width: 320px;
  background: var(--bg-card);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: relative;
  transition: width 0.3s, min-width 0.3s;
}

.sidebar.collapsed {
  width: 40px;
  min-width: 40px;
}

.sidebar.collapsed .sidebar-content {
  display: none;
}

.sidebar-toggle {
  position: absolute;
  right: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 48px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 0 8px 8px 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  z-index: 10;
  transition: color 0.2s;
}

.sidebar-toggle:hover {
  color: var(--text-primary);
}

.sidebar.collapsed .sidebar-toggle {
  right: -24px;
}

.sidebar.collapsed .toggle-icon {
  transform: rotate(180deg);
}

.toggle-icon {
  font-size: 0.7rem;
  transition: transform 0.3s;
}

.sidebar-content {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.sidebar-content h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

/* SQL Examples */
.sql-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.example {
  padding: 0.35rem 0.6rem;
  border: none;
  border-radius: 999px;
  background: rgba(96, 165, 250, 0.16);
  color: #bfdbfe;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.example:hover:not(:disabled) {
  background: rgba(96, 165, 250, 0.28);
}

.example:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#sql {
  width: 100%;
  min-height: 100px;
  padding: 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: rgba(15, 23, 42, 0.75);
  color: var(--text-primary);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.75rem;
  resize: vertical;
}

#sql:focus {
  outline: none;
  border-color: var(--accent-blue);
}

.actions {
  margin: 0.6rem 0;
}

#run-query {
  width: 100%;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

#run-query:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.35);
}

#run-query:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.query-results {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 150px;
  overflow: hidden;
}

.query-results h3 {
  margin: 0 0 0.4rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.query-results perspective-viewer {
  flex: 1;
  min-height: 120px;
}

/* Dashboard */
.dashboard {
  flex: 1;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-y: auto;
}

/* Gauges Row */
.gauges-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.gauge-card {
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gauge-ring {
  position: relative;
  width: 100px;
  height: 100px;
}

.gauge-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.gauge-bg {
  fill: none;
  stroke: rgba(100, 116, 139, 0.2);
  stroke-width: 8;
}

.gauge-fill {
  fill: none;
  stroke: var(--accent-green);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 283;
  stroke-dashoffset: 283;
  transition: stroke-dashoffset 0.5s ease-out, stroke 0.3s;
}

.gauge-fill--accent {
  stroke: var(--accent-purple);
}

.gauge-fill--warning {
  stroke: var(--accent-yellow);
}

.gauge-fill--danger {
  stroke: var(--accent-red);
}

.gauge-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.gauge-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.gauge-label {
  display: block;
  font-size: 0.65rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  margin-top: 0.2rem;
}

/* Stats Card */
.gauge-card--stats {
  flex-direction: column;
  gap: 0.5rem;
  min-width: 150px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  width: 100%;
  gap: 1rem;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.stat-value {
  font-size: 0.85rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Charts Row */
.charts-row {
  display: flex;
  gap: 1rem;
}

.chart-card {
  flex: 1;
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  min-height: 250px;
}

.chart-card h3 {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chart-card perspective-viewer {
  flex: 1;
  min-height: 180px;
}

/* Tables Row */
.tables-row {
  display: flex;
  gap: 1rem;
}

.table-card {
  flex: 1;
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  min-height: 200px;
}

.table-card h3 {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.table-card perspective-viewer {
  flex: 1;
  min-height: 140px;
}

.widget-count {
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.25);
  color: #a5b4fc;
}

/* Playground Row */
.playground-row {
  margin-top: auto;
}

.playground-card {
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1rem;
}

.playground-card h3 {
  margin: 0 0 0.25rem;
  font-size: 0.9rem;
}

.playground-card > p {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

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

.playground-section h4 {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.playground-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.playground-buttons button {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: rgba(30, 41, 59, 0.8);
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.playground-buttons button:hover {
  background: rgba(99, 102, 241, 0.2);
  border-color: var(--accent-blue);
}

#btn-error,
#btn-layout-shift,
#btn-long-task {
  border-color: rgba(248, 113, 113, 0.3);
}

#btn-error:hover,
#btn-layout-shift:hover,
#btn-long-task:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: var(--accent-red);
}

/* Scroll Content */
.scroll-content {
  max-height: 100px;
  overflow-y: auto;
  background: rgba(15, 23, 42, 0.5);
  border-radius: 6px;
  padding: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.scroll-spacer {
  height: 200px;
}

/* Footer */
.footer {
  text-align: center;
  padding: 0.75rem;
  color: var(--text-secondary);
  font-size: 0.8rem;
  border-top: 1px solid var(--border-color);
}

.footer a {
  color: #93c5fd;
}

/* Perspective Viewer Styling */
perspective-viewer {
  --plugin--background: transparent;
  --plugin--font-family: "Inter", system-ui, sans-serif;
}

/* Responsive */
@media (max-width: 1200px) {
  .playground-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 900px) {
  .main {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    min-width: 100%;
    max-height: 300px;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }

  .sidebar-toggle {
    display: none;
  }

  .tables-row {
    flex-direction: column;
  }

  .playground-grid {
    grid-template-columns: 1fr;
  }
}
