/* Componentes reutilizables — fieles al lienzo aprobado. */

/* ---------- Tarjeta ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.card-pad { padding: 24px; }
.card-pad-sm { padding: 18px 20px; }
.card-title { font-family: var(--font-display); font-weight: 500; font-size: 20px; margin: 0; }
.card-gold { background: var(--gold-tint); border-color: #E6D5A6; }
.card-sage { background: var(--sage); border-color: var(--sage); color: #fff; }
.card-dashed { background: var(--ivory); border-style: dashed; }

/* ---------- KPI ---------- */
.kpi { padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.kpi-label { font-size: 13px; color: var(--muted); }
.kpi-value { font-family: var(--font-display); font-size: 30px; font-weight: 500; line-height: 1; }
.kpi-note { font-size: 12px; color: var(--muted); font-weight: 500; }
.kpi-note.up { color: #3F6B4A; }
.kpi-note.down { color: var(--danger); }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--touch); padding: 0 20px;
  border: 1px solid transparent; border-radius: var(--r-md);
  font-size: 14px; font-weight: 600; line-height: 1; text-decoration: none;
  background: var(--surface); color: var(--ink);
  transition: background-color .15s ease, border-color .15s ease, opacity .15s ease;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--sage); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--sage-dark); }
.btn-secondary { border-color: var(--line-strong); font-weight: 500; }
.btn-secondary:hover:not(:disabled) { background: var(--sand); }
.btn-outline { border-color: var(--sage); color: var(--sage-dark); background: transparent; }
.btn-gold { background: var(--gold-soft); color: var(--gold-deep); }
.btn-gold:hover:not(:disabled) { background: #EBDCB4; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--ink-2); font-weight: 500; }
.btn-ghost:hover:not(:disabled) { background: var(--sand); }
.btn-block { width: 100%; }
.btn-lg { min-height: 52px; font-size: 16px; border-radius: 14px; }
.btn-icon { width: var(--touch); padding: 0; font-size: 18px; border-color: var(--line-strong); font-weight: 500; }
.btn.is-loading { position: relative; color: transparent; pointer-events: none; }
.btn.is-loading::after {
  content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.5); border-top-color: #fff; animation: spin .7s linear infinite;
}
.btn-secondary.is-loading::after, .btn-gold.is-loading::after { border-color: rgba(0,0,0,.2); border-top-color: var(--ink); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Chips y estados ---------- */
.chip {
  display: inline-flex; align-items: center; padding: 4px 10px;
  border-radius: var(--r-pill); font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--neutral-soft); color: var(--ink-2);
}
.chip-sage { background: var(--sage-soft); color: var(--sage-deep); }
.chip-gold { background: var(--gold-soft); color: var(--warn-ink); }
.chip-info { background: var(--info-soft); color: var(--info-ink); }
.chip-danger { background: var(--danger-soft); color: var(--danger); }
.chip-muted { background: var(--neutral-soft); color: var(--muted); }

