/*
 * Trakinver — sistema de formularios.
 *
 * Los controles nativos (select, date, number, color, checkbox) se renderizan
 * con el chrome del sistema operativo si no se resetea `appearance`. Chrome lo
 * disimula; Safari no: el campo de fecha crece más que el select de al lado,
 * aparece el doble chevron de macOS y el calendario se abre en modo claro.
 * Aquí se normalizan todos los controles para que se vean igual en Safari,
 * Chrome y Firefox, usando los tokens de design-tokens.css.
 */

/* Hace que el calendario de type=date, el popup del select, el autocompletado
   y el caret se rendericen en oscuro. Es el arreglo con más impacto. */
:root { color-scheme: dark; }

/* Solo `button` heredaba la fuente; por eso los templates repetían
   `font-family: inherit` inline en cada select y textarea. */
input, select, textarea { font-family: var(--font); }

/* ---------- Control base ---------- */
.input {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  min-height: 42px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.2;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input::placeholder { color: var(--text-muted); }
.input:hover { border-color: var(--border-hover); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(178,229,249,.12); }
.input:disabled { opacity: .5; cursor: not-allowed; }

/* Fila de campos lado a lado (sustituye a style="display:flex; gap:16px"). */
.field-row { display: flex; gap: 16px; }
.field-row > .field { flex: 1; min-width: 0; }
@media (max-width: 520px) { .field-row { flex-direction: column; gap: 0; } }

/* ---------- Select ---------- */
/* Chevron propio en --text-secondary (#A0A0A8): el nativo de macOS es un doble
   triángulo que no combina con el tema oscuro. */
.input-select,
select.input,
.select-inline {
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23A0A0A8' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px 16px;
  cursor: pointer;
  text-overflow: ellipsis;
}
select.input { padding-right: 38px; }
select.input::-ms-expand { display: none; }
/* Firefox no siempre respeta color-scheme en el popup. */
select.input option,
.select-inline option { background: var(--bg-elevated); color: var(--text-primary); }
select.input optgroup { background: var(--bg-card); color: var(--text-secondary); font-style: normal; font-weight: 600; }

/* Select sin caja propia, embebido en otro contenedor (filtro de mes/año). */
.select-inline {
  background-color: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 13px;
  padding: 4px 22px 4px 2px;
  background-position: right 2px center;
  background-size: 14px 14px;
  outline: none;
}
.select-inline:focus-visible { outline: none; box-shadow: 0 0 0 2px rgba(178,229,249,.35); border-radius: 4px; }

/* ---------- Fecha ---------- */
/* Safari mide el alto por la caja interna de edición, que trae su propio
   padding: sin estos resets el campo queda mucho más alto que un select. */
input[type="date"].input,
input[type="month"].input { cursor: text; }
input[type="date"]::-webkit-datetime-edit,
input[type="month"]::-webkit-datetime-edit { padding: 0; line-height: 1.2; }
input[type="date"]::-webkit-datetime-edit-fields-wrapper,
input[type="month"]::-webkit-datetime-edit-fields-wrapper { padding: 0; }
input[type="date"]::-webkit-date-and-time-value,
input[type="month"]::-webkit-date-and-time-value { margin: 0; text-align: left; min-height: auto; }
input[type="date"]::-webkit-inner-spin-button,
input[type="month"]::-webkit-inner-spin-button { display: none; }
/* El icono nativo es un glifo oscuro: invertido se ve sobre --bg-elevated. */
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="month"]::-webkit-calendar-picker-indicator {
  filter: invert(1);
  opacity: .55;
  cursor: pointer;
  padding: 0;
  margin: 0;
  transition: opacity .15s ease;
}
input[type="date"]::-webkit-calendar-picker-indicator:hover,
input[type="month"]::-webkit-calendar-picker-indicator:hover { opacity: 1; }

/* ---------- Numérico ---------- */
input[type="number"].input { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ---------- Color ---------- */
input[type="color"].input {
  width: 52px;
  flex: none;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 4px; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 5px; }
input[type="color"]::-moz-color-swatch { border: none; border-radius: 5px; }

/* ---------- Textarea ---------- */
textarea.input { min-height: 88px; line-height: 1.5; resize: vertical; }

/* ---------- Campo monetario ---------- */
.input-money { display: flex; align-items: center; gap: 8px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px 14px; min-height: 42px; transition: border-color .15s ease, box-shadow .15s ease; }
.input-money:hover { border-color: var(--border-hover); }
.input-money:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(178,229,249,.12); }
.input-money .prefix { color: var(--text-muted); font-size: 16px; }
.input-money input { -webkit-appearance: none; appearance: none; background: transparent; border: none; outline: none; color: var(--text-primary); font-family: var(--font); font-size: 20px; font-weight: 500; width: 100%; padding: 8px 0; }
.input-money input::placeholder { color: var(--text-muted); }

/* ---------- Etiquetas y campos ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label,
.field__label { font-size: 13px; color: var(--text-secondary); }
.field__hint { font-size: 12px; color: var(--text-secondary); margin: 6px 0 0; min-height: 15px; }
.req { color: var(--accent); }

/* ---------- Acciones del formulario ---------- */
.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 28px; }
/* Eliminar se separa al extremo opuesto; el resto queda junto a la derecha. */
.form-actions .btn--danger { margin-right: auto; }
@media (max-width: 520px) {
  .form-actions { flex-direction: column-reverse; align-items: stretch; }
  .form-actions .btn--danger { margin-right: 0; }
}

/* ---------- Validación ---------- */
.field__error { display: none; font-size: 12px; color: var(--negative); margin-top: 2px; }
.field.is-invalid .field__error { display: block; }
.input[aria-invalid="true"],
.field.is-invalid .input-money { border-color: var(--negative); }
.input[aria-invalid="true"]:focus,
.field.is-invalid .input-money:focus-within { border-color: var(--negative); box-shadow: 0 0 0 3px rgba(248,113,113,.14); }

/* ---------- Switch (sustituye al checkbox nativo) ---------- */
/* El <input type=checkbox> real sigue existiendo, oculto: el JS que lee
   .checked no necesita cambiar. */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; font-size: 13px; color: var(--text-primary); }
.switch input { position: absolute; width: 1px; height: 1px; opacity: 0; margin: 0; }
.switch__track { position: relative; flex: none; width: 38px; height: 22px; border-radius: 999px; background: var(--bg-elevated); border: 1px solid var(--border); transition: background .18s ease, border-color .18s ease; }
.switch__thumb { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--text-muted); transition: transform .18s ease, background .18s ease; }
.switch:hover .switch__track { border-color: var(--border-hover); }
.switch input:checked + .switch__track { background: var(--accent-dim); border-color: var(--accent); }
.switch input:checked + .switch__track .switch__thumb { transform: translateX(16px); background: var(--accent); }
.switch input:focus-visible + .switch__track { box-shadow: 0 0 0 3px rgba(178,229,249,.22); }
.switch input:disabled + .switch__track { opacity: .5; }
.switch__label { display: flex; align-items: center; gap: 6px; font-weight: 500; }

/* ---------- Táctil ---------- */
/* iOS Safari hace zoom automático al enfocar un campo de menos de 16px. */
@media (pointer: coarse) {
  .input, .input-money input, textarea.input, .select-inline { font-size: 16px; }
  .input, .btn { min-height: 44px; }
  .input-money { min-height: 44px; }
}
