:root {
  --bg: #f6f4ef;
  --panel: #ffffff;
  --ink: #1f2a24;
  --muted: #6b746e;
  --line: #e4e0d6;
  --brand: #24493a;        /* verde araucaria */
  --brand-2: #2f5e4b;
  --accent: #b5762a;       /* ocre */
  --accent-soft: #f5ead9;
  --ok: #2e7d4f;
  --warn: #b26b00;
  --bad: #b3362d;
  /* colores de canal (validados para daltonismo; siempre acompañados de leyenda y tabla) */
  --c-consignacion: #00b894;
  --c-distribuidor: #f47230;
  --c-directa: #257de0;
  --c-web: #ee7fac;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink); background: var(--bg); line-height: 1.45;
}
a { color: var(--brand-2); }
h1 { font-size: 1.55rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }
small, .muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--brand); color: #e7efe9; padding: 1.1rem .8rem; position: sticky; top: 0;
  height: 100vh; overflow-y: auto;
}
.brand { display: flex; gap: .6rem; align-items: center; color: #fff; text-decoration: none; padding: .2rem .5rem 1rem; }
.brand svg { flex: none; }
.brand b { display: block; font-size: 1.02rem; line-height: 1.1; }
.brand span { font-size: .75rem; opacity: .7; }
.nav-group { margin: .9rem 0 .2rem; padding: 0 .6rem; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; opacity: .55; }
.sidebar a.nav {
  display: block; color: #e7efe9; text-decoration: none; padding: .42rem .6rem; border-radius: 7px; font-size: .92rem;
}
.sidebar a.nav:hover { background: rgba(255,255,255,.08); }
.sidebar a.nav.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.main { padding: 1.6rem 2rem 3rem; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.3rem; }
.page-head .actions { margin-left: auto; display: flex; gap: .5rem; flex-wrap: wrap; }
.menu-btn { display: none; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 50; width: 250px; transform: translateX(-100%); transition: transform .2s; }
  body.menu-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .menu-btn { display: inline-flex; }
  .main { padding: 1rem; }
}

