/*
 * Discópico — Shared components (public web + panel).
 * Load after tokens.css, tokens-de-marca.css and type.css. Every page of the public web
 * and the panel use these; the design-system site (sistema-de-diseno/web) imports this
 * file on every page and reads it to document each piece.
 *
 * Rules:
 *  - One state logic for everything (tokens.css, «Interacción»): rest grey · hover gets
 *    lighter (grey) · keyboard: copper outline (fields: white border + ring) · selected:
 *    brand red · error: light red with icon and message. Red never marks hover or focus.
 *  - Spacing only from --mt-space-*. Sizes that are not spacing (touch targets, icon
 *    sizes, control heights) are literal and commented.
 *  - Classes only, never bare elements: the design-system site loads this file too.
 *  - Each piece opens with a  ═══ N · NAME ═══  header (the design-system site splits
 *    the file on it).
 */

/* ═══════════ 1 · ICON ═══════════
   One set: Feather (24px grid, 2px stroke, round caps), sprite in assets/icons.svg.
   <svg class="icon" aria-hidden="true"><use href="assets/icons.svg#x"/></svg>
   Decorative → aria-hidden. An icon alone inside a control → the control gets aria-label.
   Scoped to <svg>: the design-system site uses .icon on its own list items. */
svg.icon {
  width: 20px;  /* icon sizes: 20 default, 16 small, 22 large */
  height: 20px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
svg.icon--16 { width: 16px; height: 16px; }
svg.icon--22 { width: 22px; height: 22px; }

/* ═══════════ 2 · PRIMARY BUTTON ═══════════
   The main action of a form or a section. Full width; always the last element of its
   block (supporting copy goes before it, never right after).
   Busy (saving, sending): aria-busy="true" + disabled, and inside
   <span class="btn-loader"><span class="spinner"></span></span> next to the text
   ("Guardando…"). Stays red and legible — different from disabled, which dims.
   .btn-fit: sized to its text, for wide layouts. */
.btn-primary {
  width: 100%;
  min-height: 48px;
  padding: var(--mt-space-2);
  background: var(--rojo);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-family: 'Sora', sans-serif;
  font-size: var(--mt-font-size-label-l);
  font-weight: 600;
  letter-spacing: 0.01em;
  text-decoration: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--mt-space-1);
  transition: background var(--t), transform var(--t), opacity var(--t);
}
.btn-primary:hover { background: var(--rojo-hover); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 3px; }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-primary[aria-busy="true"],
.btn-primary[aria-busy="true"]:hover,
.btn-primary[aria-busy="true"]:disabled {
  background: var(--rojo);
  color: #fff;
  opacity: 1;
  cursor: progress;
  transform: none;
}
.btn-primary .spinner {
  display: block;
  width: 18px;
  height: 18px;
  border-color: color-mix(in srgb, currentColor 35%, transparent);
  border-top-color: currentColor;
}
.btn-primary.btn-fit { width: auto; padding: 0 var(--mt-space-3); }

/* ═══════════ 3 · SECONDARY BUTTONS ═══════════
   Grey, never competing with the primary.
   .btn-secondary  tonal surface + line — the second action ("Corregir", "Volver al mapa")
   .btn-quiet      no surface — low-priority actions ("Cancelar")
   .btn-danger     light-red text — a destructive action, never the main one
   .btn-add        dashed line — add one more of something ("Evaluar otro cóctel")
   Modifiers: .btn-block (full width) · .btn-sm (40px tall, keeps a 44px touch target).
   Works on <button> and <a>; a disabled link uses aria-disabled="true". */
.btn-secondary,
.btn-quiet,
.btn-danger,
.btn-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--mt-space-1);
  min-height: 48px;  /* control height */
  padding: var(--mt-space-2);  /* same box as .btn-primary: side by side they match */
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  font-family: 'Sora', sans-serif;
  font-size: var(--mt-font-size-label-l);
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: normal;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--t), box-shadow var(--t), border-color var(--t), color var(--t), transform var(--t);
}

