@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&display=swap');

:root {
  --font: "DM Sans", system-ui, -apple-system, sans-serif;
  --radius-sm: 6px;
  --radius: 12px;
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
}

:root,
[data-theme="light"] {
  --color-bg: #f3f6f5;
  --color-surface: #ffffff;
  --color-border: #d5e2e0;
  --color-border-hover: #b9cfcc;
  --color-border-focus: #507271;
  --color-text: #1b2c2b;
  --color-text-muted: #5d716f;
  --color-primary: #507271;
  --color-primary-hover: #3e5b5a;
  --color-primary-soft: #e7f2f1;
  --color-focus-ring: rgba(80, 114, 113, 0.22);
  --color-danger: #dc2626;
  --color-danger-hover: #b91c1c;
  --color-danger-soft: #fef2f2;
  --color-success: #059669;
  --color-bg-hover: #e7eeec;
  --color-overlay: rgba(27, 44, 43, 0.5);
  --badge-active-fg: #065f46;
  --badge-active-bg: #d1fae5;
  --badge-archived-fg: #6b7280;
  --badge-archived-bg: #f3f4f6;
  --shadow-sm: 0 1px 2px rgba(27, 44, 43, 0.05);
  --shadow: 0 8px 24px rgba(27, 44, 43, 0.08);
}

[data-theme="dark"] {
  --color-bg: #111918;
  --color-surface: #1b2524;
  --color-border: #2d3c3a;
  --color-border-hover: #3e534f;
  --color-border-focus: #8fbfbc;
  --color-text: #e7f2f1;
  --color-text-muted: #9aafad;
  --color-primary: #8fbfbc;
  --color-primary-hover: #b7d8d6;
  --color-primary-soft: #243432;
  --color-focus-ring: rgba(143, 191, 188, 0.32);
  --color-danger: #ef4444;
  --color-danger-hover: #dc2626;
  --color-danger-soft: #3f1d1d;
  --color-success: #34d399;
  --color-bg-hover: #243230;
  --color-overlay: rgba(0, 0, 0, 0.65);
  --badge-active-fg: #6ee7b7;
  --badge-active-bg: #064e3b;
  --badge-archived-fg: #9ca3af;
  --badge-archived-bg: #374151;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

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

/* Component display rules (.form, .btn, .form-field) must not override the hidden attribute. */
[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

html[data-theme="light"] {
  color-scheme: light;
}

html[data-theme="dark"] {
  color-scheme: dark;
}

h1, h2, h3 {
  margin: 0 0 var(--space-sm);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

h1 { font-size: 1.875rem; }

p { margin: 0 0 var(--space-md); }

a {
  color: var(--color-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

code {
  font-size: 0.875em;
  padding: 0.15em 0.4em;
  border-radius: var(--radius-sm);
  background: var(--color-primary-soft);
  color: var(--color-primary-hover);
}

header {
  background: var(--color-surface);
  border-bottom: 2px solid var(--color-primary);
  padding: var(--space-md) var(--space-xl);
  box-shadow: var(--shadow-sm);
}

header nav {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: var(--space-sm) var(--space-md);
  max-width: 52rem;
  margin: 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
  line-height: 0;
}

.brand img {
  display: block;
  height: 8.125rem;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  object-position: left center;
}

html[data-theme="dark"] .brand img {
  filter: brightness(1.6);
}

header nav a.brand,
header nav a.brand:hover,
header nav a.brand.selected {
  padding: 0;
  background: transparent;
  color: inherit;
  text-decoration: none;
}

header nav .nav-links {
  display: flex;
  flex-shrink: 0;
  gap: var(--space-xs);
  margin-left: auto;
}

@media (max-width: 640px) {
  header {
    padding: var(--space-sm) var(--space-md);
  }

  .brand img {
    height: 6.875rem;
  }

  header nav {
    gap: var(--space-xs);
  }

  .theme-toggle-option {
    padding: 0.4rem 0.5rem;
  }
}

header nav a {
  color: var(--color-text-muted);
  text-decoration: none;
  padding: 0.5rem 0.875rem;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

header nav a:hover {
  color: var(--color-text);
  background: var(--color-bg);
  text-decoration: none;
}

header nav a.selected {
  color: var(--color-primary);
  background: var(--color-primary-soft);
}

.theme-toggle {
  display: inline-flex;
  flex-shrink: 0;
  padding: 0.2rem;
  gap: 0.15rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.theme-toggle-option {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  padding: 0.45rem 0.65rem;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.2;
  color: var(--color-text-muted);
  background: transparent;
  border: none;
  border-radius: calc(var(--radius-sm) - 0.1rem);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.theme-toggle-option .theme-icon {
  display: block;
  flex-shrink: 0;
  color: inherit;
}

.theme-toggle-option:hover:not(.is-selected) {
  color: var(--color-text);
  background: var(--color-bg-hover);
}

/* Primary icon on surface — never matches chip/track background */
.theme-toggle-option.is-selected {
  color: var(--color-primary);
  background: var(--color-surface);
  box-shadow: 0 0 0 1px var(--color-border);
}

/* Sun: amber so it stays visible on white (light) and dark track */
.theme-toggle-option[data-theme-value="light"] {
  color: #b45309;
}

html[data-theme="dark"] .theme-toggle-option[data-theme-value="light"]:not(.is-selected) {
  color: #fbbf24;
}

.theme-toggle-option[data-theme-value="light"].is-selected {
  color: #b45309;
  background: #fffbeb;
  box-shadow: 0 0 0 1px #fcd34d;
}

html[data-theme="dark"] .theme-toggle-option[data-theme-value="light"].is-selected {
  color: #fbbf24;
  background: #422006;
  box-shadow: 0 0 0 1px #92400e;
}

main {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-xl) var(--space-md);
}

main > section {
  display: none;
  flex-direction: column;
  gap: var(--space-lg);
  width: min(42rem, 100%);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-xl);
  box-shadow: var(--shadow);
}

/* Finances and Admin hold wide tables; one rule so their widths can't drift apart. */
#finances,
#admin {
  width: min(60rem, 100%);
}

.hint {
  color: var(--color-text-muted);
  font-size: 0.9375rem;
  margin: 0;
}

.app-status {
  max-width: 52rem;
  margin: var(--space-sm) auto 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  border-radius: var(--radius-sm);
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

.app-status.error {
  background: var(--color-danger-soft);
  color: var(--color-danger);
}

.app-status[hidden] {
  display: none;
}

.status {
  font-size: 0.875rem;
  margin: 0;
  min-height: 1.25rem;
}

.status.error {
  color: var(--color-danger);
}

.status.success {
  color: var(--color-success);
}