/* ---------- componentes ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); margin-bottom: 1.1rem; }
.card-head { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; margin-bottom: .8rem; }
.card-head h2 { margin: 0; }
.card-head .right { margin-left: auto; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 1.1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.grid > .card { margin-bottom: 0; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .9rem; margin-bottom: 1.1rem; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow); }
.kpi .label { font-size: .8rem; color: var(--muted); }
.kpi .value { font-size: 1.75rem; font-weight: 700; letter-spacing: -.02em; margin-top: .15rem; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: .8rem; color: var(--muted); }
.kpi.highlight { background: var(--brand); color: #fff; border-color: var(--brand); }
.kpi.highlight .label, .kpi.highlight .sub { color: #cfe0d6; }

.btn {
  display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: .48rem .85rem; border-radius: 8px; cursor: pointer; font: inherit; font-size: .9rem; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #cfc9bb; background: #fbfaf7; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.small { padding: .25rem .55rem; font-size: .8rem; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; color: var(--brand-2); cursor: pointer; padding: 0; font: inherit; text-decoration: underline; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--line); padding: .5rem .55rem; white-space: nowrap; }
td { border-bottom: 1px solid #efece5; padding: .5rem .55rem; vertical-align: top; }
tbody tr:hover { background: #fbfaf6; }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: 0; }
.table-wrap { overflow-x: auto; }
th.sortable { cursor: pointer; }
.empty { color: var(--muted); padding: 1rem .5rem; text-align: center; }

input, select, textarea {
  font: inherit; font-size: .92rem; padding: .45rem .6rem; border: 1px solid #d6d1c4; border-radius: 7px; background: #fff; color: var(--ink); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(47,94,75,.25); border-color: var(--brand-2); }
input.qty { width: 80px; text-align: right; }
label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .2rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .8rem 1rem; }
.form-grid .full { grid-column: 1 / -1; }
.toolbar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-bottom: .8rem; }
.toolbar input[type=search] { max-width: 300px; }
.toolbar select { width: auto; }

.pill { display: inline-block; font-size: .72rem; padding: .1rem .5rem; border-radius: 999px; background: #eee; white-space: nowrap; font-weight: 600; }
.pill.consignacion { background: #dcf3ec; color: #0b6b55; }
.pill.distribuidor { background: var(--accent-soft); color: #8a5617; }
.pill.directa { background: #e1ecfa; color: #1b5aa3; }
.pill.web { background: #fbe6ef; color: #a23764; }
.pill.venta { background: #e1ecfa; color: #1b5aa3; }
.pill.despacho { background: #dcf3ec; color: #0b6b55; }
.pill.ingreso { background: #e7f3ea; color: var(--ok); }
.pill.devolucion { background: var(--accent-soft); color: #8a5617; }
.pill.baja, .pill.ajuste { background: #f6e3e1; color: var(--bad); }
.neg { color: var(--bad); font-weight: 600; }

.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs button { background: none; border: 0; padding: .55rem .9rem; font: inherit; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

/* barras */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 190px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; min-width: 0; }
.bar-stack { flex: 1; width: 100%; max-width: 44px; display: flex; flex-direction: column-reverse; justify-content: flex-start; gap: 2px; cursor: pointer; }
.bar-stack span { display: block; width: 100%; }
.bar-stack span:last-child { border-radius: 4px 4px 0 0; }
.bar-col:hover .bar-stack { opacity: .85; }
.bar-tip { position: fixed; pointer-events: none; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: .5rem .7rem; font-size: .8rem; box-shadow: 0 6px 20px rgba(0,0,0,.12); z-index: 120; }
.bar-tip i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }
.bar-total { font-size: .72rem; color: var(--muted); height: 1.1em; }
.bar-label { font-size: .7rem; color: var(--muted); margin-top: 4px; white-space: nowrap; }
.bar-col.current .bar-label { color: var(--ink); font-weight: 700; }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.hbar { height: 8px; background: #eeeae0; border-radius: 4px; overflow: hidden; min-width: 60px; }
.hbar > span { display: block; height: 100%; background: var(--brand-2); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(20,28,24,.45); display: flex; align-items: flex-start; justify-content: center; z-index: 100; padding: 4vh 1rem; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: min(760px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { width: min(1020px, 100%); }
.modal header { display: flex; align-items: center; padding: 1rem 1.2rem; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; }
.modal header .x { margin-left: auto; background: none; border: 0; font-size: 1.4rem; cursor: pointer; color: var(--muted); }
.modal .body { padding: 1.1rem 1.2rem; }
.modal footer { padding: .9rem 1.2rem; border-top: 1px solid var(--line); display: flex; gap: .5rem; justify-content: flex-end; align-items: center; }
.modal footer .left { margin-right: auto; }

.toast { position: fixed; bottom: 1.2rem; right: 1.2rem; background: var(--ink); color: #fff; padding: .7rem 1rem; border-radius: 8px; z-index: 200; box-shadow: 0 6px 24px rgba(0,0,0,.25); max-width: 420px; }
.toast.error { background: var(--bad); }
.notice { background: var(--accent-soft); border: 1px solid #ecd6b3; padding: .7rem .9rem; border-radius: 8px; font-size: .9rem; margin-bottom: .9rem; }
.notice.ok { background: #e7f3ea; border-color: #c9e3d1; }
.notice.bad { background: #f8e6e4; border-color: #efc9c4; }
.dropzone { border: 2px dashed #cfc9bb; border-radius: 10px; padding: 2rem 1rem; text-align: center; color: var(--muted); cursor: pointer; background: #fcfbf8; }
.dropzone.over { border-color: var(--brand-2); background: #eef4f0; }
tr.unmatched td { background: #fdf3e6; }
details summary { cursor: pointer; }
pre.raw { white-space: pre-wrap; font-size: .75rem; background: #f6f4ef; padding: .6rem; border-radius: 6px; max-height: 240px; overflow: auto; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: var(--brand); }
.login-card { background: #fff; padding: 2rem; border-radius: 14px; width: min(360px, 92vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }

@media print {
  .sidebar, .page-head .actions, .btn, .toolbar { display: none !important; }
  .layout { display: block; }
  .card, .kpi { box-shadow: none; break-inside: avoid; }
}
