/* ==========================================================================
   Material Design 3 (M3) Design System - Vuxenkrycka
   Zero-CDN, Self-Contained, Strict M3 Tokens
   ========================================================================== */

:root {
  /* M3 Shape Tokens */
  --md-sys-shape-corner-none: 0px;
  --md-sys-shape-corner-extra-small: 4px;
  --md-sys-shape-corner-small: 8px;
  --md-sys-shape-corner-medium: 12px;
  --md-sys-shape-corner-large: 16px;
  --md-sys-shape-corner-extra-large: 28px;
  --md-sys-shape-corner-full: 9999px;

  /* M3 Elevation Tokens */
  --md-sys-elevation-level-0: none;
  --md-sys-elevation-level-1: 0px 1px 2px rgba(0, 0, 0, 0.12), 0px 1px 3px rgba(0, 0, 0, 0.14);
  --md-sys-elevation-level-2: 0px 1px 2px rgba(0, 0, 0, 0.12), 0px 2px 6px rgba(0, 0, 0, 0.15);
  --md-sys-elevation-level-3: 0px 1px 3px rgba(0, 0, 0, 0.12), 0px 4px 8px rgba(0, 0, 0, 0.16);
  --md-sys-elevation-level-4: 0px 2px 3px rgba(0, 0, 0, 0.12), 0px 6px 10px rgba(0, 0, 0, 0.16);
  --md-sys-elevation-level-5: 0px 4px 4px rgba(0, 0, 0, 0.12), 0px 8px 12px rgba(0, 0, 0, 0.18);

  /* Typography Scale */
  --md-sys-typescale-font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --md-sys-typescale-headline-small: 500 24px/32px var(--md-sys-typescale-font);
  --md-sys-typescale-title-large: 500 22px/28px var(--md-sys-typescale-font);
  --md-sys-typescale-title-medium: 500 16px/24px var(--md-sys-typescale-font);
  --md-sys-typescale-title-small: 500 14px/20px var(--md-sys-typescale-font);
  --md-sys-typescale-body-large: 400 16px/24px var(--md-sys-typescale-font);
  --md-sys-typescale-body-medium: 400 14px/20px var(--md-sys-typescale-font);
  --md-sys-typescale-body-small: 400 12px/16px var(--md-sys-typescale-font);
  --md-sys-typescale-label-large: 500 14px/20px var(--md-sys-typescale-font);
  --md-sys-typescale-label-medium: 500 12px/16px var(--md-sys-typescale-font);
  --md-sys-typescale-label-small: 500 11px/16px var(--md-sys-typescale-font);

  /* Light Theme (Default) */
  --md-sys-color-primary: #00629E;
  --md-sys-color-on-primary: #FFFFFF;
  --md-sys-color-primary-container: #CFE5FF;
  --md-sys-color-on-primary-container: #001D34;

  --md-sys-color-secondary: #526070;
  --md-sys-color-on-secondary: #FFFFFF;
  --md-sys-color-secondary-container: #D5E4F7;
  --md-sys-color-on-secondary-container: #0E1D2A;

  --md-sys-color-tertiary: #695779;
  --md-sys-color-on-tertiary: #FFFFFF;
  --md-sys-color-tertiary-container: #F1DAFF;
  --md-sys-color-on-tertiary-container: #241532;

  --md-sys-color-error: #BA1A1A;
  --md-sys-color-on-error: #FFFFFF;
  --md-sys-color-error-container: #FFDAD6;
  --md-sys-color-on-error-container: #410002;

  --md-sys-color-background: #FCFCFF;
  --md-sys-color-on-background: #1A1C1E;
  --md-sys-color-surface: #FCFCFF;
  --md-sys-color-on-surface: #1A1C1E;

  --md-sys-color-surface-variant: #DEE3EB;
  --md-sys-color-on-surface-variant: #42474E;
  --md-sys-color-outline: #73777F;
  --md-sys-color-outline-variant: #C2C7CF;

  --md-sys-color-surface-container-lowest: #FFFFFF;
  --md-sys-color-surface-container-low: #F6F3F8;
  --md-sys-color-surface-container: #F0EDF3;
  --md-sys-color-surface-container-high: #EAE8ED;
  --md-sys-color-surface-container-highest: #E4E2E7;

  /* Custom status colors mapped to M3 palettes */
  --md-custom-status-success: #1E6B38;
  --md-custom-status-success-container: #D3F5DD;
  --md-custom-status-on-success-container: #04210E;

  --md-custom-status-warning: #855300;
  --md-custom-status-warning-container: #FFE0B4;
  --md-custom-status-on-warning-container: #2A1700;
}

