/**
 * Material Design 3 Components
 * Buttons, Forms, Cards, Navigation, etc.
 */

/* ============================================
   Buttons
   ============================================ */

.md-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--md-sys-spacing-sm);
  padding: 10px 24px;
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  font-family: var(--md-sys-typescale-font-family);
  font-size: var(--md-sys-typescale-label-large-size);
  font-weight: var(--md-sys-typescale-label-large-weight);
  line-height: var(--md-sys-typescale-label-large-line-height);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
  position: relative;
  overflow: hidden;
}

.md-button:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  pointer-events: none;
}

/* Filled Button (Primary) */
.md-button--filled {
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  box-shadow: var(--md-sys-elevation-0);
}

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

.md-button--filled:active {
  box-shadow: var(--md-sys-elevation-0);
}

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

.md-button--outlined:hover {
  background-color: rgba(25, 118, 210, var(--md-sys-state-hover-opacity));
}

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

.md-button--text:hover {
  background-color: rgba(25, 118, 210, var(--md-sys-state-hover-opacity));
}

/* Elevated Button */
.md-button--elevated {
  background-color: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-primary);
  box-shadow: var(--md-sys-elevation-1);
}

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

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

.md-button--tonal:hover {
  box-shadow: var(--md-sys-elevation-1);
}

/* Small Button */
.md-button--small {
  padding: 6px 16px;
  font-size: var(--md-sys-typescale-label-medium-size);
}

/* Icon Button */
.md-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  background-color: transparent;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: background-color 0.2s;
}

.md-icon-button:hover {
  background-color: rgba(0, 0, 0, var(--md-sys-state-hover-opacity));
}

/* FAB (Floating Action Button) */
.md-fab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--md-sys-spacing-sm);
  min-width: 56px;
  height: 56px;
  padding: 16px;
  border: none;
  border-radius: var(--md-sys-shape-corner-large);
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  box-shadow: var(--md-sys-elevation-3);
  cursor: pointer;
  transition: all 0.2s;
}

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

/* ============================================
   Form Elements
   ============================================ */

/* Text Field (Filled) */
.md-text-field {
  position: relative;
  width: 100%;
  margin-bottom: var(--md-sys-spacing-md);
}

.md-text-field__input {
  width: 100%;
  padding: 24px 16px 8px;
  border: none;
  border-bottom: 1px solid var(--md-sys-color-on-surface-variant);
  border-radius: var(--md-sys-shape-corner-extra-small) var(--md-sys-shape-corner-extra-small) 0 0;
  background-color: #ffffff;
  color: var(--md-sys-color-on-surface);
  font-family: var(--md-sys-typescale-font-family);
  font-size: var(--md-sys-typescale-body-large-size);
  line-height: var(--md-sys-typescale-body-large-line-height);
  outline: none;
  transition: border-color 0.2s;
}

.md-text-field__input:focus {
  border-bottom-width: 2px;
  border-bottom-color: var(--md-sys-color-primary);
}

.md-text-field__input::placeholder {
  color: transparent;
}

.md-text-field__label {
  position: absolute;
  left: 16px;
  top: 16px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-body-large-size);
  transition: all 0.2s;
  pointer-events: none;
}

.md-text-field__input:focus ~ .md-text-field__label,
.md-text-field__input:not(:placeholder-shown) ~ .md-text-field__label {
  top: 8px;
  font-size: var(--md-sys-typescale-body-small-size);
  color: var(--md-sys-color-primary);
}

.md-text-field__helper-text {
  display: block;
  margin-top: 4px;
  padding: 0 16px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-body-small-size);
}

.md-text-field--error .md-text-field__input {
  border-bottom-color: var(--md-sys-color-error);
}

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

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

/* Text Field (Outlined) */
.md-text-field--outlined .md-text-field__input {
  padding: 16px;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-extra-small);
  background-color: transparent;
}

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

.md-text-field--outlined .md-text-field__label {
  top: 16px;
  background-color: var(--md-sys-color-surface);
  padding: 0 4px;
}

