/* ============================================================
   Dulce Teresa – estilos
   ============================================================ */
/* Paleta "repostería artesanal": crema, cacao, caramelo, rosa empolvado y salvia (ver CLAUDE.md) */
:root {
  --bg: #F8F1E6;
  --surface: #FFFDF9;
  --surface2: #F1E6D6;
  --text: #3E2A1E;
  --muted: #8A7466;
  --border: #E9DCCB;
  --primary: #6F4530;
  --primary-dark: #55331F;
  --accent: #C98A4B;
  --accent-dark: #A25F21;
  --rose: #C97C7C;
  --sage: #8FA88C;
  --ok: #5E8C5A;
  --danger: #B9473F;
  --tS: #D4795A;
  --tA: #E3A06A;
  --tB: #E9C978;
  --tC: #B3BC85;
  --tD: #9DB9C8;
  --tF: #BFB3A8;
  --radius: 16px;
  --shadow: 0 4px 18px rgba(62, 42, 30, .08);
  --font-ui: 'Nunito', system-ui, -apple-system, sans-serif;
  --font-brand: 'Fraunces', Georgia, serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}
body.modal-open { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; display: block; }
h1, h2, h3, h4 { font-family: var(--font-brand); font-weight: 600; margin: 0; }
h3 { font-size: 20px; }
h4 { font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-family: var(--font-ui); font-weight: 800; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); font-weight: 700; }
.ok { color: var(--ok); font-weight: 800; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

#app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: rgba(248, 241, 230, .92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px dashed #D9C6AE;
}
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--font-brand); font-style: italic; font-weight: 600; font-size: 23px; color: var(--primary); white-space: nowrap; letter-spacing: .01em; }
.brand.big { font-size: 30px; justify-content: center; }
.brand-icon { display: inline-flex; }
.brand-icon svg { width: 28px; height: 28px; display: block; }
.brand.big .brand-icon svg { width: 40px; height: 40px; }
.tagline { font-family: var(--font-ui); font-weight: 800; color: var(--muted); font-size: 12px; margin: -4px 0 12px; letter-spacing: .12em; text-transform: uppercase; }
.top-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.sync-dot { width: 10px; height: 10px; border-radius: 50%; background: #C9BFB8; box-shadow: 0 0 0 3px rgba(0,0,0,.04); }
.sync-dot.ok { background: var(--ok); }
.sync-dot.err { background: var(--danger); }
.sync-dot.wait { background: var(--accent); }
.icon-btn { border: 0; background: var(--surface2); width: 38px; height: 38px; border-radius: 50%; font-size: 18px; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }

.tabs { display: flex; gap: 4px; }
.tabs button { border: 0; background: transparent; padding: 8px 14px; border-radius: 999px; font-weight: 800; color: var(--muted); }
.tabs button.active { background: var(--primary); color: #FFF7EC; }
.tabs-top { margin-left: 8px; }
.tabs-bottom { display: none; }

.banner { background: #FFF3C4; color: #6B5300; font-size: 13px; font-weight: 700; padding: 8px 16px; display: flex; gap: 10px; align-items: center; }
.banner button { border: 0; background: transparent; font-weight: 800; margin-left: auto; color: inherit; }

main { flex: 1; padding: 12px 16px 100px; max-width: 1100px; width: 100%; margin: 0 auto; }

@media (max-width: 767px) {
  .tabs-top { display: none; }
  .tabs-bottom {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    background: #fff; border-top: 1px solid var(--border);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  }
  .tabs-bottom button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; padding: 6px 4px; border-radius: 12px; }
  .tabs-bottom button .ico { font-size: 22px; }
  .tabs-bottom button.active { background: var(--surface2); color: var(--primary); }
  main { padding-bottom: 120px; }
}

/* ---------- Toolbar / búsqueda / chips ---------- */
.toolbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.search { width: 100%; border: 1px solid var(--border); border-radius: 999px; padding: 11px 16px; background: #fff; font-size: 16px; font-weight: 600; outline: none; }
.search:focus { border-color: var(--primary); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chip { border: 1px solid var(--border); background: #fff; border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 800; color: var(--muted); white-space: nowrap; }
.chip.active { background: var(--text); color: #fff; border-color: var(--text); }
.chip.toggle.active { background: var(--accent); border-color: var(--accent); color: #3B2A22; }

.seg { display: inline-flex; background: var(--surface2); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: transparent; border-radius: 999px; padding: 7px 14px; font-weight: 800; color: var(--muted); font-size: 14px; white-space: nowrap; }
.seg button.active { background: #fff; color: var(--primary); box-shadow: 0 1px 4px rgba(0, 0, 0, .1); }
.seg.small button { padding: 5px 10px; font-size: 13px; }

.rank-toolbar { gap: 8px; }
.rank-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.me-btn { border: 1px solid var(--border); background: #fff; border-radius: 999px; padding: 7px 12px; font-weight: 800; display: inline-flex; gap: 6px; align-items: center; }
.me-btn .caret { color: var(--muted); }
.rank-status { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-weight: 800; font-size: 14px; margin-bottom: 8px; flex-wrap: wrap; }
.hint { font-size: 13px; color: var(--muted); margin: 0 0 10px; }

/* ---------- Grid de tarjetas ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; text-align: left; padding: 0; cursor: pointer; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.card:active { transform: scale(.98); }
.card .thumb { aspect-ratio: 1; background: var(--surface2); position: relative; display: flex; align-items: center; justify-content: center; font-size: 44px; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.card-body { padding: 10px 12px 12px; }
.card h3 { font-size: 15px; line-height: 1.2; font-family: var(--font-ui); font-weight: 800; }
.meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.price { font-weight: 800; color: var(--accent-dark); margin-top: 5px; }
.price small { color: var(--muted); font-weight: 700; }
.badge { position: absolute; top: 8px; left: 8px; background: var(--tc, #ddd); border-radius: 8px; padding: 1px 8px; font-family: var(--font-brand); font-weight: 700; font-size: 15px; box-shadow: 0 2px 6px rgba(0, 0, 0, .15); }
.card.desc { opacity: .6; }
.tag { position: absolute; bottom: 8px; right: 8px; background: rgba(59, 42, 34, .8); color: #fff; border-radius: 8px; padding: 2px 8px; font-size: 11px; font-weight: 800; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); font-weight: 700; grid-column: 1 / -1; }
.empty-ico { font-size: 44px; margin-bottom: 8px; }
.empty .btn { margin-top: 12px; }

/* ---------- Tier list ---------- */
.tier-row { display: flex; background: #fff; border: 1px solid var(--border); border-radius: 14px; overflow: hidden; margin-bottom: 8px; min-height: 100px; }
.tier-label { flex: 0 0 62px; display: flex; align-items: center; justify-content: center; font-family: var(--font-brand); font-weight: 700; font-size: 32px; background: var(--tc, #ddd); color: #3B2A22; }
.tier-row.pool .tier-label { font-size: 12px; font-family: var(--font-ui); font-weight: 800; background: var(--surface2); color: var(--muted); text-align: center; padding: 6px; line-height: 1.2; }
.tier-cards { flex: 1; display: flex; flex-wrap: wrap; gap: 8px; padding: 8px; align-content: flex-start; min-height: 100px; }
.tier-cards.over { background: var(--surface2); outline: 2px dashed var(--accent); outline-offset: -4px; }
.tcard { width: 78px; border: 0; background: transparent; padding: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; position: relative; cursor: pointer; -webkit-user-select: none; user-select: none; }
.tcard[draggable="true"] { cursor: grab; }
.tthumb { width: 72px; height: 72px; border-radius: 12px; overflow: hidden; background: var(--surface2); display: flex; align-items: center; justify-content: center; font-size: 30px; box-shadow: var(--shadow); }
.tthumb img { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.tname { font-size: 11px; line-height: 1.15; font-weight: 800; text-align: center; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-height: 2.4em; }
.score { position: absolute; top: -5px; right: -2px; background: #fff; border: 1px solid var(--border); border-radius: 999px; font-size: 10px; font-weight: 800; padding: 1px 6px; box-shadow: 0 1px 3px rgba(0,0,0,.1); }

.tier-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.tier-btn { border: 2px solid transparent; background: var(--tc); border-radius: 14px; padding: 10px 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; color: #3B2A22; }
.tier-btn b { font-family: var(--font-brand); font-size: 26px; font-weight: 700; line-height: 1; }
.tier-btn small { font-size: 11px; font-weight: 800; }
.tier-btn.sel { border-color: var(--text); box-shadow: 0 0 0 3px #fff inset; }

.sheet-head { display: flex; gap: 12px; align-items: center; }
.sheet-thumb { width: 72px; height: 72px; border-radius: 14px; overflow: hidden; background: var(--surface2); display: flex; align-items: center; justify-content: center; font-size: 32px; flex: 0 0 auto; }
.sheet-thumb img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Lista ranking general ---------- */
.rlist { display: flex; flex-direction: column; gap: 8px; }
.rrow { display: grid; grid-template-columns: 30px 56px 1fr auto; gap: 10px; align-items: center; background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 8px 10px; text-align: left; cursor: pointer; }
.rpos { font-family: var(--font-brand); font-size: 20px; font-weight: 700; color: var(--muted); text-align: center; }
.rthumb { width: 56px; height: 56px; border-radius: 10px; overflow: hidden; background: var(--surface2); display: flex; align-items: center; justify-content: center; font-size: 26px; }
.rthumb img { width: 100%; height: 100%; object-fit: cover; }
.rname { font-weight: 800; }
.rvotes { font-size: 11px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.rvotes span { background: var(--surface2); border-radius: 6px; padding: 1px 6px; }
.rscore { text-align: right; }
.tier-pill { display: inline-block; background: var(--tc); border-radius: 8px; padding: 2px 10px; font-family: var(--font-brand); font-weight: 700; font-size: 18px; }
.rscore small { display: block; color: var(--muted); font-size: 11px; font-weight: 700; margin-top: 3px; }

/* ---------- Botones ---------- */
.btn { border: 0; border-radius: 12px; padding: 11px 16px; font-weight: 800; background: var(--surface2); color: var(--text); display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; border: 1px solid var(--border); }
.btn.danger { background: #FDECEC; color: var(--danger); }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.file-btn { cursor: pointer; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.mini { border: 0; background: var(--surface2); border-radius: 10px; padding: 0 12px; font-weight: 800; }
.fab { position: fixed; right: 16px; bottom: calc(78px + env(safe-area-inset-bottom)); z-index: 15; border: 0; border-radius: 999px; background: var(--primary); color: #FFF7EC; font-weight: 800; font-size: 16px; padding: 14px 20px; box-shadow: 0 8px 24px rgba(111, 69, 48, .35); }
@media (min-width: 768px) { .fab { bottom: 28px; right: 28px; } }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(59, 42, 34, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--surface); width: 100%; max-height: 92vh; max-height: 92dvh; overflow: auto; border-radius: 22px 22px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); animation: up .22s ease; -webkit-overflow-scrolling: touch; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 768px) {
  .modal-backdrop { align-items: center; padding: 20px; }
  .modal { border-radius: 22px; max-width: 540px; max-height: 90vh; }
  .modal.full { max-width: 760px; }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 18px; align-items: center; }
.modal p { margin: 6px 0 12px; }

/* ---------- Formularios ---------- */
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 800; color: var(--muted); }
.form label small { font-weight: 600; }
.form input, .form select, .form textarea { border: 1px solid var(--border); border-radius: 12px; padding: 11px 12px; background: #fff; font-size: 16px; font-weight: 600; color: var(--text); width: 100%; outline: none; }
.form input:focus, .form select:focus, .form textarea:focus { border-color: var(--primary); }
.form textarea { min-height: 70px; resize: vertical; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 700; color: var(--text); }
.form label.check input { width: 20px; height: 20px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.input-btn { display: flex; gap: 6px; }
.input-btn input { flex: 1; min-width: 0; }
.row { display: flex; gap: 8px; align-items: center; }
.row input { flex: 1; min-width: 0; border: 1px solid var(--border); border-radius: 12px; padding: 11px 12px; font-size: 16px; font-weight: 600; outline: none; }

.foto-box { width: 100%; max-width: 260px; aspect-ratio: 1; border-radius: 16px; overflow: hidden; background: var(--surface2); display: flex; align-items: center; justify-content: center; font-size: 60px; margin: 0 auto; }
.foto-box img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Pack editor ---------- */
.pk-section { display: flex; flex-direction: column; gap: 6px; }
.picker { max-height: 240px; overflow: auto; border: 1px solid var(--border); border-radius: 12px; }
.prow { display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.prow:last-child { border-bottom: 0; }
.prow .pname { font-weight: 800; font-size: 14px; }
.pthumb { width: 44px; height: 44px; border-radius: 10px; overflow: hidden; background: var(--surface2); display: flex; align-items: center; justify-content: center; font-size: 22px; }
.pthumb img { width: 100%; height: 100%; object-fit: cover; }
.stepper { display: inline-flex; align-items: center; gap: 2px; background: var(--surface2); border-radius: 999px; }
.stepper button { border: 0; background: transparent; width: 34px; height: 34px; font-size: 20px; font-weight: 800; border-radius: 50%; }
.stepper span { min-width: 26px; text-align: center; font-weight: 800; }
.add-btn { border: 0; background: var(--primary); color: #fff; width: 34px; height: 34px; border-radius: 50%; font-size: 20px; font-weight: 800; }
.items-box { border: 1px solid var(--border); border-radius: 12px; }
.items-box .prow .meta { margin-top: 1px; }
.pk-totals { background: var(--surface2); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.tot-row { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.tot-row.main { align-items: baseline; font-weight: 800; margin-top: 4px; }
.tot-row.sub { color: var(--muted); font-size: 12px; font-weight: 700; flex-wrap: wrap; }
.tot-row .big { font-family: var(--font-brand); font-size: 28px; color: var(--accent-dark); font-weight: 700; }

/* ---------- Ajustes ---------- */
.aj-section { border-top: 1px solid var(--border); padding: 14px 0; display: flex; flex-direction: column; gap: 8px; }
.aj-section:first-of-type { border-top: 0; }
.aj-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.aj-row .btn { flex: 0 0 auto; }
.persona { display: flex; align-items: center; gap: 8px; background: var(--surface2); border-radius: 10px; padding: 6px 10px; font-weight: 700; font-size: 14px; }
.persona .muted { font-weight: 600; font-size: 12px; }
.persona .mini { background: #fff; padding: 6px 10px; }
.status-box { background: var(--surface2); border-radius: 12px; padding: 10px 12px; font-size: 14px; font-weight: 700; }
.status-box.ok { background: #E6F6EC; color: #1E6B3A; }
.status-box.err { background: #FDECEC; color: var(--danger); }

/* ---------- Toast / PIN ---------- */
#toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: var(--text); color: #FFF7EC; padding: 10px 16px; border-radius: 999px; font-weight: 700; opacity: 0; pointer-events: none; transition: .2s; z-index: 100; max-width: 90vw; text-align: center; font-size: 14px; }
#toast.show { opacity: 1; transform: translateX(-50%); }
@media (min-width: 768px) { #toast { bottom: 30px; } }

#pin-gate { position: fixed; inset: 0; background: var(--bg); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 20px; }
.pin-box { background: var(--surface); border-radius: 22px; border: 1px solid var(--border); padding: 28px; max-width: 360px; width: 100%; text-align: center; box-shadow: var(--shadow); }
.pin-box input { font-size: 28px; text-align: center; letter-spacing: 8px; border: 1px solid var(--border); border-radius: 14px; padding: 10px; width: 100%; margin: 14px 0; outline: none; }
.pin-box input:focus { border-color: var(--primary); }
