/* ============================================================
   CLOBI Recetas · mobile-first, iPhone-friendly
   ============================================================ */
:root {
  /* Paleta Barbie */
  --c-blue: #E0218A;            /* Barbie Pink (Pantone 219 C) — color primario */
  --c-blue-dark: #B5176F;       /* hover/active del primario */
  --c-blue-soft: #FFE4F0;       /* pastel para pills, fondos suaves */
  --c-ink: #2E1F2B;             /* casi negro con tinte ciruela */
  --c-muted: #8B6B7E;            /* texto secundario en tono mauve */
  --c-line: #F5D0E3;            /* divisores rosa pálido */
  --c-bg: #FFF5F9;              /* fondo crema rosado */
  --c-card: #FFFFFF;
  --c-accent: #FFC0CB;          /* rosa pastel (acento) */
  --c-gold: #F5C99B;             /* dorado suave para detalles opcionales */
  --c-success: #4FB793;          /* verde menta (compatible con Barbie) */
  --c-warn: #B96A4F;             /* terracota */
  --c-warn-bg: #FFE7DC;
  --c-danger: #D62B6A;           /* rosa fuerte para destructivos */
  --c-ok-bg: #DEF5EA;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.06);
  --shadow-md: 0 4px 12px rgba(15,23,42,.08);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --nav-h: 56px;
  --bottom-h: calc(62px + var(--safe-bottom));
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--c-bg);
  color: var(--c-ink);
  font-size: 16px;       /* ≥16px evita zoom al enfocar inputs en iOS */
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding-bottom: var(--bottom-h);
  min-height: 100vh;
}
body.body-auth {
  padding-bottom: 0; min-height: 100dvh;
  background:
    radial-gradient(circle at 20% 0%, #FFB6D9 0%, transparent 55%),
    radial-gradient(circle at 80% 100%, #FF6FA9 0%, transparent 55%),
    linear-gradient(180deg, var(--c-blue) 0%, var(--c-blue-dark) 100%);
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(135deg, var(--c-blue) 0%, #FF6FA9 100%);
  color: #fff;
  padding-top: var(--safe-top);
  box-shadow: 0 2px 8px rgba(224,33,138,.18);
}
.topbar-inner {
  max-width: 1100px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; min-height: var(--nav-h);
}
.brand { display: flex; flex-direction: column; color: #fff; text-decoration: none; line-height: 1.1; }
.brand-mark { font-size: 18px; font-weight: 800; letter-spacing: .5px; }
.brand-sub { font-size: 11px; opacity: .8; text-transform: uppercase; letter-spacing: 1px; }
.topnav { display: flex; gap: 10px; align-items: center; }
.topnav-link { color: #fff; text-decoration: none; font-size: 14px; opacity: .85; padding: 6px 8px; border-radius: 6px; }
.topnav-link:hover, .topnav-link:active { opacity: 1; background: rgba(255,255,255,.08); }
.topnav-user { display: none; align-items: center; gap: 8px; padding-left: 8px; border-left: 1px solid rgba(255,255,255,.3); }
.user-name { font-size: 13px; font-weight: 600; }
.user-sub { font-size: 12px; color: rgba(255,255,255,.7); text-decoration: none; }
.logout-form { margin: 0; }
.btn-link {
  background: none; border: 0; color: #fff; padding: 4px 8px;
  cursor: pointer; font-size: 13px; text-decoration: underline;
}

/* ---------- Container ---------- */
.container {
  max-width: 900px; margin: 0 auto;
  padding: 16px;
}
.container-auth {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}

/* ---------- Flashes ---------- */
.flash {
  padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 12px;
  font-size: 14px; font-weight: 500;
}
.flash-success { background: var(--c-ok-bg); color: #14532d; }
.flash-warning { background: var(--c-warn-bg); color: #78350f; }
.flash-danger  { background: #fee2e2; color: #991b1b; }
.flash-info    { background: var(--c-blue-soft); color: var(--c-blue-dark); }

/* ---------- Page header ---------- */
.page-header {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 12px; margin: 4px 0 16px;
}
.page-header h1 { font-size: 22px; margin: 0; }
.page-header h2 { font-size: 17px; margin: 14px 0 6px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--c-muted); font-size: 14px; margin: 0; }

/* ---------- Botones (touch-friendly 44px) ---------- */
.btn, button.btn, a.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  background: #fff; color: var(--c-ink);
  border: 1px solid var(--c-line); border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 600; text-decoration: none;
  cursor: pointer; transition: background .15s, transform .05s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--c-blue); color: #fff; border-color: var(--c-blue); }
.btn-primary:hover, .btn-primary:active { background: var(--c-blue-dark); }
.btn-danger { background: var(--c-danger); color: #fff; border-color: var(--c-danger); }
.btn-block { width: 100%; }
.btn-sm {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 36px; padding: 0 12px; font-size: 13px; font-weight: 600;
  background: #fff; color: var(--c-ink);
  border: 1px solid var(--c-line); border-radius: var(--radius-sm);
  text-decoration: none; cursor: pointer;
}
.btn-warn { background: var(--c-warn-bg); color: #78350f; border-color: #fde68a; }
.btn-ok   { background: var(--c-ok-bg); color: #14532d; border-color: #bbf7d0; }
.inline-form { display: inline; margin: 0; }

/* ---------- Cards ---------- */
.card {
  background: var(--c-card); border: 1px solid var(--c-line);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}
.card h3 { margin: 0 0 8px 0; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--c-blue); }
.cards-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-bottom: 16px; }
@media (min-width: 720px) { .cards-grid { grid-template-columns: 1fr 1fr; } }

.kv { display: grid; grid-template-columns: 1fr; gap: 6px; margin: 0; }
.kv > div { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; border-bottom: 1px dashed var(--c-line); padding: 4px 0; }
.kv > div:last-child { border-bottom: 0; }
.kv dt { color: var(--c-muted); }
.kv dd { margin: 0; font-weight: 500; text-align: right; }

/* ---------- Search bar ---------- */
.search-bar {
  display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap;
}
.search-bar input { flex: 1; min-width: 0; }
.filters input[type="date"] { max-width: 160px; }

/* ---------- List cards ---------- */
.list-cards { display: flex; flex-direction: column; gap: 8px; }
.list-card {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; background: var(--c-card); border: 1px solid var(--c-line);
  border-radius: var(--radius); text-decoration: none; color: inherit;
  min-height: 60px; box-shadow: var(--shadow-sm);
}
.list-card:hover { border-color: var(--c-blue); }
.list-card.static:hover { border-color: var(--c-line); }
.list-card-main { min-width: 0; flex: 1; }
.list-card-title { font-weight: 600; font-size: 15px; }
.list-card-sub { font-size: 13px; color: var(--c-muted); }
.list-card-meta { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.list-card-actions { display: flex; gap: 6px; }
.pill {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  background: var(--c-blue-soft); color: var(--c-blue-dark);
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px;
}
.pill-alt { background: #f1f5f9; color: var(--c-ink); }
.pill-warn { background: var(--c-warn-bg); color: #78350f; }

/* ---------- Empty ---------- */
.empty {
  padding: 36px 18px; text-align: center; background: #fff;
  border: 1px dashed var(--c-line); border-radius: var(--radius);
  color: var(--c-muted);
}
.empty p { margin: 0 0 12px; }

/* ---------- Forms ---------- */
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-stack fieldset {
  border: 1px solid var(--c-line); border-radius: var(--radius);
  padding: 14px; margin: 0; background: #fff;
}
.form-stack legend {
  padding: 0 8px; font-weight: 700; color: var(--c-blue);
  font-size: 12px; text-transform: uppercase; letter-spacing: 1px;
}
label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 13px; color: var(--c-muted); font-weight: 600;
}
label span { text-transform: uppercase; letter-spacing: .4px; font-size: 11px; }
input[type="text"], input[type="email"], input[type="password"],
input[type="tel"], input[type="search"], input[type="date"],
input[type="number"], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  font-size: 16px;             /* anti-zoom iOS */
  font-family: inherit; color: var(--c-ink); background: #fff;
  border: 1px solid var(--c-line); border-radius: var(--radius-sm);
  -webkit-appearance: none; appearance: none;
}
textarea { min-height: 80px; resize: vertical; padding: 10px 12px; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--c-blue);
  box-shadow: 0 0 0 3px rgba(224,33,138,.20);
}
input[disabled] { background: #f1f5f9; color: var(--c-muted); }

.grid-2, .grid-5 { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: 1fr; }
.grid-5 { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 600px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-5 { grid-template-columns: repeat(5, 1fr); }
}

.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.form-actions .btn, .form-actions button { flex: 1; min-width: 140px; }
@media (min-width: 600px) { .form-actions .btn, .form-actions button { flex: 0 0 auto; } }
.actions-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }

.danger-zone {
  margin-top: 24px; padding-top: 16px; border-top: 1px dashed var(--c-line);
  text-align: right;
}

/* ---------- Timeline ---------- */
.timeline { list-style: none; padding: 0; margin: 0; position: relative; }
.timeline::before {
  content: ""; position: absolute; left: 14px; top: 4px; bottom: 4px;
  width: 2px; background: var(--c-line);
}
.tl-item {
  position: relative; padding: 8px 0 14px 36px; margin: 0;
}
.tl-item::before {
  content: ""; position: absolute; left: 8px; top: 14px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--c-blue); border: 3px solid #fff;
  box-shadow: 0 0 0 1px var(--c-line);
}
.tl-receta::before { background: #16a34a; }
.tl-date { font-size: 12px; color: var(--c-muted); text-transform: uppercase; letter-spacing: .5px; }
.tl-title { font-weight: 600; text-decoration: none; color: var(--c-ink); }
.tl-title:hover { color: var(--c-blue); text-decoration: underline; }
.tl-sub { font-size: 13px; color: var(--c-muted); }

/* ---------- Rx preview ---------- */
.rx-preview { width: 100%; border-collapse: collapse; margin-top: 4px; }
.rx-preview th, .rx-preview td { border: 1px solid var(--c-line); padding: 6px 8px; text-align: center; font-size: 13px; }
.rx-preview thead th { background: var(--c-blue); color: #fff; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.rx-preview tbody th { background: #f8fafc; text-align: left; font-weight: 600; }
.rx-preview tbody td { font-family: "SF Mono", Menlo, Consolas, monospace; font-weight: 600; }

/* ---------- Concepto (CFDI) ---------- */
.concepto { background: #f8fafc; border: 1px solid var(--c-line); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 12px; }
.concepto-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; font-size: 12px; color: var(--c-muted); }
.concepto-head .tag { background: var(--c-blue); color: #fff; padding: 2px 8px; border-radius: 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.concepto-body { font-size: 14px; line-height: 1.5; padding: 8px; background: #fff; border: 1px dashed var(--c-line); border-radius: 4px; margin: 6px 0; white-space: pre-wrap; }
.btn-copy { background: var(--c-blue); color: #fff; border: 0; border-radius: 6px; padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer; min-height: 36px; }
.btn-copy.copied { background: var(--c-success); }

/* ---------- Audit log ---------- */
.audit-list { display: flex; flex-direction: column; gap: 6px; }
.audit-row { display: flex; gap: 10px; align-items: flex-start; background: #fff; border: 1px solid var(--c-line); border-radius: var(--radius-sm); padding: 8px 10px; font-size: 13px; }
.audit-when { color: var(--c-muted); font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 11px; white-space: nowrap; }
.audit-main { flex: 1; min-width: 0; }
.audit-details { margin-top: 3px; font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 11px; color: var(--c-muted); word-break: break-word; }
.audit-meta { font-size: 11px; }

/* ---------- Auth card ---------- */
.auth-card {
  width: 100%; max-width: 380px;
  background: #fff; border-radius: var(--radius);
  padding: 28px 24px; box-shadow: var(--shadow-md);
}
.auth-brand { text-align: center; margin-bottom: 20px; }
.auth-logo {
  width: 64px; height: 64px; margin: 0 auto 10px;
  background: var(--c-blue); color: #fff; border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 800; letter-spacing: 1px;
}
.auth-brand h1 { margin: 0; font-size: 20px; color: var(--c-blue); }
.auth-form { display: flex; flex-direction: column; gap: 12px; }

/* ---------- Bottom nav (móvil) ---------- */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: #fff; border-top: 1px solid var(--c-line);
  padding-bottom: var(--safe-bottom);
  box-shadow: 0 -2px 10px rgba(15,23,42,.06);
}
.bn-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 6px 4px; min-height: 62px;
  color: var(--c-muted); text-decoration: none;
  font-size: 11px; font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
.bn-item.active { color: var(--c-blue); }
.bn-item.active .bn-icon { transform: scale(1.1); }
.bn-icon { font-size: 22px; line-height: 1; transition: transform .15s; }
.bn-label { letter-spacing: .2px; }
.bn-primary { color: var(--c-blue); }
.bn-primary .bn-icon {
  width: 44px; height: 44px; border-radius: 50%;
  background: linear-gradient(135deg, var(--c-blue) 0%, #FF6FA9 100%);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; margin-top: -8px;
  box-shadow: 0 4px 12px rgba(224,33,138,.35);
}

/* ---------- Responsive topbar ---------- */
@media (min-width: 720px) {
  .topnav-user { display: flex; }
  .bottomnav { display: none; }
  body { padding-bottom: 0; }
}

/* ---------- Graduación (selects tipo ruleta en iOS) ---------- */
.rx-fieldset { background: linear-gradient(180deg, #fff 0%, var(--c-blue-soft) 100%); }
.rx-grid {
  display: grid; gap: 8px;
  grid-template-columns: repeat(2, 1fr);
}
@media (min-width: 600px) { .rx-grid { grid-template-columns: repeat(5, 1fr); } }
.rx-grid label { gap: 4px; }
.rx-grid label span {
  font-size: 10px; color: var(--c-blue-dark); font-weight: 700;
  letter-spacing: .6px;
}
.rx-wheel {
  font-size: 18px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-weight: 700;
  text-align: center;
  text-align-last: center;
  color: var(--c-ink);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.9) 0%, transparent 20%, transparent 80%, rgba(255,255,255,0.9) 100%),
    #fff;
  border: 1px solid var(--c-line); border-radius: 10px;
  min-height: 52px;
  padding: 0 10px;
  box-shadow: inset 0 1px 2px rgba(224,33,138,.08);
}
.rx-wheel:focus { border-color: var(--c-blue); box-shadow: 0 0 0 3px rgba(224,33,138,.20); }

/* ---------- Chips (tratamientos multi-select) ---------- */
.chips-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--c-muted); font-weight: 600; margin-top: 8px; margin-bottom: 6px;
}
.chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 4px 0;
}
.chip {
  display: inline-flex; align-items: center;
  padding: 0; margin: 0;
  cursor: pointer; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-block; padding: 8px 12px;
  background: #fff; color: var(--c-ink);
  border: 1.5px solid var(--c-line); border-radius: 999px;
  font-size: 13px; font-weight: 600;
  transition: all .12s;
  min-height: 36px; line-height: 20px;
}
.chip input:checked + span {
  background: var(--c-blue); color: #fff; border-color: var(--c-blue);
  box-shadow: 0 2px 6px rgba(224,33,138,.25);
}
.chip:active span { transform: scale(.96); }

/* ---------- Warnings visuales de graduación ---------- */
.rx-warn {
  border-color: #E8A84C !important;
  background: #FFF8EC !important;
  box-shadow: 0 0 0 2px rgba(232,168,76,.2) !important;
}
.rx-warnings {
  margin: 10px 0;
  padding: 12px 14px;
  background: #FFF8EC;
  border: 1px solid #F0C88C;
  border-left: 4px solid #E8A84C;
  border-radius: var(--radius-sm);
  color: #78350F;
  font-size: 13px;
}
.rx-warnings strong { display: block; margin-bottom: 4px; color: #78350F; }
.rx-warnings ul { margin: 4px 0 0; padding-left: 18px; }
.rx-warnings li { margin-bottom: 2px; }

/* ---------- 2FA — tags y código de un solo uso ---------- */
.tag {
  display: inline-block;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .6px;
  padding: 3px 9px;
  border-radius: 999px;
  vertical-align: middle;
  font-weight: 600;
  margin-right: 6px;
}
.tag-ok   { background: #d1fae5; color: #065f46; }
.tag-warn { background: #fef3c7; color: #78350f; }
.tag-off  { background: #fee2e2; color: #991b1b; }

.codigo-input {
  font-family: "SF Mono", Menlo, ui-monospace, monospace !important;
  letter-spacing: .4em;
  text-align: center;
  font-size: 1.4rem !important;
  font-weight: 600;
}

.setup-grid {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 24px;
  align-items: start;
}
@media (max-width: 640px) {
  .setup-grid { grid-template-columns: 1fr; }
}

.form-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.form-inline input[type="password"] {
  flex: 1;
  min-width: 200px;
}

/* ---------- Print ---------- */
@media print {
  .topbar, .bottomnav, .danger-zone, .btn, .page-actions { display: none !important; }
  body { background: #fff; }
}
