/* ============================================================
   MATERIAL DESIGN 3 — VERSIÓN MINIMALISTA Y COMPACTA
   Sobrescritura global para reducir espaciado y simplificar inputs
   ============================================================ */

:root {
  --md-primary: #2c2c2e;
  --md-on-primary: #ffffff;
  --md-primary-container: #eaeaeb;
  --md-on-primary-container: #2c2c2e;
  --md-secondary-container: #f1f5f9;
  --md-on-secondary-container: #1e293b;
  --md-surface: #ffffff;
  --md-surface-dim: #f8f7f4;
  --md-surface-container-low: #fafaf8;
  --md-outline: #d1cdc6;
  --md-outline-soft: #e5e2db;
  --md-on-surface: #1a1a1a;
  --md-on-surface-variant: #6b6560;
  --md-error: #b3261e;
  --md-error-container: #fce9e7;
  --md-radius: 12px;
  --md-radius-sm: 8px;
  --md-radius-xs: 4px;
  --md-elevation-1: 0 1px 3px rgba(0,0,0,0.04);
  --md-elevation-2: 0 2px 8px rgba(0,0,0,0.06);
  --md-elevation-3: 0 4px 16px rgba(0,0,0,0.08);
  --md-elevation-4: 0 8px 32px rgba(0,0,0,0.10);
  --md-motion: .15s ease;
  --md-motion-standard: .25s cubic-bezier(0.4, 0, 0.2, 1);
  --md-font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

/* ---------- Base ---------- */
.m-material {
  font-family: var(--md-font-family);
  color: var(--md-on-surface);
  background: var(--md-surface-dim);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* ---- Selección de texto ---- */
::selection { background: rgba(44,44,46,0.12); color: var(--md-on-surface); }

/* ---- Focus visible global ---- */
:focus-visible {
  outline: 2px solid var(--md-primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ============================================================
   📦 TARJETAS (compactas)
   ============================================================ */
.m-card {
  background: var(--md-surface);
  border-radius: var(--md-radius);
  box-shadow: var(--md-elevation-1);
  border: 1px solid var(--md-outline-soft);
  padding: 0.75rem 1rem;
  transition: box-shadow var(--md-motion-standard), transform var(--md-motion-standard), border-color var(--md-motion-standard);
}
.m-card.m-hover:hover {
  box-shadow: var(--md-elevation-2);
  transform: translateY(-1px);
  border-color: var(--md-outline);
}
.m-float {
  box-shadow: var(--md-elevation-2) !important;
}

/* ============================================================
   🌊 RIPPLE (efecto de onda)
   ============================================================ */
.m-ripple { position: relative; overflow: hidden; cursor: pointer; }
.m-ripple-ink {
  position: absolute;
  border-radius: 50%;
  background: currentColor;
  opacity: .12;
  transform: scale(0);
  animation: mRipple .6s ease-out forwards;
  pointer-events: none;
  z-index: 0;
}
@keyframes mRipple {
  to { transform: scale(1); opacity: 0; }
}

/* ============================================================
   🎛️ BOTONES (compactos)
   ============================================================ */
.m-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 32px;
  padding: 0 1rem;
  border-radius: 60px;
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  border: none;
  transition: background var(--md-motion-standard), box-shadow var(--md-motion-standard), transform var(--md-motion-standard), filter var(--md-motion-standard);
  user-select: none;
  white-space: nowrap;
}
.m-btn:active { transform: scale(.97); }
.m-btn-filled {
  background: var(--md-primary);
  color: var(--md-on-primary);
  box-shadow: var(--md-elevation-1);
}
.m-btn-filled:hover {
  box-shadow: var(--md-elevation-2);
  filter: brightness(1.05);
  transform: translateY(-1px);
}
.m-btn-tonal {
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
  transition: all var(--md-motion-standard);
}
.m-btn-tonal:hover {
  background: #e2e8f0;
  transform: translateY(-1px);
}
.m-btn-outlined {
  background: transparent;
  color: var(--md-primary);
  border: 1px solid var(--md-outline);
  transition: all var(--md-motion-standard);
}
.m-btn-outlined:hover {
  background: rgba(44,44,46,0.04);
  border-color: var(--md-primary);
}
.m-btn-text {
  background: transparent;
  color: var(--md-primary);
  padding: 0 0.8rem;
  transition: all var(--md-motion-standard);
}
.m-btn-text:hover { background: rgba(44,44,46,0.04); }
.m-btn-danger {
  background: var(--md-error);
  color: #fff;
  box-shadow: var(--md-elevation-1);
  transition: all var(--md-motion-standard);
}
.m-btn-danger:hover {
  box-shadow: var(--md-elevation-2);
  filter: brightness(1.05);
  transform: translateY(-1px);
}
.m-btn-sm { min-height: 28px; padding: 0 0.8rem; font-size: 0.7rem; }
.m-btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%; border: none; background: transparent;
  color: var(--md-on-surface-variant); cursor: pointer; position: relative; overflow: hidden;
  transition: background var(--md-motion-standard);
}
.m-btn-icon:hover { background: rgba(27,27,31,.06); }

/* ============================================================
   📝 CAMPOS DE TEXTO — Material, label flotante de verdad
   El label vive encima del input (position:absolute) sea cual sea
   el orden en el HTML — :has() detecta focus/contenido sin
   depender de que <label> venga antes o después de <input> en el
   markup (el proyecto no es consistente en eso entre vistas).
   ============================================================ */
.m-field {
  position: relative;
  margin-top: 1.35rem;
}
.m-field label {
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--md-on-surface-variant);
  background: transparent;
  padding: 0 0.3rem;
  pointer-events: none;
  max-width: calc(100% - 1.3rem);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transform-origin: left center;
  transition: top .16s cubic-bezier(.2,0,0,1), font-size .16s cubic-bezier(.2,0,0,1),
              color .16s ease, background-color .16s ease;
  z-index: 1;
}
.m-field input,
.m-field textarea,
.m-field select {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1.5px solid var(--md-outline);
  border-radius: var(--md-radius-sm);
  background: var(--md-surface-container-low);
  font-size: 0.85rem;
  font-family: var(--md-font-family);
  color: var(--md-on-surface);
  transition: border-color var(--md-motion), box-shadow var(--md-motion), background var(--md-motion);
  outline: none;
}
.m-field select { background: var(--md-surface-container-low); }
.m-field textarea { resize: vertical; min-height: 60px; }
.m-field input:focus,
.m-field textarea:focus,
.m-field select:focus {
  border-color: var(--md-primary);
  background: var(--md-surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--md-primary) 15%, transparent);
}
.m-field input::placeholder,
.m-field textarea::placeholder {
  color: transparent;
  transition: color .12s ease;
}
.m-field input:focus::placeholder,
.m-field textarea:focus::placeholder {
  color: var(--md-outline);
  opacity: 0.7;
}
/* Sube y se encoge: al enfocar o si ya tiene texto (inputs/textareas).
   Los <select> —nativos o mejorados por searchable-select.js (.ss-btn)—
   siempre traen un valor elegido, así que su label vive arriba fijo. */
