/* =====================================================================
   Maison Sucrée · estilo editorial cálido
   Paleta: cacao profundo, crema marfil, caramelo, dorado cobrizo
   ===================================================================== */
:root {
  --cacao-950: #1f100a;
  --cacao-900: #2b1810;
  --cacao-800: #3b2217;
  --cacao-700: #4f2f20;
  --cacao-500: #7a5440;
  --ivory: #fbf6ec;
  --cream: #f3e9d6;
  --cream-deep: #e8d9bd;
  --caramel: #c8803a;
  --caramel-light: #e3a566;
  --gold: #b8863b;
  --copper: #a9582d;
  --ok: #2f7d4f;
  --warn: #b7791f;
  --danger: #a73a2c;
  --info: #2c6a8f;
  --radius: 14px;
  --shadow-1: 0 1px 2px rgba(43,24,16,.08), 0 2px 6px rgba(43,24,16,.06);
  --shadow-2: 0 2px 4px rgba(43,24,16,.06), 0 8px 16px rgba(43,24,16,.08), 0 18px 36px rgba(43,24,16,.08);
  --font-body: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--cacao-900);
  background:
    radial-gradient(1200px 500px at 85% -10%, rgba(200,128,58,.14), transparent 60%),
    var(--ivory);
  line-height: 1.5;
  display: grid;
  grid-template-columns: 270px 1fr;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: linear-gradient(180deg, var(--cacao-900), var(--cacao-950));
  color: var(--cream);
  padding: 26px 18px;
  display: flex; flex-direction: column; gap: 22px;
  box-shadow: 4px 0 24px rgba(31,16,10,.25);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand__mark {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; color: var(--cacao-950);
  background: linear-gradient(135deg, var(--caramel-light), var(--gold));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.4), 0 4px 10px rgba(0,0,0,.3);
}
.brand strong { display: block; font-family: var(--font-display); font-size: 1.2rem; letter-spacing: .2px; }
.brand small { color: var(--caramel-light); font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; }