/* Dark Theme via System Preference */
@media (prefers-color-scheme: dark) {
  :root {
    --md-sys-color-primary: #99CBFF;
    --md-sys-color-on-primary: #003355;
    --md-sys-color-primary-container: #004A78;
    --md-sys-color-on-primary-container: #CFE5FF;

    --md-sys-color-secondary: #B9C8DA;
    --md-sys-color-on-secondary: #243240;
    --md-sys-color-secondary-container: #3B4857;
    --md-sys-color-on-secondary-container: #D5E4F7;

    --md-sys-color-tertiary: #D4BEE5;
    --md-sys-color-on-tertiary: #3A2948;
    --md-sys-color-tertiary-container: #514060;
    --md-sys-color-on-tertiary-container: #F1DAFF;

    --md-sys-color-error: #FFB4AB;
    --md-sys-color-on-error: #690005;
    --md-sys-color-error-container: #93000A;
    --md-sys-color-on-error-container: #FFDAD6;

    --md-sys-color-background: #111416;
    --md-sys-color-on-background: #E2E2E6;
    --md-sys-color-surface: #111416;
    --md-sys-color-on-surface: #E2E2E6;

    --md-sys-color-surface-variant: #42474E;
    --md-sys-color-on-surface-variant: #C2C7CF;
    --md-sys-color-outline: #8C9199;
    --md-sys-color-outline-variant: #42474E;

    --md-sys-color-surface-container-lowest: #0C0F11;
    --md-sys-color-surface-container-low: #1A1C1E;
    --md-sys-color-surface-container: #1E2022;
    --md-sys-color-surface-container-high: #282A2D;
    --md-sys-color-surface-container-highest: #333538;

    --md-custom-status-success: #7AD997;
    --md-custom-status-success-container: #0F5227;
    --md-custom-status-on-success-container: #D3F5DD;

    --md-custom-status-warning: #FFBA66;
    --md-custom-status-warning-container: #643E00;
    --md-custom-status-on-warning-container: #FFE0B4;
  }
}

/* Explicit data-theme support for testing or manual override */
[data-theme="dark"] {
  --md-sys-color-primary: #99CBFF;
  --md-sys-color-on-primary: #003355;
  --md-sys-color-primary-container: #004A78;
  --md-sys-color-on-primary-container: #CFE5FF;

  --md-sys-color-secondary: #B9C8DA;
  --md-sys-color-on-secondary: #243240;
  --md-sys-color-secondary-container: #3B4857;
  --md-sys-color-on-secondary-container: #D5E4F7;

  --md-sys-color-tertiary: #D4BEE5;
  --md-sys-color-on-tertiary: #3A2948;
  --md-sys-color-tertiary-container: #514060;
  --md-sys-color-on-tertiary-container: #F1DAFF;

  --md-sys-color-error: #FFB4AB;
  --md-sys-color-on-error: #690005;
  --md-sys-color-error-container: #93000A;
  --md-sys-color-on-error-container: #FFDAD6;

  --md-sys-color-background: #111416;
  --md-sys-color-on-background: #E2E2E6;
  --md-sys-color-surface: #111416;
  --md-sys-color-on-surface: #E2E2E6;

  --md-sys-color-surface-variant: #42474E;
  --md-sys-color-on-surface-variant: #C2C7CF;
  --md-sys-color-outline: #8C9199;
  --md-sys-color-outline-variant: #42474E;

  --md-sys-color-surface-container-lowest: #0C0F11;
  --md-sys-color-surface-container-low: #1A1C1E;
  --md-sys-color-surface-container: #1E2022;
  --md-sys-color-surface-container-high: #282A2D;
  --md-sys-color-surface-container-highest: #333538;
}

[data-theme="light"] {
  --md-sys-color-primary: #00629E;
  --md-sys-color-on-primary: #FFFFFF;
  --md-sys-color-primary-container: #CFE5FF;
  --md-sys-color-on-primary-container: #001D34;

  --md-sys-color-secondary: #526070;
  --md-sys-color-on-secondary: #FFFFFF;
  --md-sys-color-secondary-container: #D5E4F7;
  --md-sys-color-on-secondary-container: #0E1D2A;

  --md-sys-color-tertiary: #695779;
  --md-sys-color-on-tertiary: #FFFFFF;
  --md-sys-color-tertiary-container: #F1DAFF;
  --md-sys-color-on-tertiary-container: #241532;

  --md-sys-color-error: #BA1A1A;
  --md-sys-color-on-error: #FFFFFF;
  --md-sys-color-error-container: #FFDAD6;
  --md-sys-color-on-error-container: #410002;

  --md-sys-color-background: #FCFCFF;
  --md-sys-color-on-background: #1A1C1E;
  --md-sys-color-surface: #FCFCFF;
  --md-sys-color-on-surface: #1A1C1E;

  --md-sys-color-surface-variant: #DEE3EB;
  --md-sys-color-on-surface-variant: #42474E;
  --md-sys-color-outline: #73777F;
  --md-sys-color-outline-variant: #C2C7CF;

  --md-sys-color-surface-container-lowest: #FFFFFF;
  --md-sys-color-surface-container-low: #F6F3F8;
  --md-sys-color-surface-container: #F0EDF3;
  --md-sys-color-surface-container-high: #EAE8ED;
  --md-sys-color-surface-container-highest: #E4E2E7;
}

