:root {
  --bg: #f5f6f8; --surface: #fff; --surface-2: #f0f2f5; --border: #e2e5ea; --border-strong: #cfd4db;
  --text: #17202b; --muted: #5f6b7a; --accent: #0f766e; --accent-hover: #0c5f58; --accent-soft: #e5f4f2;
  --danger: #b42318; --danger-soft: #fef3f2; --warn: #b54708; --warn-soft: #fffaeb; --ok: #067647; --ok-soft: #ecfdf3;
  --info: #3538cd; --info-soft: #eef4ff;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.07);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
img { max-width: 100%; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
h1, h2, h3 { letter-spacing: -.01em; line-height: 1.25; }
h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- botones y campos ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); padding: 9px 16px;
  border-radius: 8px; cursor: pointer; text-decoration: none; white-space: nowrap; min-height: 40px; }
.btn:hover { border-color: var(--accent); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); border-color: #f4b7b1; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 5px 10px; font-size: 13px; min-height: 32px; }
.btn.lg { padding: 13px 24px; font-size: 16px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.whatsapp { background: #1f9d55; border-color: #1f9d55; color: #fff; }
label { display: block; font-weight: 600; font-size: 13px; margin: 0 0 4px; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number], input[type=date], input[type=url], input[type=search], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 8px; padding: 9px 11px; min-height: 42px; }
textarea { resize: vertical; min-height: 80px; line-height: 1.45; }
input::placeholder, textarea::placeholder { color: #98a2b3; }
.field { margin-bottom: 14px; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; font-size: 14px; }
.check input { width: 18px; height: 18px; margin-top: 2px; flex: 0 0 auto; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.alert { padding: 11px 14px; border-radius: 8px; font-size: 14px; margin: 0 0 14px; border: 1px solid; }
.alert.err { background: var(--danger-soft); border-color: #fecdca; color: var(--danger); }
.alert.ok { background: var(--ok-soft); border-color: #abefc6; color: var(--ok); }
.alert.warn { background: var(--warn-soft); border-color: #fedf89; color: var(--warn); }
.alert.info { background: var(--info-soft); border-color: #c7d7fe; color: var(--info); }

/* ---------- estructura de la app ---------- */
.topbar { position: sticky; top: 0; z-index: 30; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 18px; padding: 0 20px; height: 60px; }
.logo { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 17px; color: var(--text); text-decoration: none; }
.logo .mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 15px; }
.nav { display: flex; gap: 2px; }
.nav a { color: var(--muted); text-decoration: none; font-weight: 600; padding: 8px 12px; border-radius: 8px; font-size: 14px; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.lang-btn { font-weight: 700; font-size: 12px; }
main.page { max-width: 1100px; margin: 0 auto; padding: 22px 20px 90px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.bottom-nav { display: none; }

/* ---------- panel ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .v { font-size: 22px; font-weight: 750; letter-spacing: -.02em; }
.stat .l { font-size: 12.5px; color: var(--muted); }
.stat .s { font-size: 12px; color: var(--muted); }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--border); font-size: 14px; }
.checklist li:first-child { border-top: 0; }
.checklist .dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border-strong); display: grid; place-items: center; font-size: 12px; flex: 0 0 auto; }
.checklist li.done .dot { background: var(--ok); border-color: var(--ok); color: #fff; }
.checklist li.done span.t { color: var(--muted); text-decoration: line-through; }
.checklist a { margin-left: auto; font-size: 13px; font-weight: 600; }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; align-items: start; }

/* ---------- listas ---------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input[type=search] { flex: 1 1 220px; width: auto; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font: inherit; font-size: 13px; font-weight: 600; border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  border-radius: 99px; padding: 5px 12px; cursor: pointer; }
.chip.on { background: var(--text); border-color: var(--text); color: #fff; }
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.li { display: grid; grid-template-columns: 90px 1fr auto auto; gap: 14px; align-items: center; padding: 13px 16px; border-top: 1px solid var(--border);
  text-decoration: none; color: inherit; }
.li:first-child { border-top: 0; }
.li:hover { background: #fafbfc; }
.li .num { font-weight: 700; color: var(--muted); font-size: 13px; }
.li .who { font-weight: 650; }
.li .what { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li .amt { font-weight: 700; text-align: right; }
.li .amt small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 99px; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.badge.sent, .badge.viewed { background: var(--info-soft); color: var(--info); }
.badge.approved, .badge.paid, .badge.invoiced { background: var(--ok-soft); color: var(--ok); }
.badge.changes, .badge.partial { background: var(--warn-soft); color: var(--warn); }
.badge.declined, .badge.void, .badge.overdue { background: var(--danger-soft); color: var(--danger); }
.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty h3 { color: var(--text); }

/* ---------- plantillas ---------- */
.trades { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.trade { border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); padding: 16px 12px; text-align: center; cursor: pointer;
  font: inherit; font-weight: 650; color: var(--text); box-shadow: var(--shadow); }
.trade:hover { border-color: var(--accent); background: var(--accent-soft); }
.trade .ic { font-size: 28px; display: block; margin-bottom: 6px; }
.trade small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }

/* ---------- editor ---------- */
.ed-head { position: sticky; top: 60px; z-index: 20; background: var(--bg); padding: 10px 0 12px; margin: -10px 0 8px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.ed-title { font-size: 19px; font-weight: 750; margin: 0; }
.save-state { font-size: 12.5px; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.save-state.ok { color: var(--ok); }
.save-state.err { color: var(--danger); }
.ed-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.ed-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.items { width: 100%; border-collapse: collapse; }
.items th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); text-align: left; padding: 6px 6px; border-bottom: 1px solid var(--border); }
.items td { padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.items td.c-qty { width: 76px; } .items td.c-unit { width: 108px; } .items td.c-price { width: 112px; } .items td.c-amt { width: 104px; text-align: right; font-weight: 650; padding-top: 18px; white-space: nowrap; }
.items td.c-qty input, .items td.c-unit input, .items td.c-price input { padding: 8px 7px; }
.items td.c-price input, .items td.c-qty input { text-align: right; }
.side .row { grid-template-columns: 1fr; gap: 0; }
.paid-row { display: flex; justify-content: space-between; font-size: 15px; padding: 4px 0 8px; }
.items td.c-act { width: 40px; padding-top: 12px; }
.items textarea { min-height: 42px; height: 42px; resize: none; overflow: hidden; }
.items input { padding: 8px; }
.icon-btn { border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 18px; width: 32px; height: 32px; border-radius: 6px; line-height: 1; }
.icon-btn:hover { background: var(--danger-soft); color: var(--danger); }
.totals { font-size: 14.5px; }
.totals .tr { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 0; }
.totals .tr input { width: 110px; text-align: right; min-height: 36px; padding: 6px 8px; }
.totals .grand { border-top: 2px solid var(--text); margin-top: 6px; padding-top: 10px; font-size: 19px; font-weight: 800; }
.totals .dep { color: var(--muted); font-size: 13.5px; }
.timeline { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.timeline li { padding: 6px 0; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.timeline li:first-child { border-top: 0; }
.timeline time { color: var(--muted); white-space: nowrap; }
.banner { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.banner .btn { margin-left: auto; }
.pay-row { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-top: 1px solid var(--border); font-size: 14px; align-items: center; }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-h { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 0; }
.modal-h h2 { margin: 0; }
.modal-b { padding: 16px 20px 20px; }
.modal-f { display: flex; gap: 8px; justify-content: flex-end; padding: 0 20px 20px; flex-wrap: wrap; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { font-size: 13px; }
.send-opts { display: grid; gap: 10px; }
.menu { position: relative; }
.menu-list { position: absolute; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(16,24,40,.15); min-width: 230px; padding: 6px; z-index: 40; }
.menu-list button { display: block; width: 100%; text-align: left; font: inherit; font-size: 14px; background: none; border: 0; padding: 9px 12px; border-radius: 6px; cursor: pointer; color: var(--text); }
.menu-list button:hover { background: var(--surface-2); }
.menu-list button.danger { color: var(--danger); }
.menu-list hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--text); color: #fff; padding: 10px 18px; border-radius: 8px;
  font-weight: 600; z-index: 70; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: calc(100vw - 32px); }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth { width: min(420px, 100%); }
.auth .logo { justify-content: center; margin-bottom: 18px; font-size: 20px; }
.auth .card { padding: 26px; }
.auth h1 { text-align: center; margin-bottom: 18px; font-size: 22px; }
.auth-links { text-align: center; margin-top: 14px; font-size: 14px; }
.plan-box { border: 2px solid var(--border); border-radius: 12px; padding: 18px; }
.plan-box.pro { border-color: var(--accent); }
.plan-box .price { font-size: 30px; font-weight: 800; }
.plan-box ul { padding-left: 18px; margin: 10px 0 14px; }
.logo-prev { width: 84px; height: 84px; border: 1px dashed var(--border-strong); border-radius: 10px; display: grid; place-items: center; overflow: hidden; background: var(--surface-2); }
.logo-prev img { max-width: 100%; max-height: 100%; }

/* ---------- móvil ---------- */
@media (max-width: 860px) {
  .ed-grid, .grid-2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 700px) {
  .nav { display: none; }
  .topbar { padding: 0 14px; }
  main.page { padding: 16px 12px 96px; }
  .bottom-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .bottom-nav a { text-align: center; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 600; padding: 4px 0; border-radius: 8px; }
  .bottom-nav a .i { display: block; font-size: 20px; line-height: 1.2; }
  .bottom-nav a.active { color: var(--accent); }
  .bottom-nav a.new .i { background: var(--accent); color: #fff; width: 38px; height: 38px; border-radius: 50%; margin: -12px auto 2px; display: grid; place-items: center; font-size: 22px; box-shadow: 0 4px 12px rgba(15,118,110,.4); }
  .row, .row3 { grid-template-columns: 1fr; }
  .li { grid-template-columns: 1fr auto; gap: 4px 10px; }
  .li .num { grid-column: 1; }
  .li .badge-cell { grid-row: 1; grid-column: 2; text-align: right; }
  .li .main { grid-column: 1 / -1; }
  .li .amt { grid-column: 1 / -1; text-align: left; }
  .items thead { display: none; }
  .items, .items tbody { display: block; }
  .items tr { display: grid; grid-template-columns: 1fr 1fr 1fr 36px; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--border); }
  .items td { display: block; border: 0; padding: 0; width: auto !important; }
  .items td.c-desc { grid-column: 1 / -1; }
  .items td.c-amt { grid-column: 1 / 4; text-align: left; padding-top: 2px; }
  .items td.c-act { grid-column: 4; grid-row: 2; padding-top: 0; }
  .items td .mlabel { display: block; font-size: 11px; color: var(--muted); font-weight: 600; }
  .ed-head { top: 60px; }
  .ed-actions { margin-left: 0; width: 100%; }
  .ed-actions .btn { flex: 1; }
  #top-new { display: none; }
  .logo-t { font-size: 16px; }
  .toast { bottom: 90px; }
}
@media (min-width: 701px) { .items td .mlabel { display: none; } }
