/* ============================================================
   DR Monitor — design tokens matched to kid-xero-extract
   ============================================================ */

:root {
  --background: 0 0% 100%;
  --foreground: 222 47% 11%;

  --card: 0 0% 100%;
  --card-foreground: 222 47% 11%;

  --popover: 0 0% 100%;
  --popover-foreground: 222 47% 11%;

  --primary: 221 83% 53%;
  --primary-foreground: 210 40% 98%;

  --secondary: 210 40% 96%;
  --secondary-foreground: 222 47% 11%;

  --muted: 210 40% 96%;
  --muted-foreground: 215 16% 47%;

  --accent: 210 40% 96%;
  --accent-foreground: 222 47% 11%;

  --destructive: 0 65% 51%;
  --destructive-foreground: 0 0% 100%;
  --destructive-soft: 0 80% 96%;
  --destructive-soft-foreground: 0 60% 35%;

  --success: 142 50% 38%;
  --success-foreground: 0 0% 100%;
  --success-soft: 142 50% 94%;
  --success-soft-foreground: 142 50% 26%;

  --warning: 36 70% 45%;
  --warning-foreground: 0 0% 100%;
  --warning-soft: 36 80% 94%;
  --warning-soft-foreground: 30 60% 32%;

  --info-soft: 217 90% 95%;
  --info-soft-foreground: 217 80% 35%;

  --border: 214 25% 82%;
  --input: 214 30% 80%;
  --ring: 221 83% 53%;

  --radius: 0.5rem;
}

html.dark {
  --background: 222 25% 8%;
  --foreground: 210 30% 92%;
  --card: 222 22% 12%;
  --card-foreground: 210 30% 92%;
  --popover: 222 22% 12%;
  --popover-foreground: 210 30% 92%;
  --primary: 217 70% 60%;
  --primary-foreground: 222 47% 11%;
  --secondary: 217 33% 17%;
  --secondary-foreground: 210 40% 98%;
  --muted: 217 22% 18%;
  --muted-foreground: 215 18% 65%;
  --accent: 217 22% 22%;
  --accent-foreground: 210 30% 92%;
  --destructive: 0 55% 58%;
  --destructive-foreground: 0 0% 100%;
  --destructive-soft: 0 50% 18%;
  --destructive-soft-foreground: 0 70% 80%;
  --success: 142 45% 45%;
  --success-foreground: 0 0% 100%;
  --success-soft: 142 35% 18%;
  --success-soft-foreground: 142 50% 80%;
  --warning: 36 70% 55%;
  --warning-foreground: 0 0% 100%;
  --warning-soft: 36 50% 18%;
  --warning-soft-foreground: 36 80% 82%;
  --info-soft: 217 50% 18%;
  --info-soft-foreground: 217 80% 82%;
  --border: 217 24% 34%;
  --input: 217 24% 34%;
  --ring: 224 76% 60%;
}

/* ============================================================
   Base
   ============================================================ */

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: 'Inter', 'Roboto', system-ui, sans-serif;
  font-feature-settings: 'rlig' 1, 'calt' 1;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-size: 14px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { font-weight: 600; letter-spacing: -0.01em; margin: 0; }

/* ============================================================
   App shell (topbar + sidebar + main)
   ============================================================ */

.app-shell { display: flex; flex-direction: column; min-height: 100vh; background: hsl(var(--muted) / 0.3); }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 0.75rem;
  height: 3.5rem; padding: 0 1rem;
  background: hsl(var(--background) / 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid hsl(var(--border));
}

.topbar-brand {
  font-weight: 600;
  font-size: 0.9375rem;
  color: hsl(var(--foreground));
  padding: 0 0.5rem;
}

.topbar-sep {
  width: 1px;
  height: 1.5rem;
  background: hsl(var(--border));
}

.topbar-spacer { flex: 1; }

.topbar-user {
  display: flex; align-items: center; gap: 0.75rem;
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
}

.topbar-user a {
  color: hsl(var(--foreground));
  font-weight: 500;
}
.topbar-user a:hover { color: hsl(var(--primary)); }

.app-body { display: flex; flex: 1; overflow: hidden; }

.sidebar {
  display: none;
  width: 14rem;
  flex-shrink: 0;
  flex-direction: column;
  border-right: 1px solid hsl(var(--border));
  background: hsl(var(--background));
  padding: 1rem 0.5rem;
}

@media (min-width: 768px) { .sidebar { display: flex; } }

.sidebar-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: hsl(var(--muted-foreground));
  padding: 0.5rem 0.75rem 0.25rem;
}

.sidebar-item {
  position: relative;
  display: flex; align-items: center; gap: 0.625rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  color: hsl(var(--foreground));
  transition: background-color 150ms;
}

.sidebar-item:hover { background: hsl(var(--accent)); }