/* ==========================================================================
   Base & Mobile-First Reset
   ========================================================================== */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font: var(--md-sys-typescale-body-large);
  background-color: var(--md-sys-color-background);
  color: var(--md-sys-color-on-background);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* Mobile-first centered frame on desktop (max 600px) */
#app-root {
  width: 100%;
  max-width: 600px;
  min-height: 100vh;
  background-color: var(--md-sys-color-surface);
  position: relative;
  display: flex;
  flex-direction: column;
  box-shadow: var(--md-sys-elevation-level-1);
}

/* Header / Top App Bar */
.m3-top-app-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background-color: var(--md-sys-color-surface);
  border-bottom: 1px solid var(--md-sys-color-surface-container-high);
}

.m3-top-app-bar__title {
  font: var(--md-sys-typescale-title-large);
  color: var(--md-sys-color-on-surface);
  display: flex;
  align-items: center;
  gap: 12px;
}

.m3-top-app-bar__title svg {
  width: 28px;
  height: 28px;
}

/* Main Content Area */
main.m3-content {
  flex: 1;
  padding: 24px 16px 96px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* M3 Navigation Bar (Bottom) */
.m3-navigation-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 600px;
  height: 80px;
  background-color: var(--md-sys-color-surface-container);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 30;
  box-shadow: var(--md-sys-elevation-level-2);
}

.m3-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  flex: 1;
  padding: 8px 0;
  gap: 4px;
  color: var(--md-sys-color-on-surface-variant);
}

