/* Botones M3 */
.m3-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 24px;
  border-radius: var(--md-sys-shape-corner-full);
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  gap: 8px;
  transition: box-shadow 0.2s, background-color 0.2s;
  text-decoration: none;
}

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

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

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

/* Tarjetas M3 */
.m3-card {
  background-color: var(--md-sys-color-surface-container-low);
  border-radius: var(--md-sys-shape-corner-large);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 1px solid var(--md-sys-color-outline-variant);
}
.m3-card--outlined {
  background-color: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
}

/* Campos de texto Outlined M3 */
.m3-text-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}
.m3-text-field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  padding-left: 4px;
}
.m3-text-field input {
  height: 56px;
  border-radius: var(--md-sys-shape-corner-small);
  border: 1px solid var(--md-sys-color-outline);
  background-color: transparent;
  color: var(--md-sys-color-on-surface);
  padding: 0 16px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}
.m3-text-field input:focus {
  border-color: var(--md-sys-color-primary);
  border-width: 2px;
}

/* Icon Button M3 */
.m3-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
  outline: none;
}
.m3-icon-button:hover {
  background-color: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
}
.m3-icon-button span.material-symbols-outlined {
  font-size: 24px;
}

/* User Badge M3 (Header) */
.m3-user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 8px;
  border-radius: 16px;
  background-color: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  transition: background-color 0.2s;
  height: 32px;
}
.m3-user-badge img {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  object-fit: cover;
}
.m3-user-badge span {
  font-size: 13px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
}

@media (max-width: 480px) {
  .m3-user-badge span {
    display: none;
  }
  .m3-user-badge {
    padding: 6px;
    border-radius: 50%;
    width: 32px;
    justify-content: center;
  }
}

/* Ocultar botón de logout nativo en cabecera */
.m3-top-app-bar #btn-logout {
  display: none !important;
}

/* Dropdown Menu M3 */
.m3-dropdown-wrapper {
  position: relative;
  display: inline-block;
}

.m3-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background-color: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  padding: 8px 0;
  min-width: 180px;
  z-index: 1000;
  display: none;
  flex-direction: column;
}

.m3-dropdown-menu.visible {
  display: flex;
}

.m3-dropdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.2s;
  outline: none;
}

.m3-dropdown-item:hover {
  background-color: var(--md-sys-color-surface-container-highest);
}

.m3-dropdown-item span.material-symbols-outlined {
  font-size: 20px;
  color: var(--md-sys-color-on-surface-variant);
}


/* M3 Select Dropdown Fallback */
.m3-select {
  width: 100%;
  height: 56px;
  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-container);
  color: var(--md-sys-color-on-surface);
  font-family: inherit;
  font-size: 16px;
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2349454F'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  background-size: 24px;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
}

.m3-select:focus {
  border-color: var(--md-sys-color-primary);
  border-width: 2px;
}

.m3-select optgroup {
  font-weight: 700;
  color: var(--md-sys-color-primary);
  background-color: var(--md-sys-color-surface-container-high);
  font-style: normal;
  font-size: 13px;
  padding: 6px 4px;
}

.m3-select option {
  background-color: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  font-weight: 400;
  font-size: 14px;
  padding: 6px 12px;
}

/* Custom M3 Outlined Select Wrapper */
.m3-select-wrapper {
  position: relative;
  width: 100%;
  box-sizing: border-box;
}

/* Hide the original select when custom styling is active */
.m3-select-wrapper select.m3-select {
  display: none !important;
}

/* Custom Trigger */
.m3-select-trigger {
  width: 100%;
  height: 56px;
  padding: 0 44px 0 16px;
  border-radius: var(--md-sys-shape-corner-small, 8px);
  border: 1px solid var(--md-sys-color-outline);
  background-color: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  font-family: inherit;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  box-sizing: border-box;
  transition: border-color 0.15s, box-shadow 0.15s;
  user-select: none;
  position: relative;
}

.m3-select-trigger::after {
  content: "";
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2349454F'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: 24px;
  transition: transform 0.2s;
}

.m3-select-wrapper.open .m3-select-trigger::after {
  transform: translateY(-50%) rotate(180deg);
}

.m3-select-trigger:focus,
.m3-select-wrapper.open .m3-select-trigger {
  border-color: var(--md-sys-color-primary);
  border-width: 2px;
  box-shadow: 0 0 0 1px var(--md-sys-color-primary);
}

/* Floating Menu Popover (Elevation Level 2) */
.m3-select-menu {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  max-height: 250px;
  overflow-y: auto;
  margin-top: 4px;
  background-color: var(--md-sys-color-surface-container-high);
  border-radius: var(--md-sys-shape-corner-small, 8px);
  border: 1px solid var(--md-sys-color-outline-variant);
  box-shadow: 0px 4px 16px rgba(0, 0, 0, 0.2);
  z-index: 9999;
  display: none;
  box-sizing: border-box;
}

.m3-select-wrapper.open .m3-select-menu {
  display: block;
}

/* Custom Option Item */
.m3-select-option {
  padding: 12px 16px;
  font-size: 15px;
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
  transition: background-color 0.15s;
  user-select: none;
}

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

.m3-select-option.selected {
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  font-weight: 500;
}

.m3-select-option.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Reset .m3-text-field styles when wrapping a custom select to prevent conflicting layouts */
.m3-text-field:has(.m3-select-wrapper) {
  border: none !important;
  background: transparent !important;
  height: auto !important;
  padding: 0 !important;
  box-shadow: none !important;
  overflow: visible !important;
  display: block !important;
}

.m3-text-field:has(.m3-select-wrapper) label {
  position: static !important;
  display: block !important;
  margin-bottom: 6px !important;
  font-size: 13px !important;
  color: var(--md-sys-color-on-surface-variant) !important;
  transform: none !important;
  pointer-events: auto !important;
}

/* Material 3 Switch Component */
.m3-switch {
  display: inline-block;
  position: relative;
  width: 52px;
  height: 32px;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}

.m3-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.m3-switch-track {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--md-sys-color-surface-container-highest);
  border: 2px solid var(--md-sys-color-outline);
  border-radius: 16px;
  transition: background-color 0.2s, border-color 0.2s;
  box-sizing: border-box;
}

.m3-switch-thumb {
  position: absolute;
  top: 50%;
  left: 6px;
  transform: translateY(-50%);
  height: 16px;
  width: 16px;
  background-color: var(--md-sys-color-outline);
  border-radius: 50%;
  transition: transform 0.2s, background-color 0.2s, width 0.2s, height 0.2s, left 0.2s;
  box-sizing: border-box;
}

/* Checked State */
.m3-switch input:checked + .m3-switch-track {
  background-color: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-primary);
}

.m3-switch input:checked + .m3-switch-track .m3-switch-thumb {
  transform: translate(20px, -50%);
  background-color: var(--md-sys-color-on-primary);
  height: 24px;
  width: 24px;
  left: 2px;
}

/* Disabled State */
.m3-switch input:disabled + .m3-switch-track {
  opacity: 0.38;
  cursor: not-allowed;
}



