/**
 * MD3 Components - Material Design 3
 * Shared UI components used across all pages (admin and public)
 *
 * This file contains reusable MD3 components:
 * - Design tokens (colors, elevation)
 * - Base styles
 * - Buttons
 * - Text fields
 * - Checkboxes
 * - Dialogs/Modals
 * - Cards
 * - Badges
 * - Loading spinners
 */

/* ========== MD3 Design Tokens ========== */
:root {
  /* MD3 Color Tokens - Dark Theme */
  --md-sys-color-primary: #A8C7FA;
  --md-sys-color-on-primary: #062E6F;
  --md-sys-color-primary-container: #1B4694;
  --md-sys-color-on-primary-container: #D8E2FF;

  --md-sys-color-secondary: #BCC7DB;
  --md-sys-color-on-secondary: #263141;
  --md-sys-color-secondary-container: #3C4758;
  --md-sys-color-on-secondary-container: #D8E3F8;

  --md-sys-color-tertiary: #D6BBDE;
  --md-sys-color-on-tertiary: #3B2948;
  --md-sys-color-tertiary-container: #523F5F;
  --md-sys-color-on-tertiary-container: #F2DAFB;

  --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-surface: #1A1C1E;
  --md-sys-color-on-surface: #E2E2E6;
  --md-sys-color-surface-variant: #43474E;
  --md-sys-color-on-surface-variant: #C3C6CF;

  --md-sys-color-outline: #8D9199;
  --md-sys-color-outline-variant: #43474E;

  --md-sys-color-background: #1A1C1E;
  --md-sys-color-on-background: #E2E2E6;

  /* Surface elevations */
  --md-sys-color-surface-1: #22252a;
  --md-sys-color-surface-2: #272a2f;
  --md-sys-color-surface-3: #2d3035;

  /* MD3 Elevation shadows */
  --md-sys-elevation-1: 0px 1px 2px 0px rgba(0, 0, 0, 0.3), 0px 1px 3px 1px rgba(0, 0, 0, 0.15);
  --md-sys-elevation-2: 0px 1px 2px 0px rgba(0, 0, 0, 0.3), 0px 2px 6px 2px rgba(0, 0, 0, 0.15);
  --md-sys-elevation-3: 0px 4px 8px 3px rgba(0, 0, 0, 0.15), 0px 1px 3px 0px rgba(0, 0, 0, 0.3);
}

/* ========== Base Styles ========== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Roboto', sans-serif;
  background: var(--md-sys-color-background);
  color: var(--md-sys-color-on-background);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ========== Custom Scrollbar ========== */
/* Webkit browsers (Chrome, Safari, Edge) */
::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

::-webkit-scrollbar-track {
  background: var(--md-sys-color-surface-1);
  border-radius: 6px;
}

::-webkit-scrollbar-thumb {
  background: var(--md-sys-color-outline);
  border-radius: 6px;
  border: 2px solid var(--md-sys-color-surface-1);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--md-sys-color-primary);
}

::-webkit-scrollbar-thumb:active {
  background: var(--md-sys-color-primary-container);
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--md-sys-color-outline) var(--md-sys-color-surface-1);
}

/* ========== MD3 Buttons ========== */
.md3-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 24px;
  border-radius: 20px;
  border: none;
  font-family: 'Roboto', sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  box-shadow: var(--md-sys-elevation-1);
}

.md3-button:hover {
  box-shadow: var(--md-sys-elevation-2);
  filter: brightness(1.1);
}

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

.md3-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.md3-button.filled:hover {
  background: var(--md-sys-color-primary-container);
  box-shadow: var(--md-sys-elevation-1);
}

.md3-button.outlined {
  background: transparent;
  color: var(--md-sys-color-primary);
  border: 1px solid var(--md-sys-color-outline);
  box-shadow: none;
}

.md3-button.outlined:hover {
  background: var(--md-sys-color-surface-1);
}

.md3-button.text {
  background: transparent;
  color: var(--md-sys-color-primary);
  box-shadow: none;
}

.md3-button.text:hover {
  background: var(--md-sys-color-surface-1);
}

.md3-button .material-icons {
  font-size: 18px;
}

.md3-button-small {
  padding: 6px 16px;
  font-size: 13px;
}

.md3-icon-button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.md3-icon-button:hover {
  background: var(--md-sys-color-surface-1);
}

.md3-icon-button .material-icons {
  font-size: 24px;
}

/* ========== MD3 Text Fields ========== */
.md3-text-field {
  position: relative;
  margin-bottom: 24px;
}

.md3-text-field input,
.md3-text-field textarea {
  width: 100%;
  padding: 16px;
  background: var(--md-sys-color-surface-2);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: 8px;
  color: var(--md-sys-color-on-surface);
  font-size: 16px;
  font-family: 'Roboto', sans-serif;
  transition: all 0.2s;
}

