:root {
  --color-primary: #0078d4;
  --color-primary-dark: #005a9e;
  --color-bg: #f3f2f1;
  --color-surface: #ffffff;
  --color-text: #323130;
  --color-text-secondary: #605e5c;
  --color-border: #edebe9;
  --color-success: #107c10;
  --color-warning: #ffb900;
  --color-danger: #d13438;
  --radius: 8px;
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  color-scheme: light dark;
}

/* Dark mode */
[data-theme="dark"] {
  --color-primary: #4db8ff;
  --color-primary-dark: #2899e6;
  --color-bg: #1b1b1b;
  --color-surface: #2d2d2d;
  --color-text: #e5e5e5;
  --color-text-secondary: #a0a0a0;
  --color-border: #404040;
  --color-success: #4caf50;
  --color-warning: #ffca28;
  --color-danger: #ef5350;
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .navbar { background: #1a3a5c; }
[data-theme="dark"] .flash-notice { background: #1b3d1b; color: var(--color-success); }
[data-theme="dark"] .flash-alert { background: #3d1b1b; color: var(--color-danger); }
[data-theme="dark"] .rate-limit-banner { background: #3d3000; border-color: var(--color-warning); }
[data-theme="dark"] .rate-limit-content { color: var(--color-warning); }
[data-theme="dark"] .loading-overlay { background: rgba(27, 27, 27, 0.85); }
[data-theme="dark"] .status-succeeded,
[data-theme="dark"] .status-enabled,
[data-theme="dark"] .status-running { background: #1b3d1b; color: var(--color-success); }
[data-theme="dark"] .status-failed,
[data-theme="dark"] .status-disabled { background: #3d1b1b; color: var(--color-danger); }
[data-theme="dark"] .status-creating,
[data-theme="dark"] .status-updating,
[data-theme="dark"] .status-warned { background: #3d3000; color: var(--color-warning); }
[data-theme="dark"] .status-unknown { background: var(--color-border); color: var(--color-text-secondary); }
[data-theme="dark"] .subscription-selector select,
[data-theme="dark"] .filter-panel .filter-group input,
[data-theme="dark"] .filter-panel .filter-group select { color: var(--color-text); background: var(--color-surface); }

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

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
}

/* Navbar */
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--color-primary);
  color: white;
  padding: 0.75rem 1.5rem;
  box-shadow: var(--shadow);
}

.navbar-brand {
  font-size: 1.1rem;
  font-weight: 600;
}

.navbar-menu {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.navbar-user { font-size: 0.9rem; }

/* Theme toggle */
.btn-theme {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  border-radius: var(--radius);
  transition: background 0.15s;
}

.btn-theme:hover { background: rgba(255, 255, 255, 0.15); }

.btn-theme img { width: 18px; height: 18px; filter: brightness(0) invert(1); }

/* Light mode: show moon (to switch to dark), hide sun */
.icon-sun { display: none; }
.icon-moon { display: block; }

/* Dark mode: show sun (to switch to light), hide moon */
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

/* Container */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  text-decoration: none;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s;
}

.btn:hover { background: var(--color-bg); }

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

.btn-primary:hover { background: var(--color-primary-dark); }

.btn-lg { padding: 0.75rem 2rem; font-size: 1rem; }

.btn-sm { padding: 0.25rem 0.75rem; font-size: 0.8rem; }

/* Flash messages */
.flash {
  padding: 0.75rem 1.5rem;
  margin-bottom: 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.flash-notice { background: #dff6dd; color: #107c10; }
.flash-alert { background: #fde7e9; color: #d13438; }

/* Login */
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 80vh;
}

.login-card {
  background: var(--color-surface);
  padding: 3rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
  max-width: 400px;
}

.login-card h1 {
  margin-bottom: 0.5rem;
  color: var(--color-primary);
}

.login-card p {
  margin-bottom: 1.5rem;
  color: var(--color-text-secondary);
}

/* Dashboard header */
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.subscription-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.subscription-selector select {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  background: var(--color-surface);
}

/* Summary cards */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.card {
  background: var(--color-surface);
  padding: 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-label {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.25rem;
}

.card-value {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--color-text);
}

/* Charts */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.chart-container {
  background: var(--color-surface);
  padding: 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.chart-container.full-width {
  margin-bottom: 1.5rem;
}

.chart-container h3 {
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
  color: var(--color-text-secondary);
}

.chart-container canvas {
  max-height: 300px;
}

.chart-container canvas.treemap-canvas {
  max-height: 400px;
}

/* Sections */
.section {
  background: var(--color-surface);
  padding: 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

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

/* Tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.data-table th,
.data-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

.data-table th {
  background: var(--color-bg);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-secondary);
}

.data-table td { font-size: 0.9rem; }

.data-table code {
  font-size: 0.8rem;
  background: var(--color-bg);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

.empty-cell {
  text-align: center;
  color: var(--color-text-secondary);
  padding: 2rem !important;
}

/* Filters */
.filters {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.filter-group label {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
}

.filter-group input,
.filter-group select {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

/* Status badges */
.status-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}

.status-succeeded,
.status-enabled,
.status-running { background: #dff6dd; color: var(--color-success); }

.status-failed,
.status-disabled { background: #fde7e9; color: var(--color-danger); }

.status-creating,
.status-updating,
.status-warned { background: #fff4ce; color: #8a6900; }

.status-unknown { background: var(--color-bg); color: var(--color-text-secondary); }

/* Tag badges */
.tag-badge {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.7rem;
  background: var(--color-border);
  color: var(--color-text-secondary);
  margin: 0.1rem 0.2rem;
  white-space: nowrap;
}

/* Rate limit banner */
.rate-limit-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff4ce;
  border: 1px solid var(--color-warning);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  margin-bottom: 1.5rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.rate-limit-content {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  color: #8a6900;
}

.rate-limit-banner .btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Loading overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.8);
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.loading-overlay.loading-visible {
  opacity: 1;
  pointer-events: all;
}

.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  color: var(--color-primary);
  font-weight: 600;
  font-size: 0.95rem;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Filter panel */
.filter-panel {
  background: var(--color-surface);
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.filter-row {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.filter-panel .filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.filter-panel .filter-group label {
  font-size: 0.75rem;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  font-weight: 600;
}

.filter-panel .filter-group input,
.filter-panel .filter-group select {
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  background: var(--color-surface);
  width: 150px;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-group-pair {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  flex-shrink: 1;
  min-width: 0;
}

.filter-group-pair .filter-group select {
  width: 140px;
  max-width: 140px;
}

.filter-actions {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 0.5rem;
  margin-left: auto;
}

.filter-actions .btn {
  white-space: nowrap;
}

/* Dashboard actions */
.dashboard-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.btn-reload {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border-color: var(--color-primary);
  color: var(--color-primary);
}

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

.icon-reload {
  width: 14px;
  height: 14px;
  filter: brightness(0) saturate(100%) invert(28%) sepia(96%) saturate(1640%) hue-rotate(193deg);
}

.btn-reload:hover .icon-reload {
  filter: brightness(0) invert(1);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--color-text-secondary);
}

.empty-state h2 { margin-bottom: 0.5rem; }

/* Responsive */
@media (max-width: 768px) {
  .charts-grid { grid-template-columns: 1fr; }
  .dashboard-header { flex-direction: column; align-items: flex-start; }
  .navbar { flex-direction: column; gap: 0.5rem; }
  .filter-row { flex-direction: column; }
  .filter-panel .filter-group input,
  .filter-panel .filter-group select { max-width: 100%; }
}