.btn-secondary { background: var(--mt-surface-sunken); color: var(--text); box-shadow: inset 0 0 0 1px var(--mt-border-default); }
.btn-secondary:not(:disabled, [aria-disabled="true"]):hover { background: var(--surface-3); box-shadow: inset 0 0 0 1px var(--mt-border-strong); }

.btn-quiet { color: var(--mt-text-secondary); }
.btn-quiet:not(:disabled, [aria-disabled="true"]):hover { background: var(--hover-wash); color: var(--text); }

.btn-danger { color: var(--state-problem-fg); }
.btn-danger:not(:disabled, [aria-disabled="true"]):hover { background: var(--state-problem-bg); }

.btn-add { color: var(--mt-text-secondary); border: 1px dashed var(--mt-border-strong); padding: calc(var(--mt-space-2) - 1px); } /* the 1px line sits inside the same box */
.btn-add:not(:disabled, [aria-disabled="true"]):hover { background: var(--hover-wash); color: var(--text); border-color: var(--mt-text-muted); }

:is(.btn-secondary, .btn-quiet, .btn-danger, .btn-add):not(:disabled, [aria-disabled="true"]):active { transform: scale(0.98); }
:is(.btn-secondary, .btn-quiet, .btn-danger, .btn-add):focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
:is(.btn-secondary, .btn-quiet, .btn-danger, .btn-add):is(:disabled, [aria-disabled="true"]) { opacity: 0.55; cursor: not-allowed; }

.btn-block { display: flex; width: 100%; }
.btn-sm {
  position: relative;
  min-height: 40px;
  padding: 0 var(--mt-space-1-5);  /* height comes from min-height */
  border-radius: var(--radius-sm);
  font-size: var(--mt-font-size-label-m);
}
.btn-sm::after { content: ""; position: absolute; inset: calc(-1 * var(--mt-space-0-25)) 0; } /* 44px target */

/* ═══════════ 4 · ICON BUTTON ═══════════
   A 44px round button with one icon. Always aria-label; the icon is aria-hidden.
   .icon-btn           with a line — actions next to a title (close, WhatsApp)
   .icon-btn--quiet    no line — inside a field or a card header (clear, remove)
   .icon-btn--overlay  dark glass — on top of a photo */
.icon-btn {
  width: 44px;  /* touch target */
  height: 44px;
  flex-shrink: 0;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--mt-border-default);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--t), box-shadow var(--t), color var(--t), transform var(--t);
}
.icon-btn:not(:disabled):hover { background: var(--hover-wash); box-shadow: inset 0 0 0 1px var(--mt-border-strong); }
.icon-btn:not(:disabled):active { transform: scale(0.94); }
.icon-btn:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.icon-btn:disabled { opacity: 0.55; cursor: not-allowed; }

.icon-btn--quiet { color: var(--mt-text-muted); box-shadow: none; }
.icon-btn--quiet:not(:disabled):hover { color: var(--text); box-shadow: none; }

.icon-btn--overlay { background: var(--mt-overlay); box-shadow: inset 0 0 0 1px var(--mt-border-strong); }
.icon-btn--overlay:not(:disabled):hover { background: linear-gradient(var(--hover-wash), var(--hover-wash)), var(--mt-overlay); }

/* ═══════════ 5 · BACK ═══════════
   Goes one step back. A link (<a href>) when it changes page, a button when it changes
   a step on the same page. The chevron lines up with the content edge.
   <button class="btn-back" type="button"><svg class="icon"><use href="assets/icons.svg#chevron-left"/></svg><span>Atrás</span></button> */
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: var(--mt-space-0-5);
  min-height: 44px;  /* touch target */
  padding: 0 var(--mt-space-1-5) 0 var(--mt-space-0-5);
  margin-left: calc(-1 * var(--mt-space-1));
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--mt-text-secondary);
  font-family: 'Sora', sans-serif;
  font-size: var(--mt-font-size-label-l);
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--t), color var(--t);
}
.btn-back:hover { background: var(--hover-wash); color: var(--text); }
.btn-back:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