.md-text-field--outlined .md-text-field__input:focus ~ .md-text-field__label,
.md-text-field--outlined .md-text-field__input:not(:placeholder-shown) ~ .md-text-field__label {
  top: -8px;
  font-size: var(--md-sys-typescale-body-small-size);
}

/* Checkbox */
.md-checkbox {
  display: inline-flex;
  align-items: center;
  gap: var(--md-sys-spacing-sm);
  cursor: pointer;
  user-select: none;
}

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

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

.md-checkbox__input:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 2px;
  width: 4px;
  height: 8px;
  border: solid var(--md-sys-color-on-primary);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.md-checkbox__label {
  font-size: var(--md-sys-typescale-body-medium-size);
  color: var(--md-sys-color-on-surface);
}

/* Direct input/select styling with md-text-field class */
input.md-text-field,
select.md-text-field,
textarea.md-text-field {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-extra-small);
  background-color: #ffffff;
  color: var(--md-sys-color-on-surface);
  font-family: var(--md-sys-typescale-font-family);
  font-size: var(--md-sys-typescale-body-large-size);
  line-height: var(--md-sys-typescale-body-large-line-height);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input.md-text-field:focus,
select.md-text-field:focus,
textarea.md-text-field:focus {
  border-width: 2px;
  border-color: var(--md-sys-color-primary);
  padding: 13px 15px;
  box-shadow: 0 0 0 1px var(--md-sys-color-primary);
}

select.md-text-field {
  cursor: pointer;
  appearance: none;
  background-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12"><path fill="%23666" d="M10.293 3.293L6 7.586 1.707 3.293A1 1 0 00.293 4.707l5 5a1 1 0 001.414 0l5-5a1 1 0 10-1.414-1.414z"/></svg>');
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 40px;
}

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

/* Select */
.md-select {
  position: relative;
  width: 100%;
  margin-bottom: var(--md-sys-spacing-md);
}

.md-select__input {
  width: 100%;
  padding: 16px;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-extra-small);
  background-color: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font-family: var(--md-sys-typescale-font-family);
  font-size: var(--md-sys-typescale-body-large-size);
  cursor: pointer;
  outline: none;
}

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

/* ============================================
   Cards
   ============================================ */

.md-card {
  background-color: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-medium);
  overflow: hidden;
}

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

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

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

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

.md-card--interactive {
  cursor: pointer;
  transition: box-shadow 0.2s, transform 0.2s;
}

.md-card--interactive:hover {
  box-shadow: var(--md-sys-elevation-2);
  transform: translateY(-2px);
}

.md-card__header {
  padding: var(--md-sys-spacing-md);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--md-sys-spacing-sm);
}

.md-card__content {
  padding: var(--md-sys-spacing-md);
}

.md-card__title {
  font-size: var(--md-sys-typescale-title-large-size);
  font-weight: var(--md-sys-typescale-title-large-weight);
  line-height: var(--md-sys-typescale-title-large-line-height);
  color: var(--md-sys-color-on-surface);
  margin: 0;
  display: flex;
  align-items: center;
}

.md-card__subtitle {
  font-size: var(--md-sys-typescale-body-medium-size);
  color: var(--md-sys-color-on-surface-variant);
  margin: 0;
}

.md-card__text {
  font-size: var(--md-sys-typescale-body-medium-size);
  color: var(--md-sys-color-on-surface);
  margin: 0;
}

.md-card__actions {
  display: flex;
  gap: var(--md-sys-spacing-sm);
  padding: var(--md-sys-spacing-sm) var(--md-sys-spacing-md);
  flex-wrap: wrap;
}

/* ============================================
   Dialogs / Modals
   ============================================ */

.md-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  min-width: 280px;
  max-width: 560px;
  background-color: var(--md-sys-color-surface-container-high);
  border-radius: var(--md-sys-shape-corner-extra-large);
  box-shadow: var(--md-sys-elevation-3);
  z-index: 1000;
}

.md-dialog__header {
  padding: var(--md-sys-spacing-lg) var(--md-sys-spacing-lg) var(--md-sys-spacing-md);
}

