/* La Casita Dulce · app de la dueña (celular primero). */
:root {
  --rosa: #FFC6D6; --nube: #FFECF2; --morado: #8642CC; --morado-2: #6E2FB0; --uva: #4A1B6D;
  --lila: #B06DDB; --lavanda: #F1BDF4; --caramelo: #FAD978; --caramelo-2: #F2C24B; --frambuesa: #C2366B;
  --menta: #2E9D6E; --blanco: #FFFFFF; --texto: #3B1656; --texto-2: #6B5580; --borde: #F0D2E0;
  --nivel-3: #8642CC; --nivel-2: #B06DDB; --nivel-1: #E0A800; --nivel-0: #C2366B;
  --sombra: 0 6px 22px rgba(134, 66, 204, .12);
  --radio: 20px;
  --titulo: 'Fredoka', system-ui, sans-serif;
  --cuerpo: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --tabs-h: 66px;
  color-scheme: light;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body.ca {
  margin: 0; min-height: 100vh; font: 400 16px/1.5 var(--cuerpo); color: var(--texto);
  background: var(--nube) radial-gradient(rgba(176, 109, 219, .2) 1.2px, transparent 1.6px) 0 0 / 22px 22px;
  -webkit-tap-highlight-color: transparent;
}
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--titulo); color: var(--uva); line-height: 1.15; margin: 0; font-weight: 700; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0; }
:focus-visible { outline: 3px solid var(--morado); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--texto-2); }
.small { font-size: .88rem; }
.nowrap { white-space: nowrap; }

/* Estructura */
.ca-app { max-width: 760px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px); }
.ca-top {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top)); background: rgba(255, 236, 242, .94); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--borde);
}
.ca-top__brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--uva); font: 700 1.1rem/1 var(--titulo); margin-right: auto; }
.ca-top__brand img { width: 40px; height: 40px; }
.ca-top__gear { color: var(--uva); width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; }
.ca-top__gear:hover, .ca-top__gear[aria-current] { background: var(--blanco); }
.ca-net { background: var(--caramelo); color: var(--uva); font-weight: 800; font-size: .8rem; padding: 4px 10px; border-radius: 999px; }
.ca-main { padding: 16px; outline: none; }
.ca-loading { padding: 60px 0; text-align: center; color: var(--texto-2); }

.ca-tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex; justify-content: center;
  background: var(--blanco); border-top: 1px solid var(--borde); padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -6px 20px rgba(74, 27, 109, .08);
}
.ca-tabs a {
  flex: 1; max-width: 152px; height: var(--tabs-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--texto-2); font-weight: 800; font-size: .74rem; position: relative;
}
.ca-tabs svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ca-tabs a[aria-current="page"] { color: var(--morado); }
.ca-tabs a[aria-current="page"]::before { content: ''; position: absolute; top: 0; left: 28%; right: 28%; height: 4px; border-radius: 0 0 6px 6px; background: var(--morado); }
.ca-tabs a[aria-current="page"] svg { fill: var(--lavanda); }

