/* Kapyderm QR - componentes: botones, campos, tarjetas, chips, hoja inferior. */

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 22px; border: 0; border-radius: var(--r-pill);
  font-size: 1rem; font-weight: 600; letter-spacing: -0.005em; line-height: 1;
  text-decoration: none; white-space: nowrap;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  transition: transform 120ms var(--ease-out), background-color 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; pointer-events: none; }
.btn .icon { width: 20px; height: 20px; }
.btn-primary { color: #fff; background: var(--navy); box-shadow: 0 8px 18px -10px rgba(37, 42, 93, 0.7); }
.btn-secondary { color: var(--navy); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line-strong); }
.btn-danger { color: #fff; background: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { min-height: 44px; padding: 0 16px; font-size: 0.9375rem; }
.btn-icon { width: 50px; padding: 0; position: relative; flex: none; }
.btn-icon.btn-sm { width: 44px; }
.btn.is-done { background: var(--ok-bg); color: var(--ok); box-shadow: none; }

@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover { background: var(--navy-deep); }
  .btn-secondary:hover { background: #fbfbf9; box-shadow: inset 0 0 0 1px var(--navy); }
  .btn-danger:hover { background: #8f1d17; }
  .topnav a:hover, .topnav-btn:hover { background: rgba(37, 42, 93, 0.06); color: var(--navy); }
  .row:hover { background: #fafaf8; }
  .action:hover { background: #fafaf8; }
}

/* ---------- Campos (16 px: sin zoom en iOS) ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 0.8125rem; font-weight: 600; color: var(--muted); letter-spacing: 0.01em; }
.input {
  width: 100%; min-height: 50px; padding: 12px 16px;
  font-size: 16px; line-height: 1.3; color: var(--ink);
  background: var(--surface); border: 0; border-radius: var(--r-ctl);
  box-shadow: inset 0 0 0 1px var(--line-strong);
  -webkit-appearance: none; appearance: none;
  transition: box-shadow 150ms ease, background-color 150ms ease;
}
select.input {
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9' fill='none' stroke='%23666670' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m1.5 1.5 5.5 5.5 5.5-5.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 16px center;
}
textarea.input { min-height: 96px; resize: vertical; }
.input::placeholder { color: #9a9aa3; }
.input:focus { outline: none; box-shadow: inset 0 0 0 2px var(--blue), 0 0 0 4px rgba(130, 205, 255, 0.45); }
.input.is-invalid { box-shadow: inset 0 0 0 2px var(--danger); }
.field-error { font-size: 0.8125rem; color: var(--danger); font-weight: 500; }
.form-alert {
  padding: 12px 16px; border-radius: var(--r-ctl); background: var(--danger-bg); color: var(--danger);
  font-size: 0.9375rem; font-weight: 500;
}
input[type="date"].input { min-height: 50px; }

.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 16px; border-radius: var(--r-ctl); background: var(--surface-2); cursor: pointer;
}
.switch-row strong { display: block; font-size: 1rem; font-weight: 600; }
.switch-row small { display: block; margin-top: 2px; color: var(--muted); font-size: 0.8125rem; line-height: 1.35; }
.switch {
  -webkit-appearance: none; appearance: none; flex: none;
  width: 51px; height: 31px; border-radius: var(--r-pill); background: #cfd0d6; position: relative; margin: 0;
  transition: background-color 220ms ease; cursor: pointer;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25);
  transition: transform 260ms var(--ease-drawer);
}
.switch:checked { background: var(--blue); }
.switch:checked::after { transform: translateX(20px); }

/* ---------- Tarjetas y grupos ---------- */
.card, .group, .qr-card {
  background: var(--surface); border-radius: var(--r-card); box-shadow: var(--shadow-card);
}
.card { padding: 18px; }
.card-title { font-size: 0.8125rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 14px; }
.group { padding: 16px; display: grid; gap: 14px; border: 0; margin: 0; min-width: 0; }

/* ---------- Chips y estados ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  display: inline-flex; align-items: center; height: 26px; padding: 0 10px; border-radius: var(--r-pill);
  font-size: 0.8125rem; font-weight: 600; color: var(--navy); background: var(--sky-soft); max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip-alt { color: #14558f; background: #dcebfa; }
.chip-quiet { color: var(--muted); background: var(--surface-2); }
.status {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: var(--r-pill);
  font-size: 0.8125rem; font-weight: 600; white-space: nowrap;
}
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-on { color: var(--ok); background: var(--ok-bg); }
.status-off { color: var(--warn); background: var(--warn-bg); }
.badge {
  position: absolute; top: 6px; right: 6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--r-pill);
  background: var(--navy); color: #fff; font-size: 0.6875rem; font-weight: 700; display: grid; place-items: center;
}

/* ---------- Avisos ---------- */
.flash {
  display: flex; align-items: center; gap: 10px; margin-bottom: 14px; padding: 12px 16px; border-radius: var(--r-ctl);
  font-size: 0.9375rem; font-weight: 500; animation: flash-in 320ms var(--ease-out);
  transition: opacity 300ms ease, transform 300ms var(--ease-out);
}
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--danger-bg); color: var(--danger); }
.flash.is-leaving { opacity: 0; transform: translateY(-6px); }
@keyframes flash-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ---------- Segmentado (periodo) ---------- */
.segmented {
  display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; padding: 3px;
  border-radius: 12px; background: rgba(37, 42, 93, 0.08); width: 100%;
}
.segmented a {
  display: grid; place-items: center; min-height: 40px; padding: 0 10px; border-radius: 9px;
  font-size: 0.875rem; font-weight: 600; color: var(--muted); white-space: nowrap;
  transition: background-color 180ms ease, color 180ms ease, box-shadow 180ms ease;
}
.segmented a.is-active { background: var(--surface); color: var(--navy); box-shadow: 0 1px 3px rgba(15, 20, 71, 0.18); }

/* ---------- Hoja inferior (movil) / panel en linea (escritorio) ---------- */
.sheet-grab { display: none; }
.sheet-title { font-size: 0.8125rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 12px; }
.sheet-grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-actions .btn { flex: 1; }

@media (max-width: 899px) {
  .js .sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    max-height: 88dvh; overflow-y: auto; overscroll-behavior: contain;
    padding: 8px var(--gutter) calc(20px + var(--safe-b));
    background: var(--surface); border-radius: 26px 26px 0 0;
    box-shadow: 0 -12px 40px -12px rgba(15, 20, 71, 0.35);
    transform: translateY(105%); visibility: hidden;
    transition: transform 340ms var(--ease-drawer), visibility 0s linear 340ms;
  }
  .js .sheet.is-open { transform: none; visibility: visible; transition-delay: 0s; }
  .js .sheet.is-dragging { transition: none; }
  .js .sheet-grab { display: block; width: 100%; height: 28px; position: relative; touch-action: none; cursor: grab; }
  .js .sheet-grab::after {
    content: ""; position: absolute; top: 10px; left: 50%; width: 38px; height: 5px; margin-left: -19px;
    border-radius: 3px; background: rgba(37, 42, 93, 0.22);
  }
  .js .scrim {
    position: fixed; inset: 0; z-index: 50; background: rgba(15, 20, 71, 0.38);
    opacity: 0; transition: opacity 300ms ease;
  }
  .js .scrim.is-open { opacity: 1; }
  .scrim[hidden] { display: none; }
}
@media (min-width: 900px) {
  .scrim { display: none !important; }
  .sheet-open, .js .sheet-open { display: none; }
  .sheet-grab, .sheet-title { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .js .sheet { transition: opacity 200ms ease, visibility 0s linear 200ms; transform: none; opacity: 0; }
  .js .sheet.is-open { opacity: 1; }
  .flash { animation: none; }
  .btn:active, .tab:active { transform: none; }
}