.sidebar-item.active {
  background: hsl(var(--primary) / 0.1);
  color: hsl(var(--primary));
  font-weight: 600;
}

.sidebar-item.active::before {
  content: '';
  position: absolute;
  inset-block: 0.25rem;
  left: 0;
  width: 2px;
  background: hsl(var(--primary));
  border-radius: 0 9999px 9999px 0;
}

.sidebar-item svg { width: 1rem; height: 1rem; flex-shrink: 0; }

.main { flex: 1; overflow-y: auto; }
.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }
@media (min-width: 1280px) { .container { padding: 1.5rem 2.5rem; } }

/* ============================================================
   Cards
   ============================================================ */

.card {
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}

.card-header { padding: 1.5rem; padding-bottom: 0; }
.card-content { padding: 1.5rem; }
.card-footer { display: flex; align-items: center; padding: 1.5rem; padding-top: 0; }

.card-title { font-size: 1.125rem; font-weight: 600; line-height: 1; }
.card-description {
  font-size: 0.875rem;
  color: hsl(var(--muted-foreground));
  margin-top: 0.375rem;
}

/* ============================================================
   Buttons
   ============================================================ */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 0.5rem;
  height: 2.25rem;
  padding: 0 1rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background-color 150ms, border-color 150ms, color 150ms;
  white-space: nowrap;
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px hsl(var(--background)), 0 0 0 4px hsl(var(--ring));
}

.btn svg { width: 1rem; height: 1rem; flex-shrink: 0; }

.btn-primary {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}
.btn-primary:hover { background: hsl(var(--primary) / 0.9); }

.btn-outline {
  background: hsl(var(--background));
  border-color: hsl(var(--input));
  color: hsl(var(--foreground));
}
.btn-outline:hover { background: hsl(var(--accent)); }

.btn-ghost { color: hsl(var(--foreground)); }
.btn-ghost:hover { background: hsl(var(--accent)); }

.btn-sm { height: 2rem; padding: 0 0.75rem; font-size: 0.75rem; }
.btn-lg { height: 2.75rem; padding: 0 1.5rem; }
.btn-full { width: 100%; }

/* ============================================================
   Inputs
   ============================================================ */

.input {
  display: block;
  width: 100%;
  height: 2.25rem;
  padding: 0.25rem 0.75rem;
  border: 1px solid hsl(var(--input));
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-family: inherit;
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  transition: border-color 150ms, box-shadow 150ms;
}
.input:focus {
  outline: none;
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 2px hsl(var(--ring) / 0.2);
}
.input::placeholder { color: hsl(var(--muted-foreground)); }

.label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: hsl(var(--foreground));
  margin-bottom: 0.375rem;
}

/* ============================================================
   Badges
   ============================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  border-radius: 0.375rem;
  border: 1px solid transparent;
  padding: 0.125rem 0.5rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.badge-success {
  background: hsl(var(--success-soft));
  color: hsl(var(--success-soft-foreground));
}
.badge-warning {
  background: hsl(var(--warning-soft));
  color: hsl(var(--warning-soft-foreground));
}
.badge-destructive {
  background: hsl(var(--destructive-soft));
  color: hsl(var(--destructive-soft-foreground));
}
.badge-info {
  background: hsl(var(--info-soft));
  color: hsl(var(--info-soft-foreground));
}
.badge-muted {
  background: hsl(var(--muted));
  color: hsl(var(--muted-foreground));
}

/* ============================================================
   Alerts
   ============================================================ */

.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  border-radius: 0.375rem;
  padding: 0.75rem;
  font-size: 0.875rem;
  border: 1px solid;
}
.alert svg { width: 1rem; height: 1rem; flex-shrink: 0; margin-top: 0.125rem; }

.alert-destructive {
  border-color: hsl(var(--destructive) / 0.3);
  background: hsl(var(--destructive-soft));
  color: hsl(var(--destructive-soft-foreground));
}

/* ============================================================
   Page header (matches kid-xero-extract)
   ============================================================ */

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

.page-header-text { display: flex; flex-direction: column; gap: 0.25rem; }
.page-title { font-size: 1.5rem; font-weight: 600; }
.page-description {
  font-size: 0.875rem;
  color: hsl(var(--muted-foreground));
}

/* ============================================================
   Dashboard stat grid (matches DashboardPage)
   ============================================================ */

.stat-grid {
  display: grid;
  grid-auto-rows: 1fr;
  gap: 1rem;
  grid-template-columns: 1fr;
}
@media (min-width: 640px)  { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1280px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }

.stat-card {
  display: block;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 1.25rem;
  color: hsl(var(--foreground));
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  transition: transform 150ms, border-color 150ms, box-shadow 150ms, background-color 150ms;
}