/* Botones */
.ca-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px; border-radius: 999px;
  border: 2px solid transparent; font-weight: 800; font-size: 1rem; text-decoration: none; cursor: pointer; background: var(--blanco); color: var(--uva);
  transition: transform .12s ease, background-color .12s ease;
}
.ca-btn:active { transform: scale(.97); }
.ca-btn[disabled] { opacity: .55; cursor: not-allowed; }
.ca-btn--primary { background: var(--morado); color: #fff; box-shadow: 0 6px 16px rgba(134, 66, 204, .3); }
.ca-btn--primary:hover { background: var(--morado-2); }
.ca-btn--candy { background: var(--caramelo); color: var(--uva); border-color: var(--uva); box-shadow: 3px 3px 0 var(--uva); }
.ca-btn--line { border-color: var(--borde); }
.ca-btn--line:hover { border-color: var(--lila); }
.ca-btn--danger { color: var(--frambuesa); border-color: #F2C3D3; }
.ca-btn--block { width: 100%; }
.ca-btn--big { min-height: 60px; font-size: 1.15rem; border-radius: 22px; }
.ca-btn--sm { min-height: 38px; padding: 0 14px; font-size: .9rem; }
.ca-btn svg { width: 20px; height: 20px; }
.ca-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.ca-row > .ca-btn { flex: 1 1 140px; }
.ca-link { background: none; border: 0; padding: 0; color: var(--morado); font-weight: 800; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* Tarjetas y bloques */
.ca-card { background: var(--blanco); border-radius: var(--radio); padding: 16px; box-shadow: var(--sombra); border: 1px solid var(--borde); }
.ca-stack { display: grid; gap: 14px; }
.ca-stack--sm { display: grid; gap: 8px; }
.ca-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.ca-section-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 22px 0 10px; }
.ca-hello { display: flex; align-items: center; gap: 12px; }
.ca-hello img { width: 78px; height: 78px; flex: none; }
.ca-hello p { color: var(--texto-2); }
.ca-date { font-weight: 700; color: var(--morado); }

.ca-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ca-kpis--2 { grid-template-columns: repeat(2, 1fr); }
.ca-kpi { background: var(--blanco); border-radius: 18px; padding: 12px; border: 1px solid var(--borde); box-shadow: var(--sombra); min-width: 0; }
.ca-kpi b { display: block; font: 700 1.35rem/1.1 var(--titulo); color: var(--uva); overflow-wrap: anywhere; }
.ca-kpi span { font-size: .8rem; color: var(--texto-2); font-weight: 700; }
.ca-kpi--main { background: var(--morado); border-color: var(--morado); }
.ca-kpi--main b, .ca-kpi--main span { color: #fff; }
.ca-kpi--good b { color: var(--menta); }
.ca-kpi--bad b { color: var(--frambuesa); }

.ca-banner { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 18px; background: var(--blanco); border: 2px dashed var(--lila); text-decoration: none; color: var(--texto); }
.ca-banner--warn { border-color: var(--caramelo-2); background: #FFF8DC; }
.ca-banner strong { color: var(--uva); }
.ca-banner .ca-emoji { font-size: 1.6rem; flex: none; }

.ca-empty { text-align: center; padding: 18px 10px; display: grid; gap: 10px; justify-items: center; }
.ca-empty img { width: 170px; height: 170px; }
.ca-empty p { color: var(--texto-2); max-width: 26em; }

/* Listas */
.ca-list { display: grid; gap: 10px; }
.ca-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--blanco); border-radius: 18px; border: 1px solid var(--borde);
  box-shadow: var(--sombra); width: 100%; text-align: left; cursor: pointer;
}
.ca-item__main { flex: 1; min-width: 0; }
.ca-item__main strong { display: block; color: var(--uva); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ca-item__main span { font-size: .86rem; color: var(--texto-2); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ca-item__amount { font: 700 1.15rem var(--titulo); color: var(--morado); white-space: nowrap; }
.ca-item__icon { width: 42px; height: 42px; border-radius: 14px; background: var(--nube); display: grid; place-items: center; flex: none; font-size: 1.2rem; }
.ca-item.is-pending { border-style: dashed; border-color: var(--caramelo-2); }
.ca-thumb { width: 54px; height: 54px; border-radius: 14px; object-fit: cover; flex: none; background: var(--nube); }
.ca-thumb svg { width: 100%; height: 100%; padding: 8px; }

/* Chips y segmentos */
.ca-chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: none; }
.ca-chips::-webkit-scrollbar { display: none; }
.ca-chip { flex: none; border: 2px solid var(--borde); background: var(--blanco); color: var(--uva); border-radius: 999px; padding: 7px 14px; font-weight: 800; font-size: .9rem; cursor: pointer; white-space: nowrap; }
.ca-chip[aria-pressed="true"] { background: var(--uva); color: #fff; border-color: var(--uva); }
.ca-chip b { background: var(--caramelo); color: var(--uva); border-radius: 999px; padding: 0 7px; margin-left: 4px; font-size: .8rem; }
.ca-seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: var(--nube); border-radius: 14px; padding: 4px; }
.ca-seg button { border: 0; background: transparent; border-radius: 10px; padding: 8px 2px; font-weight: 800; font-size: .82rem; color: var(--texto-2); cursor: pointer; line-height: 1.15; }
.ca-seg button[aria-pressed="true"] { background: var(--blanco); color: var(--uva); box-shadow: 0 2px 8px rgba(74, 27, 109, .14); }
.ca-seg button[aria-pressed="true"][data-level="3"] { color: var(--nivel-3); }
.ca-seg button[aria-pressed="true"][data-level="2"] { color: var(--nivel-2); }
.ca-seg button[aria-pressed="true"][data-level="1"] { color: #9A6B00; background: #FFF4C7; }
.ca-seg button[aria-pressed="true"][data-level="0"] { color: #fff; background: var(--nivel-0); }

/* Inventario */
.ca-prod { background: var(--blanco); border-radius: 18px; border: 1px solid var(--borde); box-shadow: var(--sombra); padding: 12px; display: grid; gap: 10px; }
.ca-prod.is-low { border-color: var(--caramelo-2); }
.ca-prod.is-out { border-color: #EBA4BD; }
.ca-prod__top { display: flex; gap: 12px; align-items: center; background: none; border: 0; padding: 0; text-align: left; cursor: pointer; width: 100%; }
.ca-prod__info { flex: 1; min-width: 0; }
.ca-prod__info strong { display: block; color: var(--uva); font-size: 1.02rem; }
.ca-prod__info span { font-size: .85rem; color: var(--texto-2); }
.ca-level-ico { width: 34px; height: 40px; flex: none; }
.ca-search { position: relative; }
.ca-search input[type="search"] { padding-left: 44px; }
.ca-search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; stroke: var(--texto-2); fill: none; stroke-width: 2; }

/* Formularios */
.ca-field { display: grid; gap: 6px; }
.ca-field > span, .ca-label { font-weight: 800; font-size: .92rem; color: var(--uva); }
.ca-field small { color: var(--texto-2); font-size: .82rem; }
.ca-input, .ca-field input:not([type="checkbox"]):not([type="file"]), .ca-field select, .ca-field textarea, .ca-search input {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 14px; border: 2px solid var(--borde); background: var(--blanco); font-size: 1rem;
}
.ca-field textarea { min-height: 84px; resize: vertical; }
.ca-field input:focus, .ca-field select:focus, .ca-field textarea:focus, .ca-search input:focus, .ca-input:focus { border-color: var(--morado); outline: none; box-shadow: 0 0 0 3px rgba(134, 66, 204, .15); }
.ca-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ca-money { position: relative; }
.ca-money::before { content: '$'; position: absolute; left: 14px; top: 50%; transform: translateY(-50%); font-weight: 800; color: var(--texto-2); pointer-events: none; }
.ca-money input { padding-left: 28px !important; }
.ca-check { display: flex; align-items: center; gap: 10px; font-weight: 700; cursor: pointer; padding: 6px 0; }
.ca-check input { width: 24px; height: 24px; accent-color: var(--morado); flex: none; }
.ca-switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 700; cursor: pointer; padding: 6px 0; }
.ca-switch input { appearance: none; width: 50px; height: 30px; border-radius: 999px; background: #E5D5EC; position: relative; cursor: pointer; flex: none; transition: background .15s; }
.ca-switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .2); transition: transform .15s; }
.ca-switch input:checked { background: var(--morado); }
.ca-switch input:checked::after { transform: translateX(20px); }
.ca-photo { position: relative; width: 150px; height: 150px; margin: 0 auto; border-radius: 24px; overflow: hidden; background: var(--nube); border: 3px dashed var(--lila); display: grid; place-items: center; cursor: pointer; }
.ca-photo img { width: 100%; height: 100%; object-fit: cover; }
.ca-photo span { position: absolute; bottom: 8px; left: 8px; right: 8px; background: rgba(255, 255, 255, .92); border-radius: 999px; font-size: .78rem; font-weight: 800; text-align: center; padding: 4px; color: var(--uva); }
.ca-photo input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.ca-calc { background: var(--nube); border-radius: 16px; padding: 12px; display: grid; gap: 10px; }
.ca-calc__out { font-weight: 800; color: var(--uva); }
.ca-hint { background: #F7EEFF; border-radius: 14px; padding: 10px 12px; font-size: .88rem; color: var(--uva); }

/* Hoja inferior (modal) */
.ca-sheet-back { position: fixed; inset: 0; z-index: 60; background: rgba(46, 14, 70, .45); display: flex; align-items: flex-end; justify-content: center; animation: ca-fade .15s ease; }
.ca-sheet {
  width: 100%; max-width: 760px; max-height: 94vh; background: var(--nube); border-radius: 26px 26px 0 0; display: flex; flex-direction: column;
  animation: ca-up .2s ease; box-shadow: 0 -10px 40px rgba(46, 14, 70, .25); padding-bottom: env(safe-area-inset-bottom);
}
.ca-sheet--full { height: 94vh; }
.ca-sheet__head { display: flex; align-items: center; gap: 10px; padding: 14px 16px 10px; border-bottom: 1px solid var(--borde); }
.ca-sheet__head h2 { flex: 1; }
.ca-sheet__close { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--blanco); font-size: 1.4rem; line-height: 1; cursor: pointer; color: var(--uva); }
.ca-sheet__body { padding: 16px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 14px; overscroll-behavior: contain; }
.ca-sheet__body > * { flex: none; }
.ca-sheet__foot { padding: 12px 16px 14px; border-top: 1px solid var(--borde); background: var(--blanco); display: grid; gap: 10px; }
@keyframes ca-up { from { transform: translateY(40px); opacity: .4; } }
@keyframes ca-fade { from { opacity: 0; } }

/* Venta */
.ca-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.ca-tile { position: relative; background: var(--blanco); border: 2px solid var(--borde); border-radius: 16px; padding: 6px; display: grid; gap: 4px; text-align: center; cursor: pointer; }
.ca-tile:active { transform: scale(.97); }
.ca-tile.in-cart { border-color: var(--morado); background: #FBF5FF; }
.ca-tile__img { aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--nube); }
.ca-tile__img img, .ca-tile__img svg { width: 100%; height: 100%; object-fit: cover; }
.ca-tile__img svg { padding: 14%; }
.ca-tile strong { font-size: .82rem; line-height: 1.15; color: var(--uva); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.3em; }
.ca-tile em { font-style: normal; font-weight: 800; color: var(--morado); font-size: .9rem; }
.ca-tile__qty { position: absolute; top: -6px; right: -6px; min-width: 28px; height: 28px; border-radius: 999px; background: var(--morado); color: #fff; font-weight: 800; display: grid; place-items: center; padding: 0 6px; border: 2px solid #fff; }
.ca-tile--other { border-style: dashed; place-content: center; color: var(--morado); font-weight: 800; min-height: 120px; }
.ca-cart { display: grid; gap: 6px; max-height: 30vh; overflow-y: auto; }
.ca-cart-sum { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; border: 0; background: var(--nube); border-radius: 14px; padding: 8px 12px; font-weight: 800; color: var(--uva); cursor: pointer; }
.ca-cart-sum small { color: var(--morado); }
.ca-sheet__foot .ca-field input { min-height: 42px; }
.ca-cash { display: flex; align-items: center; gap: 10px; }
.ca-cash .ca-money { flex: 1; }
.ca-cash span { font-weight: 800; color: var(--uva); white-space: nowrap; }
.ca-line { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; }
.ca-line__name { min-width: 0; }
.ca-line__name strong { display: block; font-size: .92rem; color: var(--uva); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ca-line__price { border: 0; background: none; padding: 0; color: var(--texto-2); font-size: .82rem; text-decoration: underline dotted; cursor: pointer; }
.ca-line__price.is-zero { color: var(--frambuesa); font-weight: 800; }
.ca-step { display: flex; align-items: center; background: var(--nube); border-radius: 999px; }
.ca-step button { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--blanco); font-weight: 800; font-size: 1.1rem; color: var(--uva); cursor: pointer; }
.ca-step span { min-width: 30px; text-align: center; font-weight: 800; }
.ca-line__sub { font-weight: 800; min-width: 64px; text-align: right; }
.ca-total { display: flex; justify-content: space-between; align-items: baseline; }
.ca-total b { font: 700 1.8rem var(--titulo); color: var(--uva); }
.ca-change { font-weight: 800; color: var(--menta); }

/* Gráficas */
.ca-chart { width: 100%; height: auto; display: block; }
.ca-bars { display: grid; gap: 8px; }
.ca-bar { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; gap: 8px; align-items: center; font-size: .9rem; }
.ca-bar__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.ca-bar__track { height: 12px; background: var(--nube); border-radius: 99px; overflow: hidden; }
.ca-bar__fill { height: 100%; background: linear-gradient(90deg, var(--lila), var(--morado)); border-radius: 99px; }
.ca-bar__val { font-weight: 800; color: var(--uva); }
.ca-legend { display: flex; gap: 14px; font-size: .82rem; color: var(--texto-2); font-weight: 700; }
.ca-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: 4px; vertical-align: -1px; }

/* Consejos */
.ca-tips { display: grid; gap: 10px; }
.ca-tip { display: flex; gap: 12px; padding: 14px; background: var(--blanco); border-radius: 18px; border: 1px solid var(--borde); }
.ca-tip__n { width: 34px; height: 34px; border-radius: 50%; background: var(--caramelo); border: 2px solid var(--uva); color: var(--uva); display: grid; place-items: center; font: 700 1rem var(--titulo); flex: none; }
.ca-tip strong { color: var(--uva); display: block; }
.ca-tip p { font-size: .92rem; color: var(--texto-2); }
.ca-tip a, .ca-tip button { margin-top: 4px; }

/* Avisos */
.ca-toast { position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 14px); transform: translate(-50%, 20px); z-index: 90; background: var(--uva); color: #fff; padding: 12px 18px; border-radius: 16px; font-weight: 800; box-shadow: 0 10px 30px rgba(46, 14, 70, .3); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); text-align: center; }
.ca-toast.show { opacity: 1; transform: translate(-50%, 0); }
.ca-toast.bad { background: var(--frambuesa); }
.ca-toast.good { background: var(--menta); }

/* Entrada */
.ca-login { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 16px; padding: 24px 16px; }
.ca-login__card { width: min(400px, 100%); background: var(--blanco); border-radius: 28px; padding: 26px 22px; box-shadow: var(--sombra); text-align: center; display: grid; gap: 12px; justify-items: center; }
.ca-login__card form { width: 100%; text-align: left; display: grid; gap: 4px; }
.ca-login__card form p { margin: 0 0 8px; }
.ca-login__card label { font-weight: 800; color: var(--uva); display: block; margin-bottom: 4px; }
.ca-login__card input[type="text"], .ca-login__card input[type="password"] { width: 100%; min-height: 50px; border-radius: 14px; border: 2px solid var(--borde); padding: 10px 14px; font-size: 1rem; }
.ca-login__card input[type="submit"] { width: 100%; min-height: 54px; border: 0; border-radius: 999px; background: var(--morado); color: #fff; font-weight: 800; font-size: 1.1rem; cursor: pointer; }
.ca-login__card .login-remember label { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.ca-login__lost, .ca-login__home { color: var(--morado); font-weight: 700; }

@media (min-width: 640px) {
  .ca-main { padding: 22px; }
  .ca-sheet { border-radius: 26px; margin-bottom: 20px; max-height: 90vh; }
  .ca-sheet-back { align-items: center; }
  .ca-sheet--full { height: 90vh; }
}
@media (max-width: 380px) {
  .ca-kpi b { font-size: 1.15rem; }
  .ca-seg button { font-size: .76rem; }
  .ca-tiles { grid-template-columns: repeat(3, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  .ca-sheet, .ca-sheet-back { animation: none; }
}

/* Nada debe ensanchar la pantalla: las columnas pueden encogerse y el texto largo se corta con "…". */
.ca-list, .ca-stack, .ca-stack--sm, .ca-tips, .ca-bars, .ca-sheet__foot { grid-template-columns: minmax(0, 1fr); }
.ca-item, .ca-prod, .ca-card, .ca-banner, .ca-line__name, .ca-tip > div { min-width: 0; }
.ca-app, .ca-sheet { overflow-x: clip; }
