/**
 * Material 3 Utility Classes
 * Uses CSS variables from theme files for consistent theming
 */

/* ========================================
   COLOR UTILITIES
   ======================================== */

/* Surface colors */
.bg-surface { background-color: var(--md-sys-color-surface); }
.bg-surface-dim { background-color: var(--md-sys-color-surface-dim); }
.bg-surface-bright { background-color: var(--md-sys-color-surface-bright); }
.bg-surface-container { background-color: var(--md-sys-color-surface-container); }
.bg-surface-container-low { background-color: var(--md-sys-color-surface-container-low); }
.bg-surface-container-high { background-color: var(--md-sys-color-surface-container-high); }
.bg-surface-container-highest { background-color: var(--md-sys-color-surface-container-highest); }
.bg-surface-variant { background-color: var(--md-sys-color-surface-variant); }

/* Primary colors */
.bg-primary { background-color: var(--md-sys-color-primary); }
.bg-primary-container { background-color: var(--md-sys-color-primary-container); }
.text-primary { color: var(--md-sys-color-primary); }
.text-on-primary { color: var(--md-sys-color-on-primary); }
.text-on-primary-container { color: var(--md-sys-color-on-primary-container); }

/* Secondary colors */
.bg-secondary { background-color: var(--md-sys-color-secondary); }
.bg-secondary-container { background-color: var(--md-sys-color-secondary-container); }
.text-secondary { color: var(--md-sys-color-secondary); }
.text-on-secondary { color: var(--md-sys-color-on-secondary); }
.text-on-secondary-container { color: var(--md-sys-color-on-secondary-container); }

/* Tertiary colors */
.bg-tertiary { background-color: var(--md-sys-color-tertiary); }
.bg-tertiary-container { background-color: var(--md-sys-color-tertiary-container); }
.text-tertiary { color: var(--md-sys-color-tertiary); }
.text-on-tertiary { color: var(--md-sys-color-on-tertiary); }
.text-on-tertiary-container { color: var(--md-sys-color-on-tertiary-container); }

/* Error colors */
.bg-error { background-color: var(--md-sys-color-error); }
.bg-error-container { background-color: var(--md-sys-color-error-container); }
.text-error { color: var(--md-sys-color-error); }
.text-on-error { color: var(--md-sys-color-on-error); }
.text-on-error-container { color: var(--md-sys-color-on-error-container); }

/* Text colors */
.text-on-surface { color: var(--md-sys-color-on-surface); }
.text-on-surface-variant { color: var(--md-sys-color-on-surface-variant); }
.text-on-background { color: var(--md-sys-color-on-background); }

/* Border colors */
.border-outline { border-color: var(--md-sys-color-outline); }
.border-outline-variant { border-color: var(--md-sys-color-outline-variant); }

/* ========================================
   MATERIAL 3 COMPONENTS
   ======================================== */

/* Base reset for Material 3 */
.m3-reset {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Typography Scale (Material 3) */
.text-display-large {
  font-size: 57px;
  line-height: 64px;
  font-weight: 400;
  letter-spacing: -0.25px;
}

.text-display-medium {
  font-size: 45px;
  line-height: 52px;
  font-weight: 400;
}

.text-display-small {
  font-size: 36px;
  line-height: 44px;
  font-weight: 400;
}

.text-headline-large {
  font-size: 32px;
  line-height: 40px;
  font-weight: 400;
}

.text-headline-medium {
  font-size: 28px;
  line-height: 36px;
  font-weight: 400;
}

.text-headline-small {
  font-size: 24px;
  line-height: 32px;
  font-weight: 400;
}

.text-title-large {
  font-size: 22px;
  line-height: 28px;
  font-weight: 400;
}

.text-title-medium {
  font-size: 16px;
  line-height: 24px;
  font-weight: 500;
  letter-spacing: 0.15px;
}

.text-title-small {
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
  letter-spacing: 0.1px;
}

.text-body-large {
  font-size: 16px;
  line-height: 24px;
  font-weight: 400;
  letter-spacing: 0.5px;
}

.text-body-medium {
  font-size: 14px;
  line-height: 20px;
  font-weight: 400;
  letter-spacing: 0.25px;
}

.text-body-small {
  font-size: 12px;
  line-height: 16px;
  font-weight: 400;
  letter-spacing: 0.4px;
}

.text-label-large {
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
  letter-spacing: 0.1px;
}

.text-label-medium {
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  letter-spacing: 0.5px;
}

.text-label-small {
  font-size: 11px;
  line-height: 16px;
  font-weight: 500;
  letter-spacing: 0.5px;
}

/* ========================================
   BUTTONS (Material 3)
   ======================================== */

/* Base button styles */
.m3-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 24px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.1px;
  line-height: 20px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: none;
  outline: none;
  position: relative;
  overflow: hidden;
  min-height: 40px;
}

.m3-button:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

/* State layer overlay */
.m3-button::before {
  content: '';
  position: absolute;
  inset: 0;
  background: currentColor;
  opacity: 0;
  transition: opacity 0.2s;
}

.m3-button:hover::before {
  opacity: 0.08;
}

.m3-button:focus::before {
  opacity: 0.12;
}

.m3-button:active::before {
  opacity: 0.12;
}

/* Focus ring */
.m3-button:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

/* Filled button (Primary) */
.m3-button-filled {
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  box-shadow: 0 1px 3px 1px rgba(0, 0, 0, 0.15),
              0 1px 2px 0 rgba(0, 0, 0, 0.3);
}

.m3-button-filled:hover {
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.3),
              0 2px 6px 2px rgba(0, 0, 0, 0.15);
}

