/* ============================================================================
   TETMA · UI compartida — Átomos y moléculas del prototipo MVP V0
   Consume exclusivamente tokens de colors_and_type.css (TETMA Design System).
   Importar SIEMPRE después de colors_and_type.css.
   ========================================================================== */

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg-app); font-family: var(--font-body); color: var(--fg-default); -webkit-font-smoothing: antialiased; }
a { color: var(--fg-link); }
a:hover { color: var(--fg-link-hover); }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-xs); }

/* ---- Átomo: botones ----------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-family: var(--font-body);
  font-weight: var(--fw-bold); font-size: 15px; border-radius: var(--radius-md); border: 1.5px solid transparent;
  cursor: pointer; padding: 0 18px; height: 48px; min-height: var(--tap-target); white-space: nowrap;
  transition: all var(--dur-fast) var(--ease-standard); text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--action-primary); color: var(--fg-on-brand); }
.btn-primary:hover { background: var(--action-primary-hover); }
.btn-accent { background: var(--action-accent); color: var(--fg-on-accent); }
.btn-accent:hover { background: var(--action-accent-hover); }
.btn-secondary { background: var(--action-secondary-bg); color: var(--fg-strong); border-color: var(--action-secondary-border); }
.btn-secondary:hover { background: var(--bg-surface-2); }
.btn-ghost { background: transparent; color: var(--fg-link); }
.btn-danger { background: transparent; color: var(--state-error-fg); border-color: var(--state-error-border); }
.btn-danger:hover { background: var(--state-error-bg); }
.btn-sm { height: 38px; font-size: 13px; padding: 0 14px; border-radius: var(--radius-sm); }
.btn-full { width: 100%; }
.btn:disabled { background: var(--bg-sunken); color: var(--fg-disabled); border-color: transparent; cursor: not-allowed; transform: none; }
.icon-btn { background: none; border: 0; width: 40px; height: 40px; border-radius: var(--radius-pill); display: inline-flex;
  align-items: center; justify-content: center; cursor: pointer; color: var(--fg-strong); }
.icon-btn:hover { background: var(--bg-sunken); }

/* ---- Átomo: chips de estado (color + icono + texto, WCAG) --------------- */
.chip { display: inline-flex; align-items: center; gap: 5px; font-weight: var(--fw-semibold); font-size: 13px;
  padding: 4px 10px; border-radius: var(--radius-pill); border: 1px solid transparent; white-space: nowrap; }
.chip i, .chip svg { width: 14px; height: 14px; }
.chip-neutral { background: var(--c-gray-100); color: var(--fg-muted); border-color: var(--border-default); }
.chip-info    { background: var(--state-info-bg); color: var(--state-info-fg); border-color: var(--state-info-border); }
.chip-success { background: var(--state-success-bg); color: var(--state-success-fg); border-color: var(--state-success-border); }
.chip-warning { background: var(--state-warning-bg); color: var(--state-warning-fg); border-color: var(--state-warning-border); }
.chip-error   { background: var(--state-error-bg); color: var(--state-error-fg); border-color: var(--state-error-border); }
.chip-accent  { background: var(--c-orange-100); color: var(--c-orange-700); border-color: var(--c-orange-500); }

/* ---- Átomo: badge fase -------------------------------------------------- */
.badge-fase { display: inline-flex; align-items: center; gap: 5px; font-size: var(--fs-caption); font-weight: var(--fw-bold);
  letter-spacing: var(--ls-caps); text-transform: uppercase; padding: 3px 10px; border-radius: var(--radius-pill);
  background: var(--state-warning-bg); color: var(--state-warning-fg); border: 1px solid var(--state-warning-border); }
.badge-v0 { background: var(--state-success-bg); color: var(--state-success-fg); border: 1px solid var(--state-success-border); }

/* ---- Átomo: código de aviso --------------------------------------------- */
.code-token { font-family: var(--font-mono); font-feature-settings: "tnum" 1, "lnum" 1; font-weight: var(--fw-extra);
  letter-spacing: 0.18em; color: var(--fg-strong); }