.filter-pill {
  display: inline-flex; align-items: center; min-height: 36px; padding: 0 16px;
  border: 1px solid var(--line-strong); border-radius: var(--r-pill);
  background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 500; text-decoration: none;
}
.filter-pill.is-active { background: var(--sage); border-color: var(--sage); color: #fff; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; min-width: 560px; }
.table th {
  text-align: left; padding: 14px 12px; font-size: 12px; font-weight: 500;
  color: var(--muted); border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 13px 12px; border-bottom: 1px solid var(--line-soft); font-size: 14px; vertical-align: middle; }
.table tbody tr:hover { background: var(--sage-tint); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.table-empty { padding: 36px 12px; text-align: center; color: var(--muted); }

/* ---------- Formularios ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .label { font-size: 13px; font-weight: 500; }
.field .hint { font-size: 12px; color: var(--muted); }
.field .error { font-size: 12px; color: var(--danger); font-weight: 500; }
.input, .select, .textarea {
  width: 100%; min-height: 46px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--ink); font-size: 15px;
}
.textarea { min-height: 90px; padding: 12px 14px; resize: vertical; }
.input::placeholder { color: var(--faint); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--sage); box-shadow: var(--focus); }
.field.has-error .input, .field.has-error .select, .field.has-error .textarea { border-color: var(--danger); background: #FFFAF8; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); gap: 16px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; padding-top: 8px; }
.check { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; line-height: 1.4; }
.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--sage); flex: none; }

.search {
  display: flex; align-items: center; gap: 8px; min-height: var(--touch); padding: 0 12px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-md); min-width: 240px;
}
.search input { border: 0; outline: 0; flex: 1; background: transparent; min-height: 40px; font-size: 14px; }

/* ---------- Pestañas ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); }
.tab {
  padding: 12px 14px; font-size: 14px; color: var(--muted); text-decoration: none;
  border-bottom: 3px solid transparent;
}
.tab.is-active { color: var(--ink); font-weight: 600; border-bottom-color: var(--sage); }

/* ---------- Avatar, progreso, interruptor ---------- */
.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  background: var(--sage-soft); color: var(--sage-dark);
  display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600;
}
.avatar-lg { width: 52px; height: 52px; font-size: 17px; }
.avatar-gold { background: var(--gold-soft); color: var(--gold-ink); }

.progress { height: 8px; background: #EEF2EC; border-radius: 4px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--sage); border-radius: 4px; }

.toggle { position: relative; display: inline-block; width: 40px; height: 24px; flex: none; }
.toggle input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.toggle i { position: absolute; inset: 0; background: var(--line-strong); border-radius: 12px; transition: background-color .15s; pointer-events: none; }
.toggle i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; }
.toggle input:checked + i { background: var(--sage); }
.toggle input:checked + i::after { transform: translateX(16px); }
.toggle input:focus-visible + i { box-shadow: var(--focus); }

/* ---------- Avisos y toasts ---------- */
.alert { padding: 12px 14px; border-radius: var(--r-md); font-size: 14px; line-height: 1.45; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-success { background: var(--sage-soft); color: var(--sage-deep); }
.alert-info { background: var(--info-soft); color: var(--info-ink); }
.alert-warn { background: var(--gold-soft); color: var(--gold-deep); }

.toast-region { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: flex; flex-direction: column; gap: 10px; max-width: min(380px, calc(100vw - 32px)); }
.toast {
  padding: 12px 16px; border-radius: var(--r-md); background: var(--ink); color: #fff; font-size: 14px;
  box-shadow: 0 8px 24px rgba(35,41,31,.25); animation: toast-in .2s ease;
}
.toast-success { background: var(--sage-dark); }
.toast-error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Modal (usa <dialog>) ---------- */
.modal {
  border: 0; padding: 0; border-radius: var(--r-xl); width: min(520px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); box-shadow: 0 24px 60px rgba(35,41,31,.3);
}
.modal::backdrop { background: rgba(35, 41, 31, .45); }
.modal-head { padding: 22px 24px 8px; }
.modal-body { padding: 8px 24px 8px; color: var(--ink-2); line-height: 1.5; }
.modal-foot { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; padding: 16px 24px 22px; }

/* ---------- Estados vacío, carga y error ---------- */
.empty { padding: 40px 20px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--muted); }
.empty h3 { color: var(--ink); }
.skeleton { background: linear-gradient(90deg, var(--sand) 25%, #F8F5EC 50%, var(--sand) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--r-sm); min-height: 16px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--sage-soft); border-top-color: var(--sage); animation: spin .8s linear infinite; }

/* ---------- Banner de datos de ejemplo / avisos de página ---------- */
.note-gold { font-size: 12px; color: var(--gold-ink); background: var(--gold-soft); border-radius: var(--r-sm); padding: 6px 12px; align-self: flex-start; }

/* ---------- Paginación ---------- */
.pagination { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: space-between; padding-top: 12px; font-size: 13px; color: var(--muted); }
.pagination .pages { display: flex; gap: 6px; }

/* ---------- Impresión (tickets y reportes) ---------- */
@media print {
  .sidebar, .page-actions, .no-print, .toast-region, .menu-toggle { display: none !important; }
  body { background: #fff; }
  .main { padding: 0; }
  .card { border-color: #ccc; }
}

/* Filas editables de formularios (agenda, compras, recetas) y listas de sugerencias (POS, agenda) */
.srv-row { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto; gap: 10px; align-items: end; padding: 12px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--ivory); }
.suggest { position: relative; }
.suggest-list { position: absolute; z-index: 10; left: 0; right: 0; top: 100%; margin-top: 4px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-md); box-shadow: 0 8px 24px rgba(35,41,31,.12); max-height: 260px; overflow: auto; }
.suggest-list button { display: block; width: 100%; text-align: left; padding: 10px 14px; border: 0; background: transparent; font-size: 14px; }
.suggest-list button:hover, .suggest-list button:focus-visible { background: var(--sage-tint); }
.srv-row.cols-3 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto; }
.srv-row.cols-4 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr) auto; }
@media (max-width: 640px) { .srv-row, .srv-row.cols-3, .srv-row.cols-4 { grid-template-columns: 1fr; } }

/* Móvil: 16 px en campos evita el zoom automático de iOS al enfocar; tablas y diálogos nunca más anchos que la pantalla */
@media (max-width: 720px) {
  .input, .select, .textarea { font-size: 16px; }
  dialog.modal { width: calc(100vw - 24px); }
}
/* Ventanas emergentes: si el contenido es más alto que la pantalla, solo el cuerpo se desplaza y los botones quedan visibles */
.modal > form { display: flex; flex-direction: column; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); }
.modal .modal-body { overflow-y: auto; min-height: 0; }
@media (max-width: 720px) { a.chip { min-height: 36px; display: inline-flex; align-items: center; } }
