/* =========================
   VARIABLES
========================= */
:root {
  --bg: #0f172a;
  --bg-secondary: #1e1b4b;
  --bg-input: #020617;
  --bg-input-auto-fill: #040d32;
  --card: #1e293b;
  --border: #334155;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-text: #60a5fa;

  --text: #e5e7eb;
  --text-muted: #94a3b8;

  --success: #22c55e;
  --error: #ef4444;
  --focus-option: #3b82f640;

  --radius: 0.75rem;
  --transition: 0.25s ease;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  --focus-shadow: 0 0 0 3px rgba(59, 130, 246, 0.4);
}

/* =========================
   RESET & BASE
========================= */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  display: grid;
  grid-template-areas: "header" "main" "footer";
  gap: 1.5rem;

  padding: 2rem 0;
  background: linear-gradient(135deg, var(--bg), var(--bg-secondary));

  font-family: system-ui, sans-serif;
  line-height: 1.5;
  color: var(--text);
}

@media (min-width: 480px) {
  body {
    padding: 2rem;
  }
}

@media (min-width: 768px) {
  body {
    padding: 3rem;
  }
}

/* =========================
   TIPOGRAFÍA
========================= */
h1 {
  font-size: clamp(1.6rem, 7vw, 2rem);
}

small {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

/* =========================
   LAYOUT
========================= */
.header {
  grid-area: header;

  display: flex;
  flex-direction: column;
  gap: 0.5rem;

  text-align: center;
}

.main {
  grid-area: main;

  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
}

/* =========================
   FOOTER
========================= */
.footer {
  grid-area: footer;

  display: flex;
  flex-direction: column;
  gap: 1rem;

  text-align: center;
  color: var(--text-muted);
}

.footer a {
  justify-content: end;
}

.footer p {
  font-size: 0.85rem;
}

hr {
  border: none;
  border-top: 1px solid var(--border);
}

/* =========================
   ENLACES
========================= */
a {
  display: flex;
  flex-direction: column;
  min-height: 44px;

  text-decoration: none;
  color: var(--primary);
}

a:hover {
  text-decoration: underline;
}

/* =========================
   FORM
========================= */
form {
  animation: fadeIn 0.6s ease;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 2rem;

  padding: 2rem 0;
  background: var(--card);

  box-shadow: var(--shadow);
}

@media (min-width: 480px) {
  .form {
    padding: 2rem;

    border-radius: var(--radius);
  }
}

/* =========================
   FIELDSETS
========================= */
.form__fieldset {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;

  padding: 1.5rem;

  border: 1px solid var(--border);

  transition: var(--transition);
}

@media (min-width: 480px) {
  .form__fieldset {
    padding: 2rem;

    border-radius: var(--radius);
  }

  .form__fieldset:has(.form__options) {
    padding: 1rem;
  }
}

.form__fieldset:hover {
  border-color: var(--primary);
}

.form__fieldset:focus-within {
  border: 2px solid var(--primary);
}

legend {
  padding: 0 0.5rem;

  font-weight: 600;
  color: var(--primary-text);
}

/* =========================
   GROUPS
========================= */
.form__group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form__group--floating {
  position: relative;
}

/* Label flotante — posición base */
.form__group--floating label {
  position: absolute;
  left: 0.75rem;
  top: 0.65rem;

  font-size: 0.9rem;
  color: var(--text-muted);

  pointer-events: none;
  transition: var(--transition);
}

/* Label flotante — activa (con foco o contenido) */
.form__group--floating input:focus + label,
.form__group--floating select:focus + label,
.form__group--floating textarea:focus + label,
.form__group--floating input:not(:placeholder-shown) + label,
.form__group--floating select:not(:placeholder-shown) + label,
.form__group--floating textarea:not(:placeholder-shown) + label {
  top: 0;

  padding: 0 0.25rem;
  background-color: var(--card);

  border-radius: 0.4rem;

  transform: translateY(-65%) scale(0.9);
}

/* Label flotante — color en foco */
.form__group--floating input:focus + label,
.form__group--floating select:focus + label,
.form__group--floating textarea:focus + label {
  color: var(--primary);
}

/* Label flotante — estados de validación */
.form__group--floating input:user-valid + label,
.form__group--floating textarea:user-valid + label {
  color: var(--success);
}

.form__group--floating input:user-invalid + label,
.form__group--floating textarea:user-invalid + label {
  color: var(--error);
}

/* =========================
   OPTIONS
========================= */
.form__options {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

/* =========================
   LABELS
========================= */
label {
  display: block;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* =========================
   INPUTS
========================= */
input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  outline: none;
  transition: var(--transition);
}

select {
  appearance: base-select;
}

textarea {
  min-height: 88px;
}

/* Foco */
input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: var(--focus-shadow);
}

/* Foco en checkbox y radio — sin sombra para evitar blur */
input[type="checkbox"]:focus,
input[type="radio"]:focus {
  box-shadow: none;
}

/* Foco dentro de .form__options */
.form__options label:focus-within {
  background-color: var(--focus-option);
  border-radius: var(--radius);
  outline: 1px dashed var(--primary);
}

/* Válido */
input:user-valid,
textarea:user-valid {
  border-color: var(--success);
}

/* Inválido */
input:user-invalid,
textarea:user-invalid {
  border-color: var(--error);
}

/* =========================
   RADIO & CHECKBOX
========================= */
input[type="radio"],
input[type="checkbox"] {
  width: auto;
  margin-right: 0.4rem;
  accent-color: var(--primary);
  cursor: pointer;
}

label:has(input[type="radio"]),
label:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  padding: 0 1rem;

  cursor: pointer;
}