.md-dialog__title {
  font-size: var(--md-sys-typescale-headline-small-size);
  font-weight: var(--md-sys-typescale-headline-small-weight);
  color: var(--md-sys-color-on-surface);
  margin: 0;
}

.md-dialog__content {
  padding: 0 var(--md-sys-spacing-lg) var(--md-sys-spacing-lg);
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-body-medium-size);
}

.md-dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--md-sys-spacing-sm);
  padding: var(--md-sys-spacing-md) var(--md-sys-spacing-lg) var(--md-sys-spacing-lg);
}

.md-dialog-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.4);
  z-index: 999;
}

/* ============================================
   Chips
   ============================================ */

.md-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--md-sys-spacing-xs);
  height: 32px;
  padding: 0 var(--md-sys-spacing-md);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-small);
  background-color: transparent;
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-label-large-size);
  font-weight: var(--md-sys-typescale-label-large-weight);
  cursor: pointer;
  transition: background-color 0.2s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.md-chip:hover {
  background-color: rgba(0, 0, 0, var(--md-sys-state-hover-opacity));
}

.md-chip--filled {
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  border: none;
}

.md-chip--small {
  height: 24px;
  padding: 0 var(--md-sys-spacing-sm);
  font-size: var(--md-sys-typescale-label-small-size);
}

/* ============================================
   Lists
   ============================================ */

.md-list {
  list-style: none;
  margin: 0;
  padding: var(--md-sys-spacing-sm) 0;
  background-color: var(--md-sys-color-surface);
}

.md-list-item {
  display: flex;
  align-items: center;
  gap: var(--md-sys-spacing-md);
  padding: var(--md-sys-spacing-sm) var(--md-sys-spacing-md);
  cursor: pointer;
  transition: background-color 0.2s;
}

.md-list-item:hover {
  background-color: rgba(0, 0, 0, var(--md-sys-state-hover-opacity));
}

.md-list-item__text {
  flex: 1;
}

.md-list-item__headline {
  font-size: var(--md-sys-typescale-body-large-size);
  color: var(--md-sys-color-on-surface);
  margin: 0;
}

.md-list-item__supporting {
  font-size: var(--md-sys-typescale-body-medium-size);
  color: var(--md-sys-color-on-surface-variant);
  margin: 0;
}

/* ============================================
   Divider
   ============================================ */

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

/* ============================================
   Snackbar / Toast
   ============================================ */

.md-snackbar {
  position: fixed;
  bottom: var(--md-sys-spacing-md);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: var(--md-sys-spacing-md);
  min-width: 344px;
  max-width: 672px;
  padding: var(--md-sys-spacing-md) var(--md-sys-spacing-md);
  background-color: var(--md-sys-color-inverse-surface);
  color: var(--md-sys-color-inverse-on-surface);
  border-radius: var(--md-sys-shape-corner-extra-small);
  box-shadow: var(--md-sys-elevation-3);
  z-index: 1000;
}

.md-snackbar__text {
  flex: 1;
  font-size: var(--md-sys-typescale-body-medium-size);
}

/* ============================================
   Badge
   ============================================ */

.md-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--md-sys-shape-corner-full);
  background-color: var(--md-sys-color-error);
  color: var(--md-sys-color-on-error);
  font-size: var(--md-sys-typescale-label-small-size);
  font-weight: var(--md-sys-typescale-label-small-weight);
}

/* ============================================
   Progress Indicators
   ============================================ */

.md-progress-linear {
  width: 100%;
  height: 4px;
  background-color: var(--md-sys-color-surface-container-highest);
  border-radius: var(--md-sys-shape-corner-full);
  overflow: hidden;
}

.md-progress-linear__bar {
  height: 100%;
  background-color: var(--md-sys-color-primary);
  transition: width 0.3s;
}

.md-progress-circular {
  display: inline-block;
  width: 48px;
  height: 48px;
  border: 4px solid var(--md-sys-color-surface-container-highest);
  border-top-color: var(--md-sys-color-primary);
  border-radius: 50%;
  animation: md-progress-spin 1s linear infinite;
}

@keyframes md-progress-spin {
  to { transform: rotate(360deg); }
}
