:root {
  --brand: #5f7d33; --brand-dark: #46601f; --brand-soft: #edf1e1;
  --gold: #d9a52a; --ink: #2a2a20; --muted: #7c7a6c; --line: #e6e2d5;
  --bg: #f4f1e8; --card: #fff; --danger: #b11e1e; --green: #16794c;
  --radius: 14px;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.45; padding-bottom: 40px;
}
a { color: var(--brand-dark); }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  background: var(--card); border-radius: 20px; padding: 30px 26px; width: 100%; max-width: 360px;
  box-shadow: 0 8px 30px rgba(70,96,31,.14); text-align: center;
}
.login-card img { width: 74px; height: 74px; margin: 0 auto 10px; }
.login-card h1 { font-size: 20px; margin: 4px 0 2px; }
.login-card p { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.login-card input { width: 100%; padding: 13px 14px; border: 1px solid var(--line); border-radius: 12px; font-size: 16px; }
.login-card button {
  width: 100%; margin-top: 12px; padding: 14px; border: none; border-radius: 12px;
  background: var(--brand); color: #fff; font-size: 16px; font-weight: 700; cursor: pointer;
}
.login-err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* App shell */
.topbar {
  background: linear-gradient(135deg, var(--brand), var(--brand-dark)); color: #fff;
  padding: 14px 18px; display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 30;
}
.topbar img { width: 38px; height: 38px; background: #fff; border-radius: 50%; }
.topbar b { font-size: 16px; flex: 1; }
.topbar button { background: rgba(255,255,255,.18); border: 1px solid rgba(255,255,255,.3); color: #fff; padding: 7px 12px; border-radius: 10px; font-size: 13px; font-weight: 600; cursor: pointer; }
.tabs { display: flex; gap: 4px; background: var(--card); padding: 8px 10px; overflow-x: auto; border-bottom: 1px solid var(--line); position: sticky; top: 66px; z-index: 20; }
.tab { flex: 0 0 auto; padding: 9px 15px; border-radius: 10px; border: none; background: transparent; color: var(--muted); font-size: 14px; font-weight: 600; cursor: pointer; }
.tab.active { background: var(--brand-soft); color: var(--brand-dark); }
.wrap { max-width: 820px; margin: 0 auto; padding: 16px; }

/* Metric cards */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.metric { background: var(--card); border-radius: var(--radius); padding: 14px 16px; border: 1px solid var(--line); }
.metric .l { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.metric .v { font-size: 26px; font-weight: 800; margin-top: 3px; }
.metric .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.metric.accent .v { color: var(--brand-dark); }
.metric.warn { background: #fff7e6; border-color: #ffe0a3; }
.metric.warn .v { color: #a86a00; }

.panel { background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); padding: 16px; margin-top: 16px; }
.panel h3 { margin: 0 0 12px; font-size: 15px; }
.chartbox { display: flex; align-items: flex-end; gap: 6px; height: 130px; padding-top: 10px; }
.bar { flex: 1; background: var(--brand); border-radius: 5px 5px 0 0; min-height: 3px; position: relative; }
.bar span { position: absolute; bottom: -18px; left: 0; right: 0; text-align: center; font-size: 9px; color: var(--muted); }
.bar b { position: absolute; top: -16px; left: 0; right: 0; text-align: center; font-size: 10px; color: var(--brand-dark); }

/* Orders */
.order { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.order .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.order .code { font-weight: 800; font-size: 15px; }
.order .when { font-size: 12px; color: var(--muted); }
.order .cust { font-size: 13.5px; margin: 6px 0; }
.order .items { font-size: 13px; color: #4a4a3e; background: #faf8f0; border-radius: 10px; padding: 8px 10px; margin: 6px 0; white-space: pre-line; }
.order .foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.order .total { font-weight: 800; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.b-nuevo { background: #e6f0ff; color: #1852a8; }
.b-preparando { background: #fff2d6; color: #a86a00; }
.b-listo { background: #e2f3e8; color: #16794c; }
.b-entregado { background: #ececec; color: #666; }
.b-cancelado { background: #fde3e3; color: #b11e1e; }
.wa-btn { display: block; text-align: center; margin-top: 10px; background: #25d366; color: #fff; text-decoration: none; padding: 11px; border-radius: 11px; font-size: 14px; font-weight: 700; }
.wa-btn:active { transform: scale(.98); }
.no-phone { margin-top: 10px; text-align: center; font-size: 12px; color: var(--muted); font-style: italic; }
.wa-ok { color: var(--green); font-size: 11.5px; font-weight: 600; }
.wa-bad { color: var(--danger); font-size: 11.5px; font-weight: 600; }
select.mini-sel, .filter-sel { padding: 7px 10px; border: 1px solid var(--line); border-radius: 9px; font-size: 13px; background: #fff; }
.link-btn { background: none; border: none; color: var(--danger); font-size: 12px; cursor: pointer; font-weight: 600; }

/* Facturación */
.segmented { display: flex; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 5px; margin-bottom: 14px; }
.segbtn { flex: 1; border: none; background: transparent; color: var(--muted); font-size: 14px; font-weight: 600; padding: 9px 8px; border-radius: 9px; cursor: pointer; }
.segbtn.active { background: var(--brand); color: #fff; }
.rep-row { display: flex; justify-content: space-between; align-items: center; padding: 11px 4px; border-bottom: 1px solid var(--line); }
.rep-row:last-child { border-bottom: none; }
.rep-label { font-size: 14px; font-weight: 600; text-transform: capitalize; }
.rep-sub { font-size: 12px; color: var(--muted); }
.rep-amt { font-size: 15px; font-weight: 800; color: var(--brand-dark); }

/* Selector de horario a mostrar */
.hours-mode { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.radio-row { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: #fff; cursor: pointer; font-size: 14px; font-weight: 600; color: var(--muted); }
.radio-row.sel, .radio-row:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-dark); }
.radio-row input { width: 18px; height: 18px; accent-color: var(--brand); }

/* Selector de íconos */
.icon-picker { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-top: 4px; }
.ic-opt { font-size: 20px; line-height: 1; padding: 7px 0; border: 1px solid var(--line); background: #fff; border-radius: 10px; cursor: pointer; }
.ic-opt.active { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 2px var(--brand-soft); }
@media (max-width: 380px) { .icon-picker { grid-template-columns: repeat(6, 1fr); } }

/* Buscador y filtro de productos */
.prod-tools { display: flex; gap: 8px; margin: 6px 0 14px; }
.prod-tools #prodSearch { flex: 2; min-width: 0; }
.prod-tools #prodCatF { flex: 1; min-width: 120px; }

/* Category group headers */
.cat-group { font-size: 12px; font-weight: 700; color: var(--brand-dark); text-transform: uppercase; letter-spacing: .6px; margin: 18px 4px 8px; display: flex; align-items: center; gap: 8px; }
.cat-count { background: var(--brand-soft); color: var(--brand-dark); border-radius: 999px; padding: 1px 8px; font-size: 11px; }
.wa-warn2 { background: #fff3cd; border: 1px solid #ffe08a; color: #6b5200; padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 12px; }

/* Products */
.prow { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 9px; display: flex; align-items: center; gap: 10px; }
.prow .pinfo { flex: 1; min-width: 0; }
.prow .pname { font-weight: 700; font-size: 14px; }
.prow .pmeta { font-size: 12px; color: var(--muted); }
.prow.hidden-p { opacity: .55; }
.pact button { border: none; background: var(--brand-soft); color: var(--brand-dark); border-radius: 9px; padding: 7px 10px; font-size: 13px; font-weight: 600; cursor: pointer; margin-left: 5px; }
.pact button.del { background: #fde3e3; color: var(--danger); }
.btn-primary { border: none; background: var(--brand); color: #fff; border-radius: 11px; padding: 12px 16px; font-size: 15px; font-weight: 700; cursor: pointer; }
.btn-block { width: 100%; margin: 6px 0 16px; }

/* Forms / config */
label.fld { display: block; margin: 12px 2px 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
input.f, textarea.f, select.f { width: 100%; border: 1px solid var(--line); border-radius: 11px; padding: 11px 13px; font-size: 15px; background: #fff; font-family: inherit; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.switch { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.switch input { width: 20px; height: 20px; }
.saved { color: var(--green); font-size: 13px; font-weight: 600; margin-left: 10px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Modal */
.modal-ov { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: none; align-items: center; justify-content: center; z-index: 60; padding: 16px; }
.modal-ov.open { display: flex; }
.modal { background: var(--bg); border-radius: 18px; width: 100%; max-width: 440px; max-height: 90vh; overflow-y: auto; padding: 20px; }
.modal h3 { margin: 0 0 6px; }
.loading { text-align: center; color: var(--muted); padding: 40px; }
