:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --ink: #2b2520;
  --muted: #8a7f72;
  --line: #ece5da;
  --primary: #d6336c;       /* magenta dulce */
  --primary-ink: #ffffff;
  --accent: #f59f00;        /* caramelo */
  --ok: #2f9e44;
  --danger: #e03131;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(43,37,32,.06);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--muted); }
.error { color: var(--danger); font-size: .9rem; }

/* ── Botones ── */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; border-radius: 10px;
  padding: .6rem 1rem; transition: filter .15s, background .15s;
}
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: var(--line); }
.btn-sm { padding: .35rem .7rem; font-size: .85rem; }
.btn-danger { background: var(--danger); color: #fff; }

/* ── Login ── */
.login-wrap {
  min-height: 100%; display: grid; place-items: center; padding: 1.5rem;
  background: radial-gradient(120% 80% at 50% -10%, #fff0f5 0%, var(--bg) 55%);
}
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.login-card { width: 100%; max-width: 360px; padding: 2rem; display: grid; gap: .85rem; }
.brand { display: flex; align-items: center; justify-content: center; }
.brand-logo { width: 130px; height: auto; border-radius: 16px; }
.topnav-logo { height: 34px; width: auto; display: block; border-radius: 8px; }
.login-card label { display: grid; gap: .3rem; font-size: .85rem; color: var(--muted); }
.login-card input {
  font: inherit; padding: .6rem .7rem; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; color: var(--ink);
}
.login-card input:focus { outline: 2px solid color-mix(in srgb, var(--primary) 40%, transparent); border-color: var(--primary); }

/* ── Topnav ── */
.topnav {
  display: flex; align-items: center; gap: 1.25rem;
  padding: .7rem 1.25rem; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.topnav-brand { font-weight: 800; display: flex; align-items: center; gap: .4rem; }
.topnav-modules { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.topnav-modules a {
  text-decoration: none; color: var(--muted); padding: .4rem .7rem;
  border-radius: 8px; font-weight: 600; font-size: .9rem;
}
.topnav-modules a:hover { background: var(--line); color: var(--ink); }
.topnav-modules a.active { background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); }
.topnav-right { display: flex; align-items: center; gap: .75rem; }

/* ── Contenido ── */
.content { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.25rem; }
.page-title { font-size: 1.3rem; margin: 0 0 1rem; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; }
.stat { padding: 1.1rem; }
.stat .n { font-size: 2rem; font-weight: 800; color: var(--primary); }
.stat .l { color: var(--muted); font-size: .85rem; }

table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
th, td { text-align: left; padding: .7rem .85rem; border-bottom: 1px solid var(--line); font-size: .9rem; }
th { background: #fbf6ef; color: var(--muted); font-weight: 700; }
tbody tr:last-child td { border-bottom: none; }
.toolbar { display: flex; gap: .6rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.toolbar input { padding: .5rem .7rem; border: 1px solid var(--line); border-radius: 10px; font: inherit; }
.badge { font-size: .75rem; padding: .15rem .5rem; border-radius: 999px; background: var(--line); color: var(--muted); white-space: nowrap; }
.badge.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--accent) 18%, transparent); color: #b3760a; }

/* ── Encabezado de página ── */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head .page-title { margin: 0; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.row-actions { display: flex; gap: .35rem; justify-content: flex-end; white-space: nowrap; }

/* ── Modales ── */
.modal-back {
  position: fixed; inset: 0; background: rgba(43,37,32,.45); backdrop-filter: blur(2px);
  display: grid; place-items: center; padding: 1rem; z-index: 100; opacity: 0; transition: opacity .18s;
}
.modal-back.show { opacity: 1; }
.modal {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 480px; padding: 1.4rem; max-height: 90vh; overflow: auto;
  transform: translateY(8px); transition: transform .18s;
}
.modal-back.show .modal { transform: translateY(0); }
.modal-wide { max-width: 760px; }
.modal-title { margin: 0 0 1rem; font-size: 1.15rem; }
.modal-msg { margin: 0 0 1.2rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.2rem; }
.modal-scroll { max-height: 55vh; overflow: auto; }
.modal-total { text-align: right; margin: 1rem 0 0; font-size: 1.05rem; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.field { display: grid; gap: .3rem; font-size: .82rem; color: var(--muted); }
.field.col2 { grid-column: 1 / -1; }
.field input, .field select, .field textarea {
  font: inherit; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--ink); width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 35%, transparent); border-color: var(--primary); }

/* ── Pedidos: ítems ── */
.items-head { display: flex; justify-content: space-between; align-items: center; margin: 1rem 0 .5rem; font-weight: 600; }
.items-list { display: grid; gap: .5rem; }
.item-row { display: grid; grid-template-columns: 1fr 90px 120px 36px; gap: .4rem; }
.item-row input { font: inherit; padding: .45rem .5rem; border: 1px solid var(--line); border-radius: 8px; }

/* ── Settings ── */
.setting-card { padding: 1.2rem; }
.setting-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .6rem; }
.setting-head h3 { margin: 0; font-size: 1rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .3rem .8rem; margin: 0; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }

/* ── Toast ── */
.toast-host { position: fixed; bottom: 1.2rem; right: 1.2rem; display: grid; gap: .5rem; z-index: 200; }
.toast {
  background: var(--ink); color: #fff; padding: .7rem 1rem; border-radius: 10px; font-size: .9rem;
  box-shadow: var(--shadow); opacity: 0; transform: translateX(12px); transition: opacity .2s, transform .2s; max-width: 320px;
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast-ok { background: var(--ok); }
.toast-warn { background: var(--accent); color: #2b2520; }
.toast-error { background: var(--danger); }

/* ── Marcación ── */
.marcar-actions { display: grid; gap: .6rem; margin-top: .4rem; }
.ok-msg { color: var(--ok); font-weight: 600; }

/* ── QR de marcación ── */
.tienda-name { text-align: center; font-weight: 700; color: var(--primary); margin: -.3rem 0 .2rem; }
.qr-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; margin-top: 1rem; }
.qr-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; text-align: center; background: #fff; }
.qr-card h4 { margin: 0 0 .6rem; }
.qr-img { width: 100%; max-width: 220px; height: auto; image-rendering: pixelated; }
.qr-url { font-size: .8rem; margin: .5rem 0; }

/* ── Navegación móvil ── */
.nav-toggle { display: none; font-size: 1.2rem; padding: .4rem .7rem; }

@media (max-width: 820px) {
  .nav-toggle { display: inline-block; order: -1; }
  .topnav { flex-wrap: wrap; gap: .6rem; }
  .topnav-modules {
    flex-basis: 100%; flex-direction: column; align-items: stretch;
    display: none; gap: .15rem; padding-top: .4rem; border-top: 1px solid var(--line);
  }
  .topnav-modules.open { display: flex; }
  .topnav-modules a { padding: .7rem .8rem; }
  .topnav-right { margin-left: auto; }
  .topnav-right .muted { display: none; }
  .content { padding: 1rem .85rem; }
  .page-head { gap: .6rem; }
}

@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; }
  .item-row { grid-template-columns: 1fr 64px 84px 30px; }
  table { font-size: .82rem; display: block; overflow-x: auto; white-space: nowrap; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
  .cards { grid-template-columns: 1fr 1fr; }
  .brand-logo { width: 110px; }
}

/* ── Asistente IA ── */
.ai-fab {
  position: fixed; bottom: 1.3rem; right: 1.3rem; width: 54px; height: 54px; border-radius: 50%;
  border: none; background: var(--primary); color: #fff; font-size: 1.4rem; cursor: pointer;
  box-shadow: var(--shadow); z-index: 90; transition: transform .15s;
}
.ai-fab:hover { transform: scale(1.06); }
.ai-answer { margin-top: .4rem; white-space: pre-wrap; line-height: 1.5; font-size: .92rem; max-height: 45vh; overflow: auto; }
.modal textarea { font: inherit; width: 100%; padding: .6rem; border: 1px solid var(--line); border-radius: 10px; }

/* ── Impresión (QR) ── */
@media print {
  .topnav, .page-head, .modal-actions, .toolbar { display: none !important; }
  .modal-back { position: static; background: none; }
  .modal { box-shadow: none; max-width: none; }
}