/* Filled tonal button */
.m3-button-filled-tonal {
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

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

/* Text button */
.m3-button-text {
  background-color: transparent;
  color: var(--md-sys-color-primary);
  padding: 10px 12px;
}

/* Elevated button */
.m3-button-elevated {
  background-color: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-primary);
  box-shadow: 0 1px 3px 1px rgba(0, 0, 0, 0.15),
              0 1px 2px 0 rgba(0, 0, 0, 0.3);
}

/* Icon buttons */
.m3-icon-button {
  width: 40px;
  height: 40px;
  padding: 8px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  position: relative;
  overflow: hidden;
  transition: all 0.2s;
}

.m3-icon-button::before {
  content: '';
  position: absolute;
  inset: 0;
  background: currentColor;
  opacity: 0;
  transition: opacity 0.2s;
}

.m3-icon-button:hover::before {
  opacity: 0.08;
}

.m3-icon-button:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

/* ========================================
   CARDS (Material 3)
   ======================================== */

.m3-card {
  background-color: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface);
  border-radius: 12px;
  padding: 16px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.m3-card-elevated {
  box-shadow: 0 1px 3px 1px rgba(0, 0, 0, 0.15),
              0 1px 2px 0 rgba(0, 0, 0, 0.3);
}

.m3-card-elevated:hover {
  box-shadow: 0 2px 6px 2px rgba(0, 0, 0, 0.15),
              0 1px 2px 0 rgba(0, 0, 0, 0.3);
}

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

.m3-card-outlined {
  background-color: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
}

/* ========================================
   INPUTS (Material 3)
   ======================================== */

.m3-text-field {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  width: 100%;
}

.m3-text-field-input {
  padding: 16px;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: 4px;
  background-color: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  font-size: 16px;
  line-height: 24px;
  transition: all 0.2s;
  outline: none;
}

.m3-text-field-input::placeholder {
  color: var(--md-sys-color-on-surface-variant);
  opacity: 0.6;
}

.m3-text-field-input:hover {
  border-color: var(--md-sys-color-on-surface);
}

.m3-text-field-input:focus {
  border-color: var(--md-sys-color-primary);
  border-width: 2px;
  padding: 15px; /* Compensate for thicker border */
}

.m3-text-field-input:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

/* Error state */
.m3-text-field-error .m3-text-field-input {
  border-color: var(--md-sys-color-error);
}

.m3-text-field-helper {
  font-size: 12px;
  line-height: 16px;
  color: var(--md-sys-color-on-surface-variant);
  margin-top: 4px;
  padding: 0 16px;
}

.m3-text-field-error .m3-text-field-helper {
  color: var(--md-sys-color-error);
}

/* ========================================
   TABLES (Material 3)
   ======================================== */

.m3-table {
  width: 100%;
  border-collapse: collapse;
  background-color: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
}

.m3-table thead {
  background-color: var(--md-sys-color-surface-container);
}

.m3-table th {
  text-align: left;
  padding: 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.m3-table td {
  padding: 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.m3-table tbody tr:hover {
  background-color: var(--md-sys-color-surface-container-low);
}

/* Zebra striping */
.m3-table-striped tbody tr:nth-child(even) {
  background-color: var(--md-sys-color-surface-container-lowest);
}

/* ========================================
   ELEVATION (Material 3)
   ======================================== */

:root {
  --md-sys-elevation-0: none;
  --md-sys-elevation-1: 0 1px 2px 0 rgba(0, 0, 0, 0.3), 0 1px 3px 1px rgba(0, 0, 0, 0.15);
  --md-sys-elevation-2: 0 1px 2px 0 rgba(0, 0, 0, 0.3), 0 2px 6px 2px rgba(0, 0, 0, 0.15);
  --md-sys-elevation-3: 0 4px 8px 3px rgba(0, 0, 0, 0.15), 0 1px 3px 0 rgba(0, 0, 0, 0.3);
  --md-sys-elevation-4: 0 6px 10px 4px rgba(0, 0, 0, 0.15), 0 2px 3px 0 rgba(0, 0, 0, 0.3);
  --md-sys-elevation-5: 0 8px 12px 6px rgba(0, 0, 0, 0.15), 0 4px 4px 0 rgba(0, 0, 0, 0.3);
}

.m3-elevation-0 {
  box-shadow: var(--md-sys-elevation-0);
}

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

.m3-elevation-2 {
  box-shadow: var(--md-sys-elevation-2);
}

.m3-elevation-3 {
  box-shadow: var(--md-sys-elevation-3);
}

.m3-elevation-4 {
  box-shadow: var(--md-sys-elevation-4);
}

.m3-elevation-5 {
  box-shadow: var(--md-sys-elevation-5);
}

/* ========================================
   SPACING UTILITIES
   ======================================== */

.m3-spacing-xs { padding: 4px; }
.m3-spacing-sm { padding: 8px; }
.m3-spacing-md { padding: 16px; }
.m3-spacing-lg { padding: 24px; }
.m3-spacing-xl { padding: 32px; }

.m3-gap-xs { gap: 4px; }
.m3-gap-sm { gap: 8px; }
.m3-gap-md { gap: 16px; }
.m3-gap-lg { gap: 24px; }
.m3-gap-xl { gap: 32px; }

/* ========================================
   DIVIDERS
   ======================================== */

.m3-divider {
  height: 1px;
  background-color: var(--md-sys-color-outline-variant);
  border: none;
  margin: 16px 0;
}

.m3-divider-vertical {
  width: 1px;
  height: 100%;
  background-color: var(--md-sys-color-outline-variant);
  border: none;
  margin: 0 16px;
}

/* ========================================
   BADGES
   ======================================== */

.m3-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.5px;
}

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

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

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