.m3-nav-item__pill {
  width: 56px;
  height: 32px;
  border-radius: var(--md-sys-shape-corner-full);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.m3-nav-item svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.m3-nav-item__label {
  font: var(--md-sys-typescale-label-medium);
  transition: font-weight 0.2s ease;
}

.m3-nav-item.active .m3-nav-item__pill {
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.m3-nav-item.active .m3-nav-item__label {
  color: var(--md-sys-color-on-surface);
  font-weight: 700;
}

/* M3 Floating Action Button (FAB) */
.m3-fab {
  position: fixed;
  bottom: 96px;
  right: calc(50% - 300px + 16px);
  width: 56px;
  height: 56px;
  border-radius: var(--md-sys-shape-corner-large);
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--md-sys-elevation-level-3);
  z-index: 25;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

@media (max-width: 600px) {
  .m3-fab {
    right: 16px;
  }
}

.m3-fab:active {
  transform: scale(0.95);
  box-shadow: var(--md-sys-elevation-level-1);
}

.m3-fab svg {
  width: 28px;
  height: 28px;
  fill: currentColor;
}

/* ==========================================================================
   M3 Cards (12px / 16px corner radius)
   ========================================================================== */

.m3-card {
  background-color: var(--md-sys-color-surface-container-low);
  border-radius: var(--md-sys-shape-corner-large);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 1px solid var(--md-sys-color-outline-variant);
  transition: background-color 0.15s ease;
}

.m3-card--clickable {
  cursor: pointer;
}

.m3-card--clickable:hover {
  background-color: var(--md-sys-color-surface-container);
}

.m3-card__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.m3-card__title {
  font: var(--md-sys-typescale-title-medium);
  color: var(--md-sys-color-on-surface);
}

.m3-card__meta {
  font: var(--md-sys-typescale-body-small);
  color: var(--md-sys-color-on-surface-variant);
}

.m3-card__description {
  font: var(--md-sys-typescale-body-medium);
  color: var(--md-sys-color-on-surface-variant);
}

.m3-card__actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

/* ==========================================================================
   M3 Badges / Status Chips
   ========================================================================== */

.m3-badge {
  font: var(--md-sys-typescale-label-small);
  padding: 4px 10px;
  border-radius: var(--md-sys-shape-corner-full);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.m3-badge--upcoming {
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.m3-badge--overdue {
  background-color: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}

.m3-badge--completed {
  background-color: var(--md-custom-status-success-container);
  color: var(--md-custom-status-on-success-container);
}

.m3-badge--snoozed {
  background-color: var(--md-custom-status-warning-container);
  color: var(--md-custom-status-on-warning-container);
}

.m3-badge--ignored {
  background-color: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface-variant);
}

/* ==========================================================================
   M3 Buttons (Full Pill Shape: 9999px)
   ========================================================================== */

.m3-btn {
  font: var(--md-sys-typescale-label-large);
  height: 40px;
  padding: 0 20px;
  border-radius: var(--md-sys-shape-corner-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  cursor: pointer;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
  white-space: nowrap;
}

.m3-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.m3-btn--filled {
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.m3-btn--filled:hover {
  box-shadow: var(--md-sys-elevation-level-1);
}

.m3-btn--tonal {
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.m3-btn--outlined {
  background-color: transparent;
  color: var(--md-sys-color-primary);
  border: 1px solid var(--md-sys-color-outline);
}

.m3-btn--text {
  background-color: transparent;
  color: var(--md-sys-color-primary);
  padding: 0 12px;
}

.m3-btn--danger {
  background-color: var(--md-sys-color-error);
  color: var(--md-sys-color-on-error);
}

.m3-btn--full {
  width: 100%;
}

.m3-btn-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--md-sys-shape-corner-full);
  background: none;
  border: none;
  color: var(--md-sys-color-on-surface-variant);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.m3-btn-icon:hover {
  background-color: var(--md-sys-color-surface-container-high);
}

.m3-btn-icon svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

/* ==========================================================================
   M3 Text Fields & Forms
   ========================================================================== */

.m3-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.m3-field__label {
  font: var(--md-sys-typescale-body-small);
  color: var(--md-sys-color-on-surface-variant);
  font-weight: 500;
}

.m3-input {
  font: var(--md-sys-typescale-body-large);
  height: 52px;
  padding: 0 16px;
  border-radius: var(--md-sys-shape-corner-small);
  border: 1px solid var(--md-sys-color-outline);
  background-color: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  outline: none;
  transition: border-color 0.2s ease;
}

.m3-input:focus {
  border-color: var(--md-sys-color-primary);
  border-width: 2px;
  padding: 0 15px;
}

textarea.m3-input {
  height: 88px;
  padding: 12px 16px;
  resize: vertical;
}

.m3-checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.m3-chip-check {
  cursor: pointer;
}

.m3-chip-check input {
  display: none;
}

.m3-chip-check span {
  font: var(--md-sys-typescale-label-medium);
  padding: 6px 14px;
  border-radius: var(--md-sys-shape-corner-full);
  border: 1px solid var(--md-sys-color-outline);
  display: inline-block;
  color: var(--md-sys-color-on-surface-variant);
  transition: all 0.15s ease;
}

.m3-chip-check input:checked + span {
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-color: var(--md-sys-color-primary);
}

/* ==========================================================================
   M3 Dialogs (28px corner radius)
   ========================================================================== */

.m3-scrim {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.m3-dialog {
  background-color: var(--md-sys-color-surface-container-high);
  border-radius: var(--md-sys-shape-corner-extra-large);
  width: 100%;
  max-width: 500px;
  padding: 24px;
  box-shadow: var(--md-sys-elevation-level-3);
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 90vh;
  overflow-y: auto;
}

.m3-dialog__title {
  font: var(--md-sys-typescale-headline-small);
  color: var(--md-sys-color-on-surface);
}

.m3-dialog__content {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.m3-dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

/* Section headers */
.m3-section-title {
  font: var(--md-sys-typescale-title-medium);
  color: var(--md-sys-color-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 4px 0;
}

/* Empty state */
.m3-empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-body-medium);
  background-color: var(--md-sys-color-surface-container-lowest);
  border-radius: var(--md-sys-shape-corner-large);
  border: 1px dashed var(--md-sys-color-outline-variant);
}

/* Auth / Login View */
.m3-auth-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 70vh;
  gap: 24px;
  padding: 16px;
}

.m3-auth-card {
  background-color: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-extra-large);
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: var(--md-sys-elevation-level-2);
}

/* M3 Snackbar / Toast Notification */
.m3-snackbar {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 568px;
  background-color: #313033;
  color: #F4EFF4;
  font: var(--md-sys-typescale-body-medium);
  padding: 14px 16px;
  border-radius: var(--md-sys-shape-corner-small);
  box-shadow: var(--md-sys-elevation-level-3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 200;
  animation: m3-snackbar-slide 0.2s cubic-bezier(0, 0, 0.2, 1);
}

@keyframes m3-snackbar-slide {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

@media (prefers-color-scheme: dark) {
  .m3-snackbar {
    background-color: #E2E2E6;
    color: #1A1C1E;
  }
}

[data-theme="dark"] .m3-snackbar {
  background-color: #E2E2E6;
  color: #1A1C1E;
}

[data-theme="light"] .m3-snackbar {
  background-color: #313033;
  color: #F4EFF4;
}

/* Utilities */
.hidden {
  display: none !important;
}

.text-error {
  color: var(--md-sys-color-error);
  font: var(--md-sys-typescale-body-small);
}