/* ---- Molécula: campos de formulario -------------------------------------- */
.fld { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.lbl { font-weight: var(--fw-semibold); font-size: 13px; color: var(--fg-strong); }
.lbl .req { color: var(--state-error-fg); }
.hint { font-size: var(--fs-caption); color: var(--fg-subtle); }
.inp { min-height: 48px; border-radius: var(--radius-sm); border: 1.5px solid var(--border-default); background: var(--bg-surface);
  padding: 0 12px; display: flex; align-items: center; gap: 9px; }
.inp i, .inp svg { color: var(--fg-subtle); flex: none; }
.inp input, .inp select { border: 0; outline: 0; background: none; font-family: var(--font-body); font-size: 15px;
  color: var(--fg-default); width: 100%; height: 100%; min-height: 44px; }
.inp:focus-within { border-color: var(--border-focus); box-shadow: var(--focus-ring); }
/* El anillo de foco lo dibuja el contenedor .inp: el control interior no repite el suyo */
.inp input:focus-visible, .inp select:focus-visible, .inp textarea:focus-visible { box-shadow: none; outline: none; }
.inp.invalid { border-color: var(--state-error-border); }
textarea.area { width: 100%; min-height: 110px; border-radius: var(--radius-sm); border: 1.5px solid var(--border-default);
  background: var(--bg-surface); padding: 10px 12px; font-family: var(--font-body); font-size: 15px; color: var(--fg-default);
  resize: vertical; line-height: var(--lh-normal); }
textarea.area:focus { outline: none; border-color: var(--border-focus); box-shadow: var(--focus-ring); }
.err-msg { display: flex; align-items: center; gap: 6px; color: var(--state-error-fg); font-size: 13px; font-weight: var(--fw-semibold); }

/* ---- Molécula: editor de texto enriquecido (rich text) -------------------- */
.rt { border: 1.5px solid var(--border-default); border-radius: var(--radius-sm); background: var(--bg-surface); overflow: hidden; }
.rt:focus-within { border-color: var(--border-focus); box-shadow: var(--focus-ring); }
.rt-bar { display: flex; gap: 2px; padding: 5px 6px; border-bottom: 1px solid var(--border-subtle); background: var(--bg-muted, var(--bg-subtle)); }
.rt-b { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; padding: 0;
  border: 1px solid transparent; border-radius: var(--radius-xs, 6px); background: transparent; color: var(--fg-muted); cursor: pointer; }
.rt-b:hover { background: var(--bg-surface); color: var(--fg-default); border-color: var(--border-subtle); }
.rt-b:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.rt-b i { width: 16px; height: 16px; }
.rt-area { min-height: 110px; padding: 10px 12px; font-family: var(--font-body); font-size: 15px; color: var(--fg-default);
  line-height: var(--lh-normal); outline: none; overflow-y: auto; }
.rt-area.rt-mono { min-height: 220px; font-family: var(--font-mono); font-size: 13px; line-height: 1.5; }
.rt-area p { margin: 0 0 8px; }
.rt-area p:last-child { margin-bottom: 0; }
.rt-area a { color: var(--fg-link, var(--color-primary)); }
.rt-area:empty::before { content: attr(data-ph); color: var(--fg-subtle); }

/* ---- Molécula: tarjetas --------------------------------------------------- */
.card { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-md);
  box-shadow: var(--elev-1); }
.card-pad { padding: var(--space-4); }
.card-hover { transition: box-shadow var(--dur-fast) var(--ease-standard), transform var(--dur-fast) var(--ease-standard); cursor: pointer; }
.card-hover:hover { box-shadow: var(--elev-2); }
.card-hover:active { transform: scale(.99); }

/* ---- Molécula: avisos / alerts ------------------------------------------- */
.notice { display: flex; gap: 10px; align-items: flex-start; border-radius: var(--radius-md); padding: 12px 14px;
  font-size: 13px; line-height: 1.45; }
.notice i, .notice svg { flex: none; margin-top: 1px; }
.notice-info    { background: var(--state-info-bg); color: var(--state-info-fg); }
.notice-warning { background: var(--state-warning-bg); color: var(--state-warning-fg); }
.notice-error   { background: var(--state-error-bg); color: var(--state-error-fg); }
.notice-success { background: var(--state-success-bg); color: var(--state-success-fg); }

/* ---- Molécula: empty state ------------------------------------------------ */
.empty { text-align: center; color: var(--fg-subtle); padding: 28px 16px; background: var(--bg-surface);
  border: 1px dashed var(--border-default); border-radius: var(--radius-md); }
.empty i, .empty svg { color: var(--border-strong); margin-bottom: 8px; }
.empty p { margin: 0; font-size: 14px; }

/* ---- Molécula: toast ------------------------------------------------------- */
.toast-live { position: fixed; left: 16px; right: 16px; bottom: 24px; max-width: 480px; margin: 0 auto;
  background: var(--c-navy-800); color: var(--fg-on-brand); border-radius: var(--radius-md); box-shadow: var(--elev-3);
  padding: 13px 15px; display: flex; gap: 11px; align-items: center; z-index: 90;
  animation: toastIn var(--dur-slow) var(--ease-decelerate); }
.toast-live i, .toast-live svg { color: var(--c-success-600); flex: none; }
.toast-live.toast-error i, .toast-live.toast-error svg { color: var(--c-error-600); }
.toast-live span { font-size: 14px; font-weight: var(--fw-semibold); }
@keyframes toastIn { from { opacity: 0; transform: translateY(16px); } }

/* ---- Molécula: segmented control ------------------------------------------ */
.seg { display: flex; gap: 4px; background: var(--bg-sunken); border-radius: var(--radius-md); padding: 4px; }
.seg-b { flex: 1; border: 0; background: none; padding: 9px 12px; border-radius: var(--radius-sm); font-weight: var(--fw-bold);
  font-size: 13px; color: var(--fg-muted); cursor: pointer; font-family: var(--font-body); white-space: nowrap; }