/* ═══════════ 6 · TEXT FIELD AND SELECT ═══════════
   Every field of the web and the panel. One state logic (tokens.css, «Interacción»):
   hover gets lighter, typing gets a white border and ring, error in light red with
   icon and message.
   <input class="text-field">  ·  <textarea class="text-field">
   Select: <span class="text-field-wrap"><select class="text-field">…</select><svg …chevron></span>
   Error: aria-invalid="true" + <p class="text-field-error"> linked with aria-describedby.
   Help: <p class="text-field-hint">. Both go below, separated by --mt-space-1. */
.text-field {
  width: 100%;
  min-height: 48px;
  padding: var(--mt-space-1-5) var(--mt-space-2);
  background: var(--field-bg);
  color: var(--text);
  border: 1px solid var(--field-border);
  border-radius: var(--radius-sm);
  font: 400 var(--mt-font-size-body-m)/1.4 'Sora', sans-serif;
  outline: none;
  box-sizing: border-box;
  transition: border-color var(--t), background var(--t), box-shadow var(--t);
}
.text-field::placeholder { color: var(--mt-text-muted); }
.text-field:hover { border-color: var(--field-border-hover); background: var(--field-bg-hover); }
.text-field:focus { border-color: var(--field-border-focus); box-shadow: 0 0 0 3px var(--field-ring); background: var(--field-bg); }
.text-field[aria-invalid="true"] { border-color: var(--field-error); }
.text-field[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px var(--field-error-ring); }
.text-field:disabled { opacity: 0.55; cursor: not-allowed; border-color: var(--mt-border-subtle); background: var(--surface); }
textarea.text-field { min-height: 96px; resize: vertical; line-height: 1.55; }
select.text-field { appearance: none; -webkit-appearance: none; padding-right: var(--mt-space-6); cursor: pointer; }

.text-field-wrap { position: relative; display: block; }
.text-field-wrap > svg {
  position: absolute; right: var(--mt-space-2); top: 50%; transform: translateY(-50%);
  width: 20px; height: 20px; color: var(--mt-text-muted); pointer-events: none;
}
.text-field:disabled + svg { opacity: 0.55; }

.text-field-hint,
.text-field-error {
  margin: var(--mt-space-1) 0 0;
  font-family: 'Sora', sans-serif;
  font-size: var(--mt-font-size-label-m);
  line-height: 1.5;
}
.text-field-hint { color: var(--mt-text-muted); }
.text-field-error { display: flex; align-items: flex-start; gap: var(--mt-space-0-75); color: var(--field-error); }
.text-field-error svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: var(--mt-space-0-25); }

/* ═══════════ 7 · LOADING ═══════════
   Feedback while waiting for an answer.
   <div class="loading-state"><div class="spinner"></div><span>Texto…</span></div>
   Overlay: .loading-overlay on the parent wrapper, .loading-state inside.
   Inside a button: the busy primary button (2). */
@keyframes spin { to { transform: rotate(360deg); } }

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--rojo-light);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--mt-space-1-5);
  padding: var(--mt-space-6) 0;
  color: var(--muted);
  font-size: var(--mt-font-size-body-s);
  font-family: 'Sora', sans-serif;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.loading-overlay .loading-state { padding: 0; }

/* ═══════════ 8 · FOOTER ═══════════
   Page footer of every public page. */
.site-footer {
  padding: 20px 24px 32px;
  text-align: center;
}
.site-footer img {
  height: 28px;
  width: auto;
  margin-bottom: 8px;
  display: block;
  margin-inline: auto;
}
.site-footer p {
  font-size: var(--mt-font-size-label-s);
  color: rgba(255,255,255,0.35);
  letter-spacing: 0.05em;
}

/* ═══════════ REDUCED MOTION ═══════════ */
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
  .text-field,
  .btn-primary, .btn-secondary, .btn-quiet, .btn-danger, .btn-add,
  .icon-btn, .btn-back { transition: none; }
  .btn-primary:active,
  :is(.btn-secondary, .btn-quiet, .btn-danger, .btn-add, .icon-btn):active { transform: none; }
}