.m-field:has(input:focus) label,
.m-field:has(input:not(:placeholder-shown)) label,
.m-field:has(textarea:focus) label,
.m-field:has(textarea:not(:placeholder-shown)) label,
.m-field:has(select) label,
.m-field:has(.ss-btn) label {
  top: 0;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--md-surface-container-low);
  /* Arriba ya no compite con el valor del campo, así que un label largo
     (p.ej. "Costo del proveedor (opcional — para tus reportes...)") puede
     mostrarse completo en vez de cortarse en "Costo del prov…". */
  max-width: calc(100% - 0.6rem);
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  line-height: 1.25;
}
.m-field:has(input:focus) label,
.m-field:has(textarea:focus) label,
.m-field:has(select:focus) label,
.m-field:has(.ss-wrap.ss-open) label {
  color: var(--md-primary);
}

/* ============================================================
   🏷️ CHIPS (compactos)
   ============================================================ */
.m-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  height: 28px;
  padding: 0 0.7rem;
  border-radius: 60px;
  border: 1px solid var(--md-outline-soft);
  background: var(--md-surface);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--md-on-surface-variant);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all var(--md-motion-standard);
  user-select: none;
}
.m-chip:hover {
  background: rgba(27,27,31,.04);
  border-color: var(--md-outline);
}
.m-chip-selected {
  background: var(--md-primary-container);
  border-color: transparent;
  color: var(--md-on-primary-container);
  font-weight: 700;
}
.m-chip-selected::before { content: '✓ '; }

/* ============================================================
   🎯 BADGES
   ============================================================ */