label:has(input[type="radio"]):hover,
label:has(input[type="checkbox"]):hover {
  border-radius: var(--radius);
  outline: 1px dashed var(--primary);
}

/* =========================
   RANGE
========================= */
input[type="range"] {
  padding: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

.range {
  position: relative;
}

.range__small {
  position: absolute;
  inset: auto 8px 0;
  display: flex;
  justify-content: space-between;
}

/* =========================
   COLOR
========================= */
input[type="color"] {
  border: none;
  height: 40px;
  cursor: pointer;
}

/* =========================
   FILE
========================= */
input[type="file"] {
  background: transparent;
  border: none;
}

/* =========================
   ACCIONES
========================= */
.form__actions {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;

  padding: 0 1.5rem;
}

@media (min-width: 480px) {
  .form__actions {
    padding: 0;
  }
}

/* =========================
   BOTONES
========================= */
.button {
  position: relative;

  padding: 0.7rem 1.2rem;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-weight: 500;
  transition: var(--transition);
}

.button:active {
  transform: translateY(2px) scale(0.98);
  filter: brightness(1.3);
}

.button--primary {
  background: var(--primary);
  color: white;
}

.button--primary:hover:not(:active) {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.button--ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.button--ghost:hover {
  border-color: var(--primary);
  color: var(--text);
}

/* =========================
   ANIMACIONES
========================= */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* =========================
   FIXES
========================= */

/* Autofill Chrome */
input:-webkit-autofill,
input:-webkit-autofill:focus,
input:-webkit-autofill:hover {
  -webkit-text-fill-color: var(--text);
  transition: background-color 9999s ease-in-out 0s;
  box-shadow: 0 0 0px 1000px var(--bg-input-auto-fill) inset;
}

/* Icono de date picker */
input::-webkit-calendar-picker-indicator {
  filter: invert(1);
  opacity: 0.8;
  cursor: pointer;
}

input[list]::-webkit-calendar-picker-indicator {
  color: black;
}

input::-webkit-calendar-picker-indicator:hover {
  opacity: 1;
  transform: scale(1.1);
}
