/* ==================================================================
   BASE — variables, reset y componentes compartidos
   Para cambiar la paleta de todo el sitio, tocá solo :root.
   ================================================================== */

:root {
  --bg: #f7f5f2;
  --surface: #ffffff;
  --surface-2: #f1eee9;
  --border: #e4dfd8;
  --border-strong: #cfc8be;

  --text: #1d1b19;
  --text-muted: #6b655e;
  --text-soft: #8f887f;

  --accent: #1f4d43;
  --accent-hover: #173b33;
  --accent-soft: #e3eeea;
  --accent-contrast: #ffffff;

  --danger: #b42318;
  --danger-soft: #fdecea;
  --success: #1e7b4a;
  --success-soft: #e6f4ec;
  --warning: #9a6200;
  --warning-soft: #fdf3dc;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow: 0 1px 2px rgb(29 27 25 / 6%), 0 4px 16px rgb(29 27 25 / 6%);
  --shadow-lg: 0 12px 40px rgb(29 27 25 / 18%);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
  --transition: 160ms ease;
  --focus-ring: 0 0 0 3px rgb(31 77 67 / 30%);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, p {
  margin: 0;
}

h1, h2, h3 {
  line-height: 1.2;
  letter-spacing: -0.01em;
}

a {
  color: var(--accent);
}

img,
svg {
  display: block;
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

[hidden] {
  display: none !important; /* el atributo hidden siempre gana sobre display de componentes */
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.muted {
  color: var(--text-muted);
}

.small {
  font-size: 0.875rem;
}

.container {
  width: 100%;
  max-width: 720px;
  margin-inline: auto;
  padding-inline: var(--space-4);
}

/* ---------- Botones ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition),
    transform var(--transition), opacity var(--transition);
}

.btn:hover {
  background: var(--surface-2);
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

.btn--primary:hover {
  background: var(--accent-hover);
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
}

.btn--ghost:hover {
  background: var(--surface-2);
}

.btn--danger {
  color: var(--danger);
  border-color: #efc4bf;
}

.btn--danger:hover {
  background: var(--danger-soft);
}

.btn--sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 0.875rem;
  border-radius: var(--radius-sm);
}

.btn--block {
  width: 100%;
}

.btn[aria-busy="true"]::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ---------- Formularios ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label,
.field-label {
  font-size: 0.875rem;
  font-weight: 600;
}

.input,
.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.field textarea {
  min-height: 84px;
  resize: vertical;
}

.input:focus,
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.field input[aria-invalid="true"] {
  border-color: var(--danger);
}

.field-hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.form-error {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.9rem;
}

.form-success {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--success-soft);
  color: var(--success);
  font-size: 0.9rem;
}

.form-grid {
  display: grid;
  gap: var(--space-4);
}

.form-row {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: 1fr 1fr;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  font-size: 0.95rem;
}

.checkbox input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

/* Interruptor (checkbox con forma de switch) */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  font-size: 0.875rem;
}

.switch input {
  appearance: none;
  width: 42px;
  height: 24px;
  margin: 0;
  border-radius: 999px;
  background: var(--border-strong);
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
  flex-shrink: 0;
}

.switch input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 25%);
  transition: transform var(--transition);
}

.switch input:checked {
  background: var(--accent);
}

.switch input:checked::after {
  transform: translateX(18px);
}

.switch input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Tarjetas y badges ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-muted);
  white-space: nowrap;
}

.badge--success { background: var(--success-soft); color: var(--success); }
.badge--danger  { background: var(--danger-soft);  color: var(--danger); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--accent  { background: var(--accent-soft);  color: var(--accent); }

.notice {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  background: var(--warning-soft);
  color: var(--warning);
  font-size: 0.9rem;
}

.empty {
  padding: var(--space-6) var(--space-4);
  text-align: center;
  color: var(--text-muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
}

/* ---------- Carga ---------- */

.spinner {
  width: 28px;
  height: 28px;
  margin: var(--space-6) auto;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Toasts ---------- */

.toast-region {
  position: fixed;
  inset: auto var(--space-4) var(--space-4) var(--space-4);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  pointer-events: none;
}

.toast {
  max-width: 480px;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--text);
  color: #fff;
  font-size: 0.925rem;
  box-shadow: var(--shadow-lg);
  transition: opacity 300ms ease, transform 300ms ease;
  animation: toast-in 200ms ease;
}

.toast--error { background: var(--danger); }
.toast--success { background: var(--success); }

.toast--leaving {
  opacity: 0;
  transform: translateY(8px);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
}

/* ---------- Diálogos ---------- */

dialog.modal {
  width: min(520px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: none;
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

dialog.modal::backdrop {
  background: rgb(29 27 25 / 45%);
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}

.modal__header h2 {
  font-size: 1.125rem;
}

.modal__body {
  padding: var(--space-5);
  display: grid;
  gap: var(--space-4);
}

.modal__footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border);
}

.modal__footer .spacer {
  flex: 1;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

@media (max-width: 420px) {
  .form-row {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important; /* respeta la preferencia del sistema */
    transition-duration: 0.01ms !important;
  }
}
