:root {
  --bg: #f5ead8;
  --bg-2: #ebddc5;
  --bg-2-hover: #e0cdb0;
  --card: #fbf5ec;
  --accent: #c67139;
  --accent-dark: #8f4a1f;
  --accent-soft: #e08a52;
  --dark: #201e1d;
  --dark-2: #3a3633;
  --muted: #6b625a;
  --muted-light: #c9bca6;
  --green: #7a8a5e;
  --up: #4f6a34;
  --down: #b3412e;
  --amber: #b9821c;
  --radius-lg: 28px;
  --radius: 24px;
  --shadow: 0 1px 2px rgba(80, 50, 20, .08);
  --font-display: Caprasimo, Georgia, serif;
  --font: Figtree, system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--dark);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
@media (min-width: 520px) { body { background: #e4d6bd; } }
button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 2px; }
[hidden] { display: none !important; }

.app {
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: flex;
  flex-direction: column;
}

/* Header */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 8px 16px 6px; }
.top-row { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 44px; height: 44px; flex: none; border: none; border-radius: 999px;
  background: var(--bg-2); color: var(--dark); font-size: 20px;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg-2-hover); }
.top-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.1; }
.brand { font: 400 22px var(--font-display); color: var(--accent-dark); }
.title { font: 400 20px var(--font-display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kicker { font-size: 11px; font-weight: 700; letter-spacing: .08em; color: var(--muted); text-transform: uppercase; }
.status { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 6px 2px 0; font-size: 12px; color: var(--muted); min-height: 22px; }
.status i { margin-right: 4px; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-weight: 700; font-size: 12px; }
.badge-offline { background: var(--dark); color: var(--bg); }
.badge-pending { background: var(--bg-2); color: var(--accent-dark); }
.spinning { animation: spin 1s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Period controls */
.controls { padding: 0 16px; }
.tabs { display: flex; background: var(--bg-2); border-radius: 999px; padding: 4px; gap: 2px; }
.tab {
  flex: 1; height: 36px; border: none; border-radius: 999px; background: transparent;
  font-size: 13px; font-weight: 800; letter-spacing: .06em; color: var(--muted); transition: background .2s;
}
.tab.active { background: var(--accent); color: #fff; }
.range { display: flex; align-items: center; justify-content: space-between; padding: 12px 4px 6px; }
.arrow { width: 36px; height: 36px; border: none; border-radius: 999px; background: transparent; font-size: 18px; color: var(--muted); }
.arrow:hover:not(:disabled) { background: var(--bg-2); }
.arrow:disabled { opacity: .3; }
.range-title {
  flex: 1; min-height: 44px; border: none; border-radius: 999px; background: transparent; white-space: nowrap;
  font-weight: 700; font-size: 15px; color: var(--accent-dark); display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.range-title:hover { background: var(--bg-2); }
.range-title i { font-size: 16px; }
.picker { display: grid; grid-template-columns: repeat(var(--cols, 7), minmax(0, 1fr)); gap: 4px; padding-bottom: 12px; }
.pick {
  border: none; border-radius: 16px; padding: 6px 0; background: transparent; color: var(--dark);
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 44px; justify-content: center;
}
.pick:hover:not(:disabled) { outline: 2px solid var(--bg-2-hover); }
.pick.selected { background: var(--dark); color: var(--bg); }
.pick:disabled { opacity: .35; }
.pick-top { font-size: 10px; font-weight: 700; letter-spacing: .06em; opacity: .8; }
.pick-main { font-size: 15px; font-weight: 800; }

/* Content */
.view { flex: 1; padding: 0 16px 40px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.section { font: 400 20px var(--font-display); margin: 6px 4px 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chip {
  height: 36px; border: none; border-radius: 999px; background: var(--bg-2); padding: 0 14px;
  font-size: 12px; font-weight: 700; display: inline-flex; gap: 6px; align-items: center;
}
.chip:hover { background: var(--bg-2-hover); }
.muted { color: var(--muted); }
.note { font-size: 12px; color: var(--muted); margin: 0 4px; }

.hero { background: var(--dark); color: var(--bg); border-radius: var(--radius-lg); padding: 20px 20px 12px; display: flex; flex-direction: column; gap: 4px; }
.hero.light { background: var(--card); color: var(--dark); }
.hero-kicker { font-size: 11px; font-weight: 800; letter-spacing: .12em; color: #e0b48f; }
.hero.light .hero-kicker { color: var(--accent-dark); }
.hero-total { font: 400 44px/1.05 var(--font-display); overflow-wrap: anywhere; }
.hero-row { display: flex; gap: 16px; align-items: flex-start; margin-top: 6px; }
.hero-col { display: flex; flex-direction: column; }
.hero-col.end { flex: 1; align-items: flex-end; text-align: right; }
.hero-col.end .pill { align-self: flex-end; }
.hero-strong { font-size: 17px; font-weight: 800; }
.hero-sub { font-size: 12px; color: var(--muted-light); margin-top: 4px; }
.hero.light .hero-sub { color: var(--muted); }
.pill { align-self: flex-start; font-size: 14px; font-weight: 800; background: var(--bg); padding: 3px 10px; border-radius: 999px; display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; }
.hero.light .pill { background: var(--bg-2); }
.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--muted); }
.chart { width: 100%; height: auto; margin-top: 8px; overflow: visible; display: block; }
.chart-label { font-size: 9px; fill: var(--muted-light); font-family: var(--font); }
.hero.light .chart-label { fill: var(--muted); }

.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.kpi { background: var(--card); border-radius: 20px; padding: 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kpi i { font-size: 18px; color: var(--accent); }
.kpi-label { font-size: 11px; color: var(--muted); }
.kpi-val { font-size: 18px; font-weight: 800; overflow-wrap: anywhere; }
.kpi-sub { font-size: 11px; font-weight: 700; }

.card {
  width: 100%; text-align: left; border: none; background: var(--card); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 10px; color: var(--dark); box-shadow: var(--shadow);
}
button.card:hover { background: #fff; }
button.card:active { transform: scale(.99); }
.card-row { display: flex; gap: 10px; align-items: flex-start; width: 100%; }
.card-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.card-name { font-size: 13px; font-weight: 800; letter-spacing: .02em; }
.card-sub { font-size: 12px; color: var(--muted); }
.card-end { display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.card-total { font: 400 22px var(--font-display); }
.delta { font-size: 13px; font-weight: 800; }
.bar { height: 6px; border-radius: 999px; background: var(--bg-2); width: 100%; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.bar.green > span { background: var(--green); }
.card-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; width: 100%; font-size: 12px; color: var(--muted); }
.card-grid span { display: flex; gap: 4px; align-items: center; min-width: 0; }
.card-grid i { color: var(--accent); }

.list { background: var(--card); border-radius: var(--radius); padding: 8px 16px; display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; font-size: 14px; color: var(--muted); }
.list-row + .list-row { border-top: 1px solid var(--bg-2); }
.list-row .val { font-weight: 700; color: var(--dark); text-align: right; }
.list-row .lbl { flex: 1; min-width: 0; }
.list-row.strong { font-size: 15px; font-weight: 700; color: var(--dark); }
.dot { width: 8px; height: 8px; border-radius: 999px; background: var(--accent); flex: none; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--card); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.tile-icon { width: 40px; height: 40px; border-radius: 999px; background: #f3dcc9; color: var(--accent-dark); display: flex; align-items: center; justify-content: center; font-size: 18px; }
.tile-label { font-size: 12px; color: var(--muted); }
.tile-val { font-size: 19px; font-weight: 800; }

.bars-card { background: var(--card); border-radius: var(--radius); padding: 16px; }
.bars-card .bar-rect { fill: var(--accent); }
.bars-label { font-size: 9px; fill: var(--muted); font-family: var(--font); }

.rank { background: var(--card); border-radius: 20px; padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.rank-n { font-size: 11px; font-weight: 800; color: var(--accent-dark); width: 22px; flex: none; }
.rank-name { font-size: 13px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-amt { font-size: 16px; font-weight: 800; color: var(--accent-dark); }

.cov { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 800; white-space: nowrap; }
.cov.red { background: #f4d6cf; color: var(--down); }
.cov.amber { background: #f6e4bf; color: #8a5d0c; }
.cov.green { background: #e3e8d9; color: var(--up); }
.cov.none { background: var(--bg-2); color: var(--muted); }

.progress { position: relative; height: 10px; border-radius: 999px; background: var(--bg-2); overflow: visible; }
.progress > .fill { display: block; height: 100%; border-radius: 999px; background: var(--accent); max-width: 100%; }
.progress.green > .fill { background: var(--green); }
.progress > .marker { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--dark); border-radius: 2px; }
.progress-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; margin-bottom: 6px; }
.progress-head b { font-weight: 800; }

.banner { display: flex; gap: 10px; align-items: flex-start; background: #f6e4bf; color: #6b4a0c; border-radius: 18px; padding: 12px 14px; font-size: 13px; font-weight: 600; }
.banner i { font-size: 18px; flex: none; }
.banner.error { background: #f4d6cf; color: var(--down); }

.sub-rows { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); border-top: 2px dashed var(--bg-2); padding-top: 8px; }
.sub-rows div { display: flex; justify-content: space-between; gap: 8px; }
.sub-rows b { color: var(--dark); }

/* CEDIS */
.subsection { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 800; margin: 4px 4px 0; color: var(--accent-dark); }
.info-card { flex-direction: row; align-items: flex-start; gap: 12px; }
.info-icon, .flow-icon { font-size: 20px; color: var(--accent); flex: none; }
.empty.small { padding: 12px 0; font-size: 13px; }

/* Buttons & forms */
.btn {
  min-height: 48px; border: none; border-radius: 999px; padding: 0 18px; font-size: 14px; font-weight: 800;
  letter-spacing: .03em; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-dark { background: var(--dark); color: var(--bg); }
.btn-dark:hover { background: var(--accent); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost { background: var(--bg-2); color: var(--dark); }
.btn:disabled { opacity: .6; }
.btn-block { width: 100%; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 700; color: var(--muted); }
.input, .select {
  min-height: 48px; border: 2px solid var(--bg-2); border-radius: 16px; background: var(--card);
  padding: 0 14px; font-size: 16px; color: var(--dark); width: 100%;
}
.input:focus, .select:focus { border-color: var(--accent); outline: none; }
.input.invalid { border-color: var(--down); }
.goal-row { display: flex; align-items: center; gap: 10px; }
.goal-row .lbl { flex: 1; min-width: 0; font-size: 13px; font-weight: 800; }
.goal-row .input { width: 120px; flex: none; text-align: right; }
.form-error { color: var(--down); font-size: 13px; font-weight: 700; min-height: 18px; }

.login { min-height: 80vh; display: flex; flex-direction: column; justify-content: center; gap: 18px; padding: 24px 8px; }
.login-brand { font: 400 34px var(--font-display); color: var(--accent-dark); text-align: center; }
.login-sub { text-align: center; color: var(--muted); font-size: 13px; font-weight: 700; letter-spacing: .08em; }
.login form { background: var(--card); border-radius: var(--radius-lg); padding: 20px; display: flex; flex-direction: column; gap: 14px; }

/* Drawer */
.drawer-wrap { position: fixed; inset: 0; z-index: 20; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(32, 30, 29, .45); border: none; width: 100%; }
.drawer {
  position: absolute; top: 0; bottom: 0; left: 0; width: min(300px, 85vw); background: var(--dark); color: var(--bg);
  border-radius: 0 36px 36px 0; padding: calc(40px + env(safe-area-inset-top)) 20px calc(28px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 22px; overflow-y: auto;
}
.drawer-brand { font: 400 26px var(--font-display); color: var(--accent-soft); }
.drawer-email { font-size: 12px; color: var(--muted-light); word-break: break-all; }
.drawer-menu { display: flex; flex-direction: column; gap: 4px; }
.drawer-item {
  border: none; border-radius: 999px; background: transparent; color: var(--bg); min-height: 48px; padding: 0 16px;
  font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 12px; text-align: left;
}
.drawer-item:hover { background: var(--dark-2); }
.drawer-item.active { background: var(--accent); }
.drawer-item.logout { color: #e0b48f; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 30;
  max-width: min(440px, calc(100vw - 32px)); background: var(--dark); color: var(--bg); border-radius: 999px;
  padding: 14px 20px; font-size: 14px; font-weight: 700; text-align: center; box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}

.loading, .empty { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 48px 0; color: var(--muted); font-weight: 700; }
.spinner { width: 20px; height: 20px; border-radius: 999px; border: 3px solid var(--bg-2); border-top-color: var(--accent); animation: spin .9s linear infinite; }
.error-card { background: var(--card); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }

/* Big period selector (S14) */
body.sheet-open { overflow: hidden; }
.sheet-wrap { position: fixed; inset: 0; z-index: 25; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; border: none; width: 100%; background: rgba(32, 30, 29, .45); }
.sheet {
  position: relative; width: 100%; max-width: 480px; max-height: 88vh; max-height: 88dvh; overflow-y: auto;
  background: var(--bg); border-radius: 28px 28px 0 0; padding: 14px 16px calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px; box-shadow: 0 -10px 30px rgba(0, 0, 0, .2);
  animation: sheet-up .2s ease-out;
}
@keyframes sheet-up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sheet-heading { font: 400 22px var(--font-display); margin: 0 4px; color: var(--accent-dark); }
.sheet-jump { display: grid; grid-template-columns: 3fr 2fr; gap: 8px; }
.sheet-nav { display: flex; align-items: center; justify-content: space-between; }
.sheet-nav .arrow { width: 44px; height: 44px; font-size: 20px; }
.sheet-nav-title { flex: 1; text-align: center; font-weight: 800; font-size: 16px; }
.sheet-grid { display: grid; gap: 6px; }
.sheet-grid.cal { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.sheet-grid.weeks { grid-template-columns: 1fr; }
.sheet-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cal-head { text-align: center; font-size: 12px; font-weight: 800; color: var(--muted); padding: 4px 0; }
.sheet-cell {
  min-height: 48px; border: none; border-radius: 16px; background: var(--card); color: var(--dark);
  font-size: 16px; font-weight: 800; display: flex; align-items: center; justify-content: center; padding: 0 6px;
}
.sheet-grid.weeks .sheet-cell { justify-content: flex-start; padding: 0 16px; }
.sheet-cell:hover:not(:disabled) { background: var(--bg-2-hover); }
.sheet-cell.out { background: transparent; color: var(--muted); font-weight: 600; }
.sheet-cell.today { box-shadow: inset 0 0 0 2px var(--accent); }
.sheet-cell.selected { background: var(--dark); color: var(--bg); }
.sheet-cell:disabled { opacity: .3; }

/* Collapsible sales summary (S15) */
.summary { background: var(--card); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; }
.summary-head {
  width: 100%; min-height: 64px; border: none; background: transparent; text-align: left; padding: 12px 16px;
  display: flex; align-items: center; gap: 10px; color: var(--dark);
}
.summary-key { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.summary-total { font: 400 24px var(--font-display); overflow-wrap: anywhere; }
.summary-meta { font-size: 13px; font-weight: 700; color: var(--muted); }
.summary-toggle { flex: none; display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 800; color: var(--accent-dark); background: var(--bg-2); border-radius: 999px; padding: 6px 12px; }
.summary-body { display: flex; flex-direction: column; padding: 0 16px 10px; border-top: 1px solid var(--bg-2); }
.summary-body .list-row.compare { color: var(--muted); }
.summary-body .list-row .val span { margin-left: 4px; font-size: 12px; }
.summary-note { margin: 4px 0 0; }

/* Chart flags (S17) */
.chart .hit { fill: transparent; pointer-events: all; cursor: pointer; outline: none; }
.chart .hit:focus-visible, .chart .hit.active { fill: rgba(198, 113, 57, .12); }
.chart .flag { pointer-events: none; }
.chart .flag-box { fill: var(--dark); }
.chart .flag-text { fill: var(--bg); font: 700 11px var(--font); }
.chart-dark .flag-box { fill: var(--bg); }
.chart-dark .flag-text { fill: var(--dark); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* S16 Paquetes + S18 BI reports */
.chip-group { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.chip.active { background: var(--dark); color: var(--bg); }
.kind-badge { display: inline-block; vertical-align: middle; margin-left: 4px; padding: 1px 8px; border-radius: 999px; font-size: 10px; font-weight: 800; background: var(--bg-2); color: var(--accent-dark); }
.kind-badge.kit { color: var(--up); }
.share-line { display: flex; align-items: center; gap: 10px; }
.share-line .card-sub { flex: none; min-width: 48px; text-align: right; }
.card-sub.up i, .card-sub.down i, .card-sub.flat i { margin-right: 2px; }
.share-card { gap: 12px; }
.share-card .chip { align-self: flex-start; }
.share-row { display: flex; flex-direction: column; }
.share-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.pace { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 13px; color: var(--accent-dark); }
.pace-main { font-weight: 800; }
.pace-sub { color: var(--muted); font-weight: 600; }
.pace.big { margin-top: 6px; font-size: 16px; }
.pace.big .pace-main { font-size: 20px; }
.pace.done { color: var(--up); }

/* S19 Pedidos programados */
.status-badge { display: inline-block; vertical-align: middle; margin-left: 4px; padding: 1px 8px; border-radius: 999px; font-size: 10px; font-weight: 800; letter-spacing: .02em; white-space: nowrap; }
.status-badge.amber { background: #f6e4bf; color: #8a5d0c; }
.status-badge.green { background: #e3e8d9; color: var(--up); }
.status-badge.red { background: #f4d6cf; color: var(--down); }
.status-badge.gray { background: var(--bg-2); color: var(--muted); }
.order-badges { display: flex; gap: 4px; flex-wrap: wrap; }
.order-badges .status-badge { margin-left: 0; font-size: 12px; padding: 3px 10px; }
.banner.overdue { background: #f4d6cf; color: var(--down); }
.day-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 6px 4px 0; flex-wrap: wrap; }
.day-name { font: 400 18px var(--font-display); text-transform: capitalize; }
.order-row { gap: 6px; }
.order-row.overdue { box-shadow: inset 4px 0 0 var(--down); }
.order-row .card-sub i, .card .card-sub i { font-size: 12px; vertical-align: -1px; }
.order-summary { color: var(--dark); font-weight: 600; }
.origin { color: var(--accent-dark); font-weight: 700; }
.item-toggle { all: unset; display: block; width: 100%; cursor: pointer; border-radius: 12px; }
.item-toggle:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 2px; }
.item-qty { font-size: 13px; font-weight: 800; color: var(--accent-dark); min-width: 28px; flex: none; }
.components { border-top: 1px solid var(--bg-2); padding-left: 38px; }
.note-card { gap: 4px; font-size: 14px; }
