:root {
  --brand-50: #f0fdfa;
  --brand-100: #ccfbf1;
  --brand-600: #0d9488;
  --brand-700: #0f766e;
  --brand-800: #115e59;
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-900: #0f172a;
  --rose-50: #fff1f2;
  --rose-200: #fecdd3;
  --rose-600: #e11d48;
  --rose-700: #be123c;
  --amber-50: #fffbeb;
  --amber-200: #fde68a;
  --amber-800: #92400e;
  --green-50: #ecfdf5;
  --green-200: #a7f3d0;
  --green-700: #047857;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 1px 3px rgba(15, 23, 42, 0.04);
  --surface: #fff;
  --page: var(--slate-50);
  color-scheme: light;
}

/* Dark follows the OS unless the toggle pinned a theme (data-theme on <html>). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface: #131b2c;
    --page: #0b1120;
    --brand-50: #0b2b2a;
    --brand-100: #11403d;
    --brand-700: #5eead4;
    --brand-800: #99f6e4;
    --slate-50: #0b1120;
    --slate-100: #1a2234;
    --slate-200: #283247;
    --slate-300: #3b475d;
    --slate-400: #64748b;
    --slate-500: #94a3b8;
    --slate-600: #b4c0d0;
    --slate-700: #cbd5e1;
    --slate-900: #f1f5f9;
    --rose-50: #33121b;
    --rose-200: #7f1d36;
    --rose-700: #fda4af;
    --amber-50: #2e2008;
    --amber-200: #78500f;
    --amber-800: #fde68a;
    --green-50: #0a2a20;
    --green-200: #14532d;
    --green-700: #6ee7b7;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --surface: #131b2c;
  --page: #0b1120;
  --brand-50: #0b2b2a;
  --brand-100: #11403d;
  --brand-700: #5eead4;
  --brand-800: #99f6e4;
  --slate-50: #0b1120;
  --slate-100: #1a2234;
  --slate-200: #283247;
  --slate-300: #3b475d;
  --slate-400: #64748b;
  --slate-500: #94a3b8;
  --slate-600: #b4c0d0;
  --slate-700: #cbd5e1;
  --slate-900: #f1f5f9;
  --rose-50: #33121b;
  --rose-200: #7f1d36;
  --rose-700: #fda4af;
  --amber-50: #2e2008;
  --amber-200: #78500f;
  --amber-800: #fde68a;
  --green-50: #0a2a20;
  --green-200: #14532d;
  --green-700: #6ee7b7;
  --shadow: none;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--slate-900);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  margin: 0;
}

code,
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.muted {
  color: var(--slate-500);
}

.small {
  font-size: 12px;
}

.num {
  font-variant-numeric: tabular-nums;
}

/* Login */
.login {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
  background: linear-gradient(160deg, #115e59, #0d9488);
}

.login > .powered {
  position: absolute;
  bottom: 16px;
  left: 0;
  right: 0;
  text-align: center;
  color: rgba(255, 255, 255, 0.7);
}

.sidebar .powered {
  padding: 0 8px;
  font-size: 11px;
  color: var(--slate-400);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.25);
}

.login-card h1 {
  font-size: 20px;
  margin-top: 24px;
}

.login-card p {
  margin: 4px 0 20px;
}

/* Shell */
.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  width: 232px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px 12px;
  background: var(--surface);
  border-right: 1px solid var(--slate-200);
}

.sidebar .brand {
  padding: 0 8px 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  color: var(--slate-900);
}

.brand-name {
  font-weight: 600;
}

nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--slate-600);
  text-decoration: none;
  font-weight: 500;
}

nav a:hover {
  background: var(--slate-50);
  color: var(--slate-900);
}

nav a.active {
  background: var(--brand-50);
  color: var(--brand-700);
}

main {
  flex: 1;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  padding: 0 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--slate-200);
}

.topbar h1 {
  font-size: 18px;
  font-weight: 600;
}

.content {
  padding: 24px 32px 48px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 1280px;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--slate-200);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.card-header h2 {
  font-size: 15px;
  font-weight: 600;
}

.card-header p {
  margin: 2px 0 0;
  color: var(--slate-500);
}

.grid {
  display: grid;
  gap: 24px;
}

.grid-2 {
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
}

.stats {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.stat {
  background: var(--surface);
  border: 1px solid var(--slate-200);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--slate-500);
}

.stat-value {
  margin-top: 6px;
  font-size: 24px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stat-hint {
  margin-top: 2px;
  font-size: 12px;
  color: var(--slate-500);
}

.stat.warn .stat-value {
  color: var(--amber-800);
}

.stat.bad .stat-value {
  color: var(--rose-700);
}

/* Forms */
label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--slate-700);
}

input,
select {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--slate-300);
  border-radius: 8px;
  background: var(--surface);
  font: inherit;
  color: var(--slate-900);
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--brand-600);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
}

.field {
  margin-bottom: 14px;
}

.form-row {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

input.compact,
select.compact {
  height: 32px;
  width: auto;
  min-width: 120px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

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

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

.btn-sm {
  height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--brand-600);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.1);
}

.btn-outline {
  background: var(--surface);
  border-color: var(--slate-300);
  color: var(--slate-700);
}

.btn-outline:hover:not(:disabled) {
  background: var(--slate-50);
}

.btn-ghost {
  background: transparent;
  color: var(--slate-600);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--slate-100);
  color: var(--slate-900);
}

.btn-danger {
  background: var(--surface);
  border-color: var(--rose-200);
  color: var(--rose-700);
}

.btn-danger:hover:not(:disabled) {
  background: var(--rose-50);
}

/* Tables */
.table-wrap {
  margin: 0 -20px -20px;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  padding: 10px 20px;
  background: var(--slate-50);
  border-top: 1px solid var(--slate-200);
  border-bottom: 1px solid var(--slate-200);
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--slate-500);
  white-space: nowrap;
}

td {
  padding: 12px 20px;
  border-bottom: 1px solid var(--slate-100);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

td.right,
th.right {
  text-align: right;
}

.empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--slate-500);
  border: 1px dashed var(--slate-200);
  border-radius: 10px;
}

/* Badges, alerts */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--slate-200);
  background: var(--slate-50);
  color: var(--slate-600);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.badge.success {
  background: var(--green-50);
  border-color: var(--green-200);
  color: var(--green-700);
}

.badge.warning {
  background: var(--amber-50);
  border-color: var(--amber-200);
  color: var(--amber-800);
}

.badge.danger {
  background: var(--rose-50);
  border-color: var(--rose-200);
  color: var(--rose-700);
}

.badge.brand {
  background: var(--brand-50);
  border-color: var(--brand-100);
  color: var(--brand-700);
}

.alert {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
}

.alert-danger {
  background: var(--rose-50);
  border: 1px solid var(--rose-200);
  color: var(--rose-700);
}

.code-box {
  padding: 20px;
  border-radius: 10px;
  background: var(--brand-50);
  border: 1px solid var(--brand-100);
  text-align: center;
}

.code-box .code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--brand-800);
}

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.links a {
  text-decoration: none;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  padding: 10px 16px;
  border-radius: 10px;
  background: #0f172a;
  color: #fff;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.25);
}

.toast.error {
  background: var(--rose-700);
}

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

  .sidebar {
    position: static;
    height: auto;
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--slate-200);
  }

  nav {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .topbar,
  .content {
    padding-left: 16px;
    padding-right: 16px;
  }

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

.login-card input {
  margin-bottom: 16px;
}

.sidebar .btn-ghost {
  justify-content: flex-start;
  padding: 0 12px;
}
