:root {
  color-scheme: light dark;
  --bg: #f8f9fa;
  --surface: #ffffff;
  --surface-alt: #f5f5f7;
  --surface-strong: #e8ecf1;
  --ink: #1a1d1f;
  --ink-muted: #6b7280;
  --ink-light: #9ca3af;
  --line: #e5e7eb;
  --line-light: #f3f4f6;
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --primary-light: #dbeafe;
  --success: #10b981;
  --success-light: #d1fae5;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --error: #ef4444;
  --error-light: #fee2e2;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --radius: 6px;
  --radius-lg: 12px;
  --radius-full: 9999px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-alt: #334155;
    --surface-strong: #475569;
    --ink: #f1f5f9;
    --ink-muted: #cbd5e1;
    --ink-light: #94a3b8;
    --line: #334155;
    --line-light: #0f172a;
    --primary: #3b82f6;
    --primary-light: #1e3a8a;
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  transition: background-color 0.3s ease, color 0.3s ease;
}

.hidden {
  display: none !important;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  transition: all 0.2s ease;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 8px 12px;
  transition: border-color 0.2s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* App Shell */
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 0;
}

.app-shell.hidden {
  display: none;
}

/* Auth Screen */
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, var(--bg) 0%, var(--surface-alt) 100%);
}

.auth-screen.hidden {
  display: none;
}

.auth-card {
  width: min(480px, 100%);
  display: grid;
  gap: 24px;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  font-weight: 700;
  font-size: 18px;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
}

.brand p {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--ink-muted);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  border-bottom: 1px solid var(--line);
}

.auth-tab {
  padding: 12px 16px;
  background: transparent;
  color: var(--ink-muted);
  border: none;
  border-bottom: 2px solid transparent;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: -1px;
}

.auth-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.auth-form {
  display: grid;
  gap: 16px;
}

.auth-form label {
  display: block;
  font-weight: 500;
  font-size: 14px;
  color: var(--ink);
  margin-bottom: 4px;
}

.auth-form input {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
}

.auth-message {
  padding: 12px;
  border-radius: var(--radius);
  font-size: 14px;
  display: none;
}

.auth-message.visible {
  display: block;
}

.auth-message.error {
  background: var(--error-light);
  color: #991b1b;
  border: 1px solid #fca5a5;
}

.auth-message.success {
  background: var(--success-light);
  color: #065f46;
  border: 1px solid #a7f3d0;
}

/* Buttons */
.primary-button,
.secondary-button,
.ghost-button {
  padding: 10px 16px;
  font-weight: 500;
  font-size: 14px;
  border-radius: var(--radius);
  transition: all 0.2s ease;
}

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

.primary-button:hover {
  background: var(--primary-dark);
  box-shadow: var(--shadow-md);
}

.primary-button:active {
  transform: scale(0.98);
}

.secondary-button {
  background: var(--surface-strong);
  color: var(--ink);
  border: 1px solid var(--line);
}

.secondary-button:hover {
  background: var(--line);
}

.ghost-button {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--line);
}

.ghost-button:hover {
  background: var(--primary-light);
  border-color: var(--primary);
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px 16px;
  overflow-y: auto;
  position: sticky;
  top: 0;
}

.nav-list {
  display: grid;
  gap: 4px;
  margin-top: 24px;
  flex: 1;
}

.nav-item {
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: var(--ink-muted);
  text-align: left;
  border-radius: var(--radius);
  font-weight: 500;
  font-size: 14px;
  transition: all 0.2s ease;
}

.nav-item:hover {
  background: var(--surface-alt);
  color: var(--ink);
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.account-box {
  padding: 12px;
  background: var(--surface-alt);
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 12px;
  word-break: break-all;
}

/* Main Content */
.main-content {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 32px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  gap: 24px;
  flex-wrap: wrap;
}

.topbar p {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-light);
  font-weight: 600;
}

.topbar h2 {
  margin: 4px 0 0 0;
  font-size: 24px;
  font-weight: 700;
}

.topbar-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.date-control {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--ink-muted);
}

.date-control input {
  padding: 6px 8px;
  font-size: 14px;
}

.save-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 16px;
  background: var(--success);
  color: white;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 1000;
}

.save-toast.visible {
  opacity: 1;
  pointer-events: auto;
}

/* Sections */
.section {
  display: none;
  padding: 32px;
  gap: 32px;
  animation: fadeIn 0.2s ease;
}

.section.active-section {
  display: grid;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.section-heading {
  display: grid;
  gap: 8px;
}

.section-heading h3 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.section-heading p {
  margin: 0;
  color: var(--ink-muted);
  font-size: 14px;
}

/* Metric Grid */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.metric-card {
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  display: grid;
  gap: 12px;
  box-shadow: var(--shadow);
  transition: all 0.2s ease;
}

.metric-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
}

.metric-label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-light);
  font-weight: 600;
}

.metric-card strong {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
}

.metric-card p {
  margin: 0;
  font-size: 13px;
  color: var(--ink-muted);
}

/* Forms */
.form-group {
  display: grid;
  gap: 8px;
}

.form-group label {
  font-weight: 500;
  color: var(--ink);
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
}

/* Cards & Lists */
.card-list {
  display: grid;
  gap: 12px;
}

.list-item {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow);
  transition: all 0.2s ease;
}

.list-item:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--primary);
}

.list-item-content {
  display: grid;
  gap: 4px;
  flex: 1;
}

.list-item-title {
  font-weight: 600;
  color: var(--ink);
}

.list-item-subtitle {
  font-size: 13px;
  color: var(--ink-muted);
}

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

  .sidebar {
    display: none;
  }

  .topbar {
    padding: 16px;
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-actions {
    width: 100%;
    flex-direction: column;
  }

  .topbar-actions > button,
  .topbar-actions > label {
    width: 100%;
  }

  .section {
    padding: 16px;
  }

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

/* Admin only */
.admin-only,
.family-only {
  display: none;
}

.admin-only.visible,
.family-only.visible {
  display: block;
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Utilities */
.text-center {
  text-align: center;
}

.mt-24 {
  margin-top: 24px;
}

.gap-16 {
  gap: 16px;
}