.md3-text-field input:focus,
.md3-text-field textarea:focus {
  outline: none;
  border-color: var(--md-sys-color-primary);
  border-width: 2px;
  padding: 15px;
}

.md3-text-field input::placeholder,
.md3-text-field textarea::placeholder {
  color: var(--md-sys-color-on-surface-variant);
}

.md3-text-field label {
  position: absolute;
  left: 16px;
  top: -10px;
  background: var(--md-sys-color-surface-1);
  padding: 0 4px;
  font-size: 12px;
  color: var(--md-sys-color-primary);
  font-weight: 500;
}

/* Error state for text fields */
.md3-text-field.error input,
.md3-text-field.error textarea {
  border-color: #dc2626;
  border-width: 2px;
}

.md3-text-field.error label {
  color: #dc2626;
}

.md3-text-field .error-text {
  color: #dc2626;
  font-size: 12px;
  margin-top: 4px;
  margin-bottom: 0;
}

.md3-text-field textarea {
  resize: vertical;
  min-height: 100px;
}

/* Hint text */
.hint {
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
  margin-top: 4px;
  padding-left: 16px;
}

/* ========== MD3 Checkbox ========== */
.md3-checkbox-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  padding: 0;
}

.md3-checkbox-wrapper label {
  flex: 1;
  line-height: 1.4;
  cursor: pointer;
  font-size: 14px;
  color: var(--md-sys-color-on-surface);
}

.md3-checkbox-wrapper label a {
  color: var(--md-sys-color-primary);
  text-decoration: none;
}

.md3-checkbox-wrapper label a:hover {
  text-decoration: underline;
}

.md3-checkbox-wrapper label a:visited {
  color: var(--md-sys-color-primary);
}

.md3-checkbox {
  position: relative;
  width: 18px;
  height: 18px;
  appearance: none;
  -webkit-appearance: none;
  border: 2px solid var(--md-sys-color-on-surface-variant);
  border-radius: 2px;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.md3-checkbox:hover {
  border-color: var(--md-sys-color-primary);
}

.md3-checkbox:checked {
  background: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-primary);
}

.md3-checkbox:checked::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 6px;
  height: 10px;
  border: solid var(--md-sys-color-on-primary);
  border-width: 0 2px 2px 0;
  transform: translate(-50%, -60%) rotate(45deg);
}

/* ========== MD3 Dialog / Modal ========== */
.md3-scrim {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}

.md3-scrim.hidden {
  display: none;
}

.md3-dialog {
  background: var(--md-sys-color-surface-1);
  border-radius: 16px;
  padding: 24px;
  max-width: 400px;
  width: 100%;
  box-shadow: var(--md-sys-elevation-2);
}

.md3-dialog h3 {
  font-size: 20px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  margin-bottom: 16px;
}

.md3-dialog p {
  font-size: 14px;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 24px;
}

.dialog-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
}

.dialog-actions .md3-button {
  width: auto;
  min-width: 100px;
}

/* ========== MD3 Card ========== */
.md3-card {
  background: var(--md-sys-color-surface-1);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--md-sys-elevation-1);
  transition: box-shadow 0.2s;
}

.md3-card:hover {
  box-shadow: var(--md-sys-elevation-2);
}

/* ========== Badge ========== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.badge.success {
  background: rgba(46, 125, 50, 0.2);
  color: #4CAF50;
}

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

.badge.warning {
  background: rgba(237, 108, 2, 0.2);
  color: #FF9800;
}

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

/* ========== Error Message ========== */
.error-message {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
  display: none;
  align-items: center;
  gap: 8px;
}

.error-message.show {
  display: flex;
}

.error-message .material-icons {
  font-size: 20px;
}

/* ========== Loading Spinner ========== */
.spinner {
  border: 2px solid var(--md-sys-color-surface-variant);
  border-top: 2px solid var(--md-sys-color-primary);
  border-radius: 50%;
  width: 18px;
  height: 18px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ========== Empty State ========== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--md-sys-color-on-surface-variant);
}

.empty-state .material-icons {
  font-size: 64px;
  color: var(--md-sys-color-outline);
  margin-bottom: 16px;
}

.empty-state p {
  font-size: 14px;
  color: var(--md-sys-color-on-surface-variant);
}

.empty-state.hidden {
  display: none;
}

/* ========== Toggle Switch ========== */
.toggle-switch {
  position: relative;
  width: 52px;
  height: 32px;
  background: var(--md-sys-color-surface-variant);
  border-radius: 16px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-switch.active {
  background: var(--md-sys-color-primary);
}

.toggle-knob {
  position: absolute;
  width: 28px;
  height: 28px;
  background: var(--md-sys-color-outline);
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: all 0.2s;
  box-shadow: var(--md-sys-elevation-1);
}

.toggle-switch.active .toggle-knob {
  left: 22px;
  background: var(--md-sys-color-on-primary);
}