.seg-b.on { background: var(--bg-surface); color: var(--fg-strong); box-shadow: var(--elev-1); }

/* ---- Molécula: stepper de wizard ------------------------------------------- */
.wiz-steps { display: flex; padding: 6px 8px 0; }
.wstep { display: flex; align-items: center; flex: 1; }
.wstep:last-child { flex: none; }
.wdot { width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: var(--fw-extra); font-size: 13px; border: 2px solid var(--border-default);
  background: var(--bg-surface); color: var(--fg-subtle); flex: none; }
.wbar { flex: 1; height: 3px; background: var(--border-default); margin: 0 6px; border-radius: 2px; }
.wstep.done .wdot { background: var(--c-success-600); border-color: var(--c-success-600); color: #fff; }
.wstep.done .wbar { background: var(--c-success-600); }
.wstep.active .wdot { background: var(--action-primary); border-color: var(--action-primary); color: #fff; }

/* ---- Molécula: timeline ------------------------------------------------------ */
.timeline { display: flex; flex-direction: column; }
.tl-row { display: flex; gap: 14px; }
.tl-line { display: flex; flex-direction: column; align-items: center; }
.tl-dot { width: 32px; height: 32px; border-radius: 50%; background: var(--bg-sunken); color: var(--fg-subtle);
  display: flex; align-items: center; justify-content: center; flex: none; border: 2px solid var(--border-default); }
.tl-bar { width: 2px; flex: 1; min-height: 22px; background: var(--border-default); margin: 2px 0; }
.tl-row.done .tl-dot { background: var(--c-success-600); border-color: var(--c-success-600); color: #fff; }
.tl-row.done .tl-bar { background: var(--c-success-600); }
.tl-row.cancel .tl-dot { background: var(--c-error-600); border-color: var(--c-error-600); color: #fff; }
.tl-tx { display: flex; flex-direction: column; padding-bottom: 18px; }
.tl-k { font-weight: var(--fw-bold); font-size: 14px; color: var(--fg-strong); }
.tl-d { font-size: 13px; color: var(--fg-muted); }

/* ---- Molécula: tabla de datos (backoffice/control) ---------------------------- */
.dtable { width: 100%; border-collapse: collapse; font-size: 14px; }
.dtable th { text-align: left; font-size: var(--fs-caption); font-weight: var(--fw-bold); letter-spacing: var(--ls-caps);
  text-transform: uppercase; color: var(--fg-subtle); padding: 10px 14px; border-bottom: 1px solid var(--border-default);
  background: var(--bg-surface-2); white-space: nowrap; }
.dtable td { padding: 12px 14px; border-bottom: 1px solid var(--border-subtle); color: var(--fg-default); vertical-align: middle; }
.dtable tbody tr { cursor: pointer; transition: background var(--dur-fast); }
.dtable tbody tr:hover { background: var(--bg-brand-soft); }
.dtable .row-hoy { box-shadow: inset 3px 0 0 var(--c-orange-600); }

/* ---- Molécula: modal ------------------------------------------------------------ */
.modal-scrim { position: fixed; inset: 0; background: var(--bg-scrim); display: flex; align-items: center;
  justify-content: center; z-index: 80; padding: 20px; animation: fadeIn var(--dur-base) var(--ease-standard); }
.modal { background: var(--bg-surface); border-radius: var(--radius-lg); box-shadow: var(--elev-4); width: 100%;
  max-width: 560px; max-height: 90vh; overflow: auto; padding: var(--space-5); }
@keyframes fadeIn { from { opacity: 0; } }

/* ---- Molécula: resumen clave-valor ----------------------------------------------- */
.summary { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-md);
  box-shadow: var(--elev-1); padding: 4px 16px; }
.sum-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 13px 0;
  border-bottom: 1px solid var(--border-subtle); }
.sum-row:last-child { border-bottom: 0; }
.sum-k { display: flex; align-items: center; gap: 8px; font-weight: var(--fw-semibold); font-size: 14px; color: var(--fg-muted); }
.sum-v { font-weight: var(--fw-bold); font-size: 14px; color: var(--fg-strong); text-align: right; }

/* ---- Organismo: barra "volver al portal" ------------------------------------------- */
.portal-bar { display: flex; align-items: center; gap: 8px; padding: 8px 14px; background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle); color: var(--fg-muted); font-size: 13px; font-weight: var(--fw-semibold); }
.portal-bar a { display: inline-flex; align-items: center; gap: 6px; color: var(--fg-strong); text-decoration: none;
  padding: 6px 12px; border-radius: var(--radius-pill); background: var(--bg-sunken); min-height: 32px; }
.portal-bar a:hover { background: var(--c-gray-200); color: var(--fg-strong); }
.portal-bar .spacer { flex: 1; }

/* ---- Utilidades -------------------------------------------------------------------- */
.row { display: flex; align-items: center; gap: var(--space-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.stack { display: flex; flex-direction: column; gap: var(--space-3); }
.muted { color: var(--fg-muted); }
.subtle { color: var(--fg-subtle); }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
