:root {
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 3.8% 46.1%;
  --card: 0 0% 100%;
  --border: 240 5.9% 90%;
  --primary: 240 5.9% 10%;
  --primary-foreground: 0 0% 98%;
  --accent: 240 4.8% 95.9%;
  --ring: 240 5.9% 10%;
  --destructive: 0 84.2% 60.2%;
  --radius: 0.5rem;
  --shadow: 0 1px 2px hsl(240 10% 3.9% / 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: 240 10% 3.9%;
    --foreground: 0 0% 98%;
    --muted: 240 3.7% 15.9%;
    --muted-foreground: 240 5% 64.9%;
    --card: 240 10% 3.9%;
    --border: 240 3.7% 15.9%;
    --primary: 0 0% 98%;
    --primary-foreground: 240 5.9% 10%;
    --accent: 240 3.7% 15.9%;
    --ring: 240 4.9% 83.9%;
    --shadow: 0 1px 2px hsl(0 0% 0% / 0.4);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 15px;
}

body {
  margin: 0;
  min-height: 100vh;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
}

a {
  color: inherit;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
}

.shell {
  max-width: 72rem;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 3rem;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
  padding-bottom: 1rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid hsl(var(--border));
}

.brand {
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand:hover {
  text-decoration: none;
}

.topbar nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.topbar nav a {
  padding: 0.35rem 0.7rem;
  border-radius: calc(var(--radius) - 2px);
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
}

.topbar nav a:hover {
  background: hsl(var(--accent));
  color: hsl(var(--foreground));
  text-decoration: none;
}

h1 {
  margin: 0 0 1rem;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}

h2 {
  margin: 1.75rem 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.lead {
  margin: 0 0 1.25rem;
  color: hsl(var(--muted-foreground));
  max-width: 40rem;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.alert {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--muted));
}

.alert[role="status"] code {
  display: block;
  margin-top: 0.35rem;
  word-break: break-all;
}

.filters,
.stack {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: end;
  margin-bottom: 1.25rem;
}

.stack {
  flex-direction: column;
  align-items: stretch;
  max-width: 36rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
}

.inline {
  flex-direction: row;
  align-items: center;
}

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  width: 100%;
  min-width: 10rem;
  padding: 0.45rem 0.7rem;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font: inherit;
}

textarea {
  min-height: 10rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
}

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  padding: 0.45rem 0.85rem;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
}

button:hover,
.btn:hover {
  opacity: 0.92;
  text-decoration: none;
}

.btn-ghost,
button.ghost {
  background: transparent;
  color: hsl(var(--foreground));
}

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr));
  gap: 0.75rem;
  margin: 0 0 1.5rem;
  padding: 0;
  list-style: none;
}

.kpi {
  margin: 0;
  padding: 0.85rem 1rem;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--card));
  box-shadow: var(--shadow);
}

.kpi-label {
  display: block;
  margin-bottom: 0.25rem;
  color: hsl(var(--muted-foreground));
  font-size: 0.75rem;
  font-weight: 500;
}

.kpi-value {
  font-variant-numeric: tabular-nums;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--card));
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

th,
td {
  padding: 0.65rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid hsl(var(--border));
  white-space: nowrap;
}

th {
  color: hsl(var(--muted-foreground));
  font-weight: 500;
  background: hsl(var(--muted));
}

tbody tr:hover {
  background: hsl(var(--accent));
}

tbody tr:last-child td {
  border-bottom: 0;
}

.empty {
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
}

.badge {
  display: inline-flex;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: hsl(var(--muted));
  font-size: 0.75rem;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