nav { display: flex; flex-direction: column; gap: 18px; }
.nav-group h4 {
  margin: 0 0 6px 10px; font-size: .68rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--caramel-light); font-weight: 700; opacity: .85;
}
.nav-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: transparent; border: 0; color: var(--cream); font: inherit; font-size: .92rem;
  padding: 9px 12px; border-radius: 10px; cursor: pointer; text-align: left;
  transition: background .15s ease, transform .15s ease;
}
.nav-btn::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--cacao-500); flex: none; }
.nav-btn:hover { background: rgba(255,255,255,.07); transform: translateX(2px); }
.nav-btn.is-active { background: linear-gradient(90deg, rgba(200,128,58,.32), rgba(200,128,58,.08)); color: #fff; }
.nav-btn.is-active::before { background: var(--caramel-light); box-shadow: 0 0 0 3px rgba(227,165,102,.25); }
.sidebar__foot { margin: auto 0 0; font-size: .72rem; color: var(--cacao-500); letter-spacing: .1em; text-transform: uppercase; }

.menu-toggle {
  display: none; position: fixed; top: 12px; left: 12px; z-index: 30;
  background: var(--cacao-900); color: var(--cream); border: 0; border-radius: 10px;
  width: 42px; height: 42px; font-size: 1.2rem; box-shadow: var(--shadow-2); cursor: pointer;
}

/* ---------- Main ---------- */
.main { padding: 30px clamp(18px, 3vw, 44px) 60px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.eyebrow { margin: 0 0 2px; font-size: .72rem; letter-spacing: .16em; text-transform: uppercase; color: var(--copper); font-weight: 700; }
h1, h2, h3 { font-family: var(--font-display); margin: 0; color: var(--cacao-900); }
h1 { font-size: clamp(1.6rem, 3vw, 2.2rem); }
h2 { font-size: 1.6rem; }
h3 { font-size: 1.1rem; margin-bottom: 14px; }
.muted { color: var(--cacao-500); margin: 4px 0 0; }

.rules { display: flex; gap: 10px; flex-wrap: wrap; }
.rule-pill {
  padding: 8px 14px; border-radius: 999px; font-size: .8rem; font-weight: 700;
  background: var(--cacao-900); color: var(--caramel-light); border: 1px solid var(--cacao-700);
  box-shadow: var(--shadow-1);
}
.rule-pill--today { background: linear-gradient(135deg, var(--caramel), var(--copper)); color: #fff; border-color: transparent; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 26px; }
.kpi {
  border-radius: var(--radius); padding: 18px 20px; color: #fff; display: flex; flex-direction: column; gap: 2px;
  box-shadow: var(--shadow-2); position: relative; overflow: hidden;
}
.kpi::after { content: ''; position: absolute; right: -30px; top: -30px; width: 110px; height: 110px; border-radius: 50%; background: rgba(255,255,255,.1); }
.kpi span { font-size: .78rem; letter-spacing: .1em; text-transform: uppercase; opacity: .9; }
.kpi strong { font-family: var(--font-display); font-size: 1.9rem; line-height: 1.2; }
.kpi small { opacity: .85; font-size: .8rem; }
.kpi--cacao   { background: linear-gradient(135deg, var(--cacao-700), var(--cacao-950)); }
.kpi--caramel { background: linear-gradient(135deg, var(--caramel-light), var(--copper)); }
.kpi--gold    { background: linear-gradient(135deg, #d4a24f, #8c6422); }
.kpi--copper  { background: linear-gradient(135deg, #b8643a, #6e2f17); }

/* ---------- Cards, forms ---------- */
.content { display: flex; flex-direction: column; gap: 22px; }
.view-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card {
  background: #fffdf8; border: 1px solid var(--cream-deep); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow-1);
}
.card--dark { background: var(--cacao-950); color: var(--cream); border-color: var(--cacao-700); }
.card--dark h3 { color: var(--caramel-light); }
.count { font-family: var(--font-body); font-size: .75rem; background: var(--cream); color: var(--cacao-700); padding: 2px 9px; border-radius: 999px; vertical-align: middle; margin-left: 6px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px 18px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: .85rem; }
.field > span { font-weight: 700; color: var(--cacao-700); letter-spacing: .02em; }
.field--wide, .form-actions, .summary.field--wide { grid-column: 1 / -1; }
input, select, textarea {
  font: inherit; color: var(--cacao-900); background: var(--ivory);
  border: 1px solid var(--cream-deep); border-radius: 10px; padding: 10px 12px; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--caramel); box-shadow: 0 0 0 3px rgba(200,128,58,.22); }

.btn {
  font: inherit; font-weight: 700; border-radius: 10px; padding: 10px 18px; border: 1px solid transparent;
  cursor: pointer; transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn--primary { background: linear-gradient(135deg, var(--caramel), var(--copper)); color: #fff; box-shadow: 0 4px 12px rgba(169,88,45,.35); }
.btn--commit { background: linear-gradient(135deg, #3f9a63, #2f7d4f); color: #fff; box-shadow: 0 4px 12px rgba(47,125,79,.35); }
.btn--rollback { background: linear-gradient(135deg, #c1503f, #8f2a1d); color: #fff; box-shadow: 0 4px 12px rgba(167,58,44,.35); }
.btn--ghost { background: transparent; border-color: var(--cream-deep); color: var(--cacao-700); }
.btn--sm { padding: 5px 10px; font-size: .78rem; }

.summary {
  background: linear-gradient(135deg, var(--cream), var(--ivory)); border: 1px dashed var(--gold);
  border-radius: 12px; padding: 14px 16px; display: grid; gap: 6px; font-size: .9rem;
}
.summary .row { display: flex; justify-content: space-between; gap: 12px; }
.summary .row strong { font-family: var(--font-display); font-size: 1.05rem; }
.summary .row--min strong { color: var(--copper); }
.summary .warn { color: var(--danger); font-weight: 700; }
.summary .good { color: var(--ok); font-weight: 700; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--cream-deep); }
table.data { width: 100%; border-collapse: collapse; font-size: .88rem; min-width: 560px; }
table.data th {
  text-align: left; background: var(--cacao-900); color: var(--cream); font-size: .72rem;
  letter-spacing: .1em; text-transform: uppercase; padding: 11px 12px; white-space: nowrap;
}
table.data td { padding: 10px 12px; border-top: 1px solid var(--cream); vertical-align: top; }
table.data tbody tr:nth-child(even) { background: #fbf4e6; }
table.data tbody tr:hover { background: #f6e9d0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; }
tfoot td { font-weight: 700; background: var(--cream); }
.empty, .loading { color: var(--cacao-500); text-align: center; padding: 24px; }

progress { width: 120px; height: 10px; accent-color: var(--caramel); }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .74rem; font-weight: 700; background: var(--cream); color: var(--cacao-700); border: 1px solid var(--cream-deep); white-space: nowrap; }
.badge--pendiente, .badge--programada { background: #fdf0d3; color: #8a5a0b; border-color: #f0d79b; }
.badge--confirmada, .badge--confirmado, .badge--encamino, .badge--plata { background: #dcecf5; color: #1f5a7d; border-color: #b4d3e4; }
.badge--pagada, .badge--pagado, .badge--entregada, .badge--entregado, .badge--true { background: #dcf1e3; color: #226640; border-color: #b0dcc0; }
.badge--cancelada, .badge--cancelado, .badge--anulado, .badge--noentregada, .badge--false { background: #f7dcd7; color: #8f2a1d; border-color: #e8b5ac; }
.badge--oro { background: #f6e3b0; color: #7a5410; border-color: #e5c97a; }
.badge--bronce { background: #f0dccb; color: #7a4423; border-color: #dfbd9f; }

/* ---------- Consola transaccional ---------- */
.terminal {
  background: #140a06; color: #e9dcc4; font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  font-size: .82rem; line-height: 1.55; border-radius: 10px; padding: 14px 16px; min-height: 220px;
  max-height: 420px; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: 14px 0 0;
  border: 1px solid var(--cacao-700);
}
.log--cmd { color: var(--caramel-light); }
.log--ok { color: #7fd6a0; font-weight: 700; }
.log--err { color: #ff8f7f; font-weight: 700; }
.log--info { color: #b9a98c; }
.btn-row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 14px; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 50; max-width: min(420px, calc(100vw - 36px)); }
.toast {
  display: grid; gap: 2px; padding: 12px 16px; border-radius: 12px; color: #fff; box-shadow: var(--shadow-2);
  animation: slide-in .25s ease; border-left: 5px solid rgba(255,255,255,.55); font-size: .88rem;
}
.toast--ok { background: #2a6e47; } .toast--error { background: #92291c; }
.toast--warn { background: #8e5f14; } .toast--info { background: #245b7d; }
@keyframes slide-in { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  body { grid-template-columns: 1fr; }
  .menu-toggle { display: block; }
  .sidebar { position: fixed; z-index: 25; width: 280px; transform: translateX(-105%); transition: transform .25s ease; }
  .sidebar.is-open { transform: none; }
  .main { padding-top: 66px; }
}
@media (max-width: 640px) {
  table.data { min-width: 0; }
  table.data thead { display: none; }
  table.data tr { display: block; border-top: 8px solid var(--ivory); padding: 6px 0; }
  table.data td { display: flex; justify-content: space-between; gap: 14px; border: 0; padding: 6px 12px; }
  table.data td::before { content: attr(data-label); font-weight: 700; color: var(--cacao-500); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; }
  td.num { text-align: right; }
}

/* ---------- Estadísticas (reporte de ingresos) ---------- */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.stat-card { background: #fffdf8; border: 1px solid var(--cream-deep); border-left: 5px solid var(--caramel); border-radius: var(--radius); padding: 14px 18px; box-shadow: var(--shadow-1); display: flex; flex-direction: column; gap: 2px; }
.stat-card span { font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--cacao-500); font-weight: 700; }
.stat-card strong { font-family: var(--font-display); font-size: 1.5rem; color: var(--cacao-900); }
.stat-card small { color: var(--copper); font-weight: 700; font-size: .78rem; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 22px; }
.bars { display: flex; flex-direction: column; gap: 14px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr auto; align-items: center; gap: 12px; font-size: .88rem; }
.bar-label { font-weight: 700; color: var(--cacao-700); }
.bar-track { background: var(--cream); border-radius: 999px; height: 20px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; min-width: 4px; transition: width .6s ease; }
.bar-fill--m0, .bar-fill--t0 { background: linear-gradient(90deg, var(--caramel-light), var(--copper)); }
.bar-fill--m1, .bar-fill--t1 { background: linear-gradient(90deg, #d4a24f, #8c6422); }
.bar-fill--m2, .bar-fill--t2 { background: linear-gradient(90deg, var(--cacao-500), var(--cacao-900)); }
.bar-fill--m3, .bar-fill--t3 { background: linear-gradient(90deg, #6aa98a, #2f7d4f); }
.bar-value { font-variant-numeric: tabular-nums; font-weight: 700; text-align: right; white-space: nowrap; }
.bar-value small { color: var(--cacao-500); font-weight: 500; margin-left: 4px; }
@media (max-width: 640px) { .bar-row { grid-template-columns: 1fr auto; } .bar-track { grid-column: 1 / -1; order: 3; } }

/* ---------- Gráfico de columnas (ingresos por método) ---------- */
.col-chart__body { display: grid; grid-template-columns: 52px 1fr; gap: 8px; height: 300px; padding: 8px 4px 0; }
.col-chart__y { display: flex; flex-direction: column; justify-content: space-between; text-align: right; font-size: .75rem; color: var(--cacao-500); font-variant-numeric: tabular-nums; }
.col-chart__y span { line-height: 0; }
.col-chart__plot {
  display: flex; align-items: stretch; justify-content: space-around; gap: 18px; padding: 0 12px;
  border-left: 3px solid var(--cacao-900); border-bottom: 3px solid var(--cacao-900);
  --seg: 25%;
  background: repeating-linear-gradient(to top, transparent 0, transparent calc(var(--seg) - 1px), var(--cream-deep) calc(var(--seg) - 1px), var(--cream-deep) var(--seg));
  margin-bottom: 0;
}
.col-item { flex: 1; max-width: 140px; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; padding-bottom: 0; }
.col-bar { width: 100%; border: 3px solid var(--cacao-900); border-bottom: 0; border-radius: 4px 4px 0 0; min-height: 4px; height: 0; transition: height .7s ease; order: 2; }
.col-value { order: 1; font-weight: 700; font-size: .82rem; margin-bottom: 4px; white-space: nowrap; }
.col-label { order: 3; position: absolute; bottom: -30px; font-weight: 700; font-size: .85rem; color: var(--cacao-700); white-space: nowrap; }
.col-bar--0 { background: #ee3d3a; }
.col-bar--1 { background: #5bc8f8; }
.col-bar--2 { background: #fbb556; }
.col-bar--3 { background: #74c6a5; }
.col-chart .muted { margin-top: 38px; }

/* ---------- Gráfico circular (donut) ---------- */
.donut-wrap { display: flex; align-items: center; gap: 32px; flex-wrap: wrap; }
.donut { width: 220px; height: 220px; flex: none; transform: none; }
.donut-t1 { fill: var(--cacao-500); font-family: var(--font-body); }
.donut-t2 { fill: var(--cacao-900); font-family: var(--font-display); font-weight: 700; }
.legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 260px; display: flex; flex-direction: column; gap: 10px; }
.legend li { display: grid; grid-template-columns: 16px 1fr auto; align-items: center; gap: 10px; font-size: .88rem; }
.legend .lg-name { font-weight: 700; color: var(--cacao-700); }
.legend .lg-val { font-variant-numeric: tabular-nums; font-weight: 700; text-align: right; }
.legend small { color: var(--cacao-500); font-weight: 500; margin-left: 4px; }
.sw { width: 14px; height: 14px; border-radius: 4px; border: 2px solid var(--cacao-900); }
.sw0 { background: #ee3d3a; } .sw1 { background: #5bc8f8; } .sw2 { background: #fbb556; } .sw3 { background: #74c6a5; }
.sw4 { background: #a9582d; } .sw5 { background: #7a5440; } .sw6 { background: #b8863b; }
.col-chart--compact .col-chart__plot { gap: 8px; padding: 0 6px; }
.col-chart--compact .col-value { font-size: .68rem; }
.col-chart--compact .col-label { font-size: .72rem; }
@media (max-width: 640px) { .donut { width: 180px; height: 180px; } }