.m-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  height: 18px;
  padding: 0 0.5rem;
  border-radius: 60px;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.m-badge-success { background: #e6f4ea; color: #137333; }
.m-badge-warn { background: #fef7e0; color: #a86600; }
.m-badge-error { background: #fce8e6; color: #c5221f; }
.m-badge-neutral { background: #eef1f6; color: #444746; }
.m-badge-primary { background: var(--md-primary-container); color: var(--md-on-primary-container); }

/* ============================================================
   📋 LISTAS / FILAS (compactas)
   ============================================================ */
.m-list-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.5rem 0.6rem;
  border-radius: var(--md-radius-sm);
  transition: background var(--md-motion);
  cursor: pointer;
}
.m-list-item:hover { background: rgba(27,27,31,.04); }
.m-list-item:active { background: rgba(27,27,31,.06); }

/* ============================================================
   🧭 NAVEGACIÓN
   ============================================================ */
.m-nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.7rem;
  border-radius: var(--md-radius-sm);
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--md-on-surface-variant);
  position: relative;
  overflow: hidden;
  transition: background var(--md-motion), color var(--md-motion);
  cursor: pointer;
}
.m-nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.m-nav-item-active {
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
}
.m-nav-item-active:hover {
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
}

/* ============================================================
   🗂️ SUPERFICIES / DRAWER
   ============================================================ */
.m-surface {
  background: var(--md-surface);
  border-radius: var(--md-radius);
}

/* ============================================================
   ✨ ANIMACIONES DE ENTRADA (más rápidas)
   ============================================================ */
.m-rise {
  animation: mRise .25s cubic-bezier(.2,0,0,1) both;
}
@keyframes mRise {
  from { opacity: 0; transform: translateY(6px) scale(.99); }
  to { opacity: 1; transform: none; }
}
.m-pop {
  animation: mPop .18s cubic-bezier(.2,0,0,1) both;
}
@keyframes mPop {
  from { opacity: 0; transform: scale(.96); }
  to { opacity: 1; transform: none; }
}

/* ============================================================
   🔘 SWITCH (interruptor)
   ============================================================ */
.m-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
}
.m-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.m-switch .track {
  width: 36px;
  height: 20px;
  border-radius: 60px;
  background: #b0aaa2;
  transition: background var(--md-motion-standard);
  position: relative;
}
.m-switch input:checked + .track {
  background: var(--md-primary);
}
.m-switch .thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--md-elevation-1);
  transition: transform var(--md-motion-standard), top var(--md-motion-standard);
}
.m-switch input:checked + .track .thumb {
  transform: translateX(16px);
}
.m-switch input:focus-visible + .track {
  outline: 2px solid var(--md-primary);
  outline-offset: 2px;
}

/* ============================================================
   ☑️ CHECKBOX — cualquier <input type="checkbox"> del sitio se
   moderniza solo (sin tocar cada vista); para dejar uno con su
   estilo nativo, agrégale la clase "no-m-checkbox". El interruptor
   .m-switch ya tiene su propio diseño y queda fuera de esta regla.
   ============================================================ */
input[type="checkbox"]:not(.m-switch input):not(.no-m-checkbox) {
  appearance: none;
  -webkit-appearance: none;
  width: 19px;
  height: 19px;
  flex: none;
  margin: 0;
  border: 1.5px solid var(--md-outline);
  border-radius: 5px;
  background: var(--md-surface-container-low);
  display: inline-grid;
  place-content: center;
  cursor: pointer;
  vertical-align: middle;
  transition: background var(--md-motion), border-color var(--md-motion), box-shadow var(--md-motion);
}
input[type="checkbox"]:not(.m-switch input):not(.no-m-checkbox)::after {
  content: '';
  width: 5px;
  height: 9px;
  margin-top: -2px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) scale(0);
  transition: transform .14s cubic-bezier(.2,0,0,1);
}
input[type="checkbox"]:not(.m-switch input):not(.no-m-checkbox):hover {
  border-color: var(--md-primary);
}
input[type="checkbox"]:not(.m-switch input):not(.no-m-checkbox):checked {
  background: var(--md-primary);
  border-color: var(--md-primary);
}
input[type="checkbox"]:not(.m-switch input):not(.no-m-checkbox):checked::after {
  transform: rotate(45deg) scale(1);
}
input[type="checkbox"]:not(.m-switch input):not(.no-m-checkbox):focus-visible {
  outline: 2px solid var(--md-primary);
  outline-offset: 2px;
}
input[type="checkbox"]:not(.m-switch input):not(.no-m-checkbox):disabled {
  opacity: .5;
  cursor: not-allowed;
}

/* ============================================================
   ✨ FAB (botón flotante) – más compacto
   ============================================================ */