.stat-card:hover {
  transform: translateY(-2px);
  border-color: hsl(var(--primary));
  background: hsl(var(--accent) / 0.4);
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

.stat-card-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: hsl(var(--muted-foreground));
}
.stat-card-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin-top: 0.5rem;
}
.stat-card-stat {
  font-size: 1.875rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-top: 0.75rem;
}
.stat-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.75rem;
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
}

/* ============================================================
   Login layout (matches AdminLoginPage)
   ============================================================ */

.login-shell {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  background: hsl(var(--muted) / 0.3);
  padding: 1rem;
}

.login-card { width: 100%; max-width: 28rem; }

.login-title  { font-size: 1.5rem; font-weight: 600; text-align: center; }
.login-description {
  text-align: center;
  color: hsl(var(--muted-foreground));
  margin-top: 0.5rem;
  font-size: 0.875rem;
}

/* Microsoft logo: 2×2 colored squares */
.ms-logo {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 1px;
  width: 1rem;
  height: 1rem;
}
.ms-logo span { display: block; }
.ms-logo span:nth-child(1) { background: #f25022; }
.ms-logo span:nth-child(2) { background: #7fba00; }
.ms-logo span:nth-child(3) { background: #00a4ef; }
.ms-logo span:nth-child(4) { background: #ffb900; }

/* ============================================================
   Utilities
   ============================================================ */

.muted { color: hsl(var(--muted-foreground)); }
.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.875rem; }
.text-lg { font-size: 1.125rem; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.tabular { font-variant-numeric: tabular-nums; }

.flex { display: flex; }
.inline-flex { display: inline-flex; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.w-full { width: 100%; }

.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mt-8 { margin-top: 2rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.space-y-2 > * + * { margin-top: 0.5rem; }
.space-y-4 > * + * { margin-top: 1rem; }
.space-y-6 > * + * { margin-top: 1.5rem; }

/* ============================================================
   Theme toggle button
   ============================================================ */

.theme-toggle { width: 2rem; padding: 0; }
.theme-toggle .theme-icon-sun  { display: none; }
.theme-toggle .theme-icon-moon { display: inline-block; }
html.dark .theme-toggle .theme-icon-sun  { display: inline-block; }
html.dark .theme-toggle .theme-icon-moon { display: none; }

/* ============================================================
   Data table (admin users etc.)
   ============================================================ */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: hsl(var(--muted-foreground));
  padding: 0.75rem 1rem;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--muted) / 0.4);
}

.data-table tbody td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid hsl(var(--border));
  vertical-align: middle;
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: hsl(var(--muted) / 0.3); }

/* Sortable header indicators */
table.sortable thead th[data-sort] {
  cursor: pointer;
  user-select: none;
  padding-right: 1.5rem;
  position: relative;
}
table.sortable thead th[data-sort]::after {
  content: '↕';
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.3;
  font-size: 0.875rem;
}
table.sortable thead th[aria-sort="ascending"]::after  { content: '↑'; opacity: 1; color: hsl(var(--primary)); }
table.sortable thead th[aria-sort="descending"]::after { content: '↓'; opacity: 1; color: hsl(var(--primary)); }
table.sortable thead th[data-sort]:hover { background: hsl(var(--muted) / 0.7); }

/* Filter bar above a table */
.filter-bar {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  align-items: center;
}
.filter-bar input { max-width: 320px; }
.filter-bar .filter-count {
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
}

/* ============================================================
   Permission grid (admin_user_edit)
   ============================================================ */

.perm-row { padding: 0.5rem 0; }
.perm-row + .perm-row { border-top: 1px solid hsl(var(--border) / 0.4); }

.perm-checkbox {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  cursor: pointer;
}

.perm-checkbox input[type="checkbox"] {
  margin-top: 0.25rem;
  width: 1rem;
  height: 1rem;
  accent-color: hsl(var(--primary));
  cursor: pointer;
}

.perm-checkbox input[type="checkbox"]:disabled { cursor: not-allowed; opacity: 0.6; }

.perm-label {
  font-weight: 500;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
}

.perm-description {
  font-size: 0.8125rem;
  color: hsl(var(--muted-foreground));
  margin-top: 0.125rem;
}

.perm-app-block { padding: 0.75rem 0; }
.perm-app-block + .perm-app-block { border-top: 1px solid hsl(var(--border)); }
.perm-app-name {
  font-weight: 600;
  font-size: 0.9375rem;
  margin-bottom: 0.25rem;
}

/* ============================================================
   Custom scrollbar (matches kid-xero-extract)
   ============================================================ */

* { scrollbar-width: thin; scrollbar-color: hsl(var(--border)) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: hsl(var(--border));
  border-radius: 9999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: hsl(var(--muted-foreground) / 0.5); background-clip: padding-box; }