.m-fab {
  position: fixed;
  right: 16px;
  bottom: 72px;
  z-index: 50;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  border: none;
  cursor: pointer;
  background: var(--md-primary);
  color: var(--md-on-primary);
  box-shadow: var(--md-elevation-3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow var(--md-motion-standard), transform var(--md-motion-standard), background var(--md-motion-standard);
}
@media (min-width: 768px) {
  .m-fab { bottom: 16px; right: 20px; }
}
.m-fab:hover {
  box-shadow: var(--md-elevation-4);
  filter: brightness(1.06);
  transform: translateY(-2px);
}
.m-fab:active { transform: scale(.94); }
.m-fab:focus-visible {
  outline: 2px solid var(--md-primary);
  outline-offset: 2px;
}
.m-fab-label {
  position: fixed;
  right: 76px;
  bottom: 24px;
  z-index: 50;
  background: var(--md-on-surface);
  color: var(--md-surface);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.3rem 0.7rem;
  border-radius: 60px;
  box-shadow: var(--md-elevation-2);
  transition: opacity var(--md-motion-standard);
}

/* ============================================================
   📱 BOTTOM NAV (móvil) – compacto
   ============================================================ */
.m-bottomnav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 45;
  background: var(--md-surface);
  box-shadow: var(--md-elevation-3);
  border-radius: 16px 16px 0 0;
  display: flex;
}
.m-bottomnav a, .m-bottomnav button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 0.4rem 0 0.6rem;
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--md-on-surface-variant);
  text-decoration: none;
  position: relative;
  overflow: hidden;
  transition: color var(--md-motion);
}
.m-bottomnav button { background: none; border: none; cursor: pointer; font-family: inherit; }
.m-bottomnav a.m-active, .m-bottomnav button.m-active {
  color: var(--md-primary);
}
.m-bottomnav a.m-active::before, .m-bottomnav button.m-active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 2px;
  border-radius: 0 0 2px 2px;
  background: var(--md-primary);
}

/* ============================================================
   📜 SCROLLBAR personalizada (más delgada)
   ============================================================ */
.m-scroll::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}
.m-scroll::-webkit-scrollbar-thumb {
  background: #d1cdc6;
  border-radius: 60px;
}
.m-scroll::-webkit-scrollbar-thumb:hover {
  background: #b0aaa2;
}
.m-scroll::-webkit-scrollbar-track {
  background: transparent;
}

/* ============================================================
   💀 SKELETON (shimmer) – compacto
   ============================================================ */
.m-shimmer {
  position: relative;
  overflow: hidden;
  background: #e9edf3;
  border-radius: var(--md-radius-sm);
}
.m-shimmer::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.5), transparent);
  transform: translateX(-100%);
  animation: mShimmer 1.4s infinite;
}
@keyframes mShimmer {
  to { transform: translateX(100%); }
}

/* ============================================================
   ♿ REDUCIR MOVIMIENTO (accesibilidad)
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .m-rise, .m-pop { animation: none; }
  .m-ripple-ink { display: none; }
  .m-shimmer::after { animation: none; }
}

/* ============================================================
   🌙 MODO OSCURO (compacto)
   ============================================================ */
body.dark {
  background: #0d1117;
  --md-primary: #d4d4d4;
  --md-on-primary: #1c1c1e;
  --md-primary-container: #3a3a3d;
  --md-on-primary-container: #ececed;
  --md-secondary-container: #1c2a3a;
  --md-on-secondary-container: #cfd5df;
  --md-surface: #161b22;
  --md-surface-dim: #0d1117;
  --md-surface-container-low: #0d1117;
  --md-on-surface: #e6edf3;
  --md-on-surface-variant: #9aa7b4;
  --md-outline: #30363d;
  --md-outline-soft: #21262d;
  --md-error-container: #4c1d24;
  --md-elevation-1: 0 1px 2px rgba(0,0,0,.4);
  --md-elevation-2: 0 2px 8px rgba(0,0,0,.5);
  --md-elevation-3: 0 4px 16px rgba(0,0,0,.6);
  --md-elevation-4: 0 8px 32px rgba(0,0,0,.7);
}
body.dark ::selection { background: rgba(138,180,248,0.2); }
body.dark .m-field input,
body.dark .m-field select,
body.dark .m-field textarea {
  background: #0d1117;
  border-color: #30363d;
  color: #e6edf3;
}
body.dark .m-field input:focus,
body.dark .m-field select:focus,
body.dark .m-field textarea:focus {
  border-color: #8ab4f8;
  background: #161b22;
}
body.dark .m-field input:focus::placeholder,
body.dark .m-field textarea:focus::placeholder {
  color: #6e7681;
}
body.dark .m-field label {
  color: #9aa7b4;
}
body.dark .m-card {
  background: #161b22;
  border-color: #21262d;
}
body.dark .m-list-item:hover { background: #1c222b; }
body.dark .m-chip {
  background: #161b22;
  border-color: #30363d;
  color: #c9d1d9;
}
body.dark .m-chip:hover { background: #21262d; border-color: #30363d; }
body.dark .m-badge-neutral { background: #21262d; color: #9aa7b4; }
body.dark .m-btn-outlined {
  border-color: #30363d;
  color: #c9d1d9;
}
body.dark .m-btn-outlined:hover { background: #21262d; border-color: #8ab4f8; }
body.dark .m-btn-tonal {
  background: #1c2a3a;
  color: #d6e3ff;
}
body.dark .m-bottomnav { background: #161b22; }
body.dark .toast-in { filter: brightness(.95); }
body.dark :focus-visible { outline-color: #8ab4f8; }