/* Facturas MDE — colores de la plantilla de Maderas de Espino. Móvil primero. */
[hidden] { display: none !important; }
:root {
  --text: #46281d; --label: #5f453b; --muted: #7a6a62; --brown: #6b4936; --beige: #efe6db; --cream: #f6f2ef;
  --line: #e3d2c4; --green: #80932f; --white: #fff; --danger: #a3352b; --ok: #2e6b3f; --warn: #8a5a00;
  --radius: 12px; --nav-h: 64px; --top-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--cream); color: var(--text); }
body { font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
h2 { font-size: 1.15rem; margin: 4px 2px 12px; }
h3 { font-size: .95rem; margin: 18px 2px 8px; color: var(--label); text-transform: uppercase; letter-spacing: .04em; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 6px; min-height: calc(var(--top-h) + var(--safe-t));
  padding: var(--safe-t) 10px 0 14px; background: var(--brown); color: #fff; }
.top h1 { flex: 1; font-size: 1.1rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 0; background: transparent; color: inherit; border-radius: 10px; }
#topActions { display: flex; gap: 6px; }
#view { padding: 14px 14px calc(var(--nav-h) + var(--safe-b) + 28px); max-width: 760px; margin: 0 auto; outline: none; }
body.kb #view { padding-bottom: 28px; }

.bottomnav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: #fff; border-top: 1px solid var(--line); }
.bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .74rem; color: var(--muted); text-decoration: none; }
.bottomnav a.active { color: var(--brown); font-weight: 700; }
body.kb .bottomnav { display: none; } /* teclado abierto: la barra no tapa los campos */

.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card-title { display: block; background: var(--beige); margin: -14px -14px 12px; padding: 10px 14px; border-radius: var(--radius) var(--radius) 0 0;
  font-weight: 700; font-size: .9rem; letter-spacing: .03em; text-transform: uppercase; }
.list { list-style: none; padding: 0; margin: 0; }
.list a, .list button.item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 13px 12px; background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 8px; color: var(--text); text-decoration: none; text-align: left; font: inherit; }
.list .grow { flex: 1; min-width: 0; }
.list small { display: block; color: var(--muted); }
.list .chev { color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--text); font: inherit; font-weight: 700; cursor: pointer; text-decoration: none; }
.btn-primary { background: var(--brown); border-color: var(--brown); color: #fff; }
.btn-light { background: #fff; color: var(--brown); border-color: #fff; min-height: 38px; padding: 6px 14px; }
.btn-danger { color: var(--danger); }
.btn-small { min-height: 36px; padding: 5px 12px; font-size: .9rem; }
.btn[disabled] { opacity: .5; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > .btn { flex: 1; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: .85rem; font-weight: 700; color: var(--label); }
.field input, .field textarea, .field select { font: inherit; font-size: 16px; color: var(--text); background: var(--cream); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 12px; min-height: 48px; width: 100%; }
.field textarea { min-height: 72px; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus { outline: 2px solid var(--green); border-color: transparent; background: #fff; }
.field .hint { font-size: .8rem; color: var(--muted); }
.field .hint.bad { color: var(--warn); }
.field .hint.good { color: var(--ok); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 48px; font-weight: 600; }
.check input { width: 22px; height: 22px; accent-color: var(--brown); }

.alert { padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; font-size: .92rem; background: #fff4df; color: #6b4300; border: 1px solid #f0d9a8; }
.alert.ok { background: #e7f3ea; color: #1e5b35; border-color: #c4e2cc; }
.alert.bad { background: #fbe8e5; color: #8c1d18; border-color: #f0c4be; }
.alert .row { margin-top: 8px; }
.search { width: 100%; font: inherit; font-size: 16px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; margin-bottom: 10px; min-height: 48px; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: .92rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }

.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  background: #2b1d14; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: .92rem; transition: all .2s; z-index: 90; max-width: 92vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--danger); } .toast.ok { background: var(--ok); }
body.kb .toast { bottom: 16px; }
.update { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; padding: 8px 12px; background: var(--green); color: #fff; font-size: .9rem; }
.update[hidden] { display: none; }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--beige); color: var(--label); }
.dialog { position: fixed; inset: 0; z-index: 95; background: rgba(30, 15, 8, .45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.dialog .box { background: #fff; border-radius: 14px; padding: 18px; width: min(420px, 100%); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- 0.4.0: borradores de factura ---------- */
.col { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.draft-band { background: #fbe8e5; color: var(--danger); border: 1px solid #f0c4be; border-radius: 10px; padding: 8px 12px; margin-bottom: 12px; font-size: .85rem; font-weight: 700; text-align: center; letter-spacing: .02em; }
.grid3 { display: grid; grid-template-columns: 1fr 1.3fr 1fr; gap: 0 8px; }
.line { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px 2px; margin-bottom: 10px; background: #fff; }
.line-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.line-n { font-size: .85rem; color: var(--label); }
.line-amt { flex: 1; text-align: right; font-size: .85rem; color: var(--muted); }
.line-del { width: 40px; height: 40px; color: var(--muted); }
.line-err { color: var(--warn); font-size: .82rem; margin: -6px 0 8px; }
.line-err:empty { display: none; }
.zero { background: var(--cream); border-radius: 8px; padding: 8px 8px 0; margin-bottom: 10px; }
.party { margin: 0 0 10px; font-size: .95rem; }
.tot { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin: 0; font-size: .95rem; }
.tot dt { color: var(--label); } .tot dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.tot dt small { display: block; color: var(--muted); font-size: .78rem; }
.tot .sub { font-weight: 700; border-top: 1px solid var(--line); padding-top: 6px; }
.tot .pay { font-weight: 800; font-size: 1.1rem; color: var(--text); border-top: 2px solid var(--brown); padding-top: 8px; }
form.locked { opacity: .55; }
.sheet { position: fixed; inset: 0; z-index: 60; background: var(--cream); display: flex; flex-direction: column; }
.sheet-top { display: flex; align-items: center; gap: 8px; padding: calc(var(--safe-t) + 6px) 8px 6px 14px; background: var(--brown); color: #fff; min-height: 56px; }
.sheet-top b { flex: 1; font-size: 1.05rem; }
.sheet-body { flex: 1; overflow: auto; padding: 14px 14px calc(var(--safe-b) + 20px); max-width: 760px; width: 100%; margin: 0 auto; }
.viewer { display: flex; flex-direction: column; gap: 10px; }
.pv-page { width: 100%; height: auto; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .18); border-radius: 2px; }
.sheet-actions { position: sticky; bottom: 0; background: var(--cream); padding: 10px 0; }
.undo { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--safe-b) + 16px); z-index: 91; display: flex; align-items: center; gap: 12px;
  background: #2b1d14; color: #fff; padding: 8px 8px 8px 16px; border-radius: 10px; font-size: .92rem; max-width: 92vw; }
.undo .btn { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .5); }
body.kb .undo { bottom: 16px; }
.nowrap { white-space: nowrap; }
/* 0.6.0: archivo de facturas emitidas y recibidas */
.seg { display: flex; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; margin-bottom: 12px; }
.seg a { flex: 1; text-align: center; padding: 9px 6px; border-radius: 9px; text-decoration: none; color: var(--label); font-weight: 700; min-height: 40px; display: flex; align-items: center; justify-content: center; }
.seg a.on { background: var(--brown); color: #fff; }
.chips { display: flex; gap: 6px; margin-bottom: 10px; }
.chips button { flex: 1; min-height: 40px; border-radius: 99px; border: 1px solid var(--line); background: #fff; color: var(--label); font: inherit; font-weight: 700; font-size: .9rem; }
.chips button[aria-pressed="true"] { background: var(--beige); border-color: var(--brown); color: var(--brown); }
.filters { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 10px; }
.filters select, .filters .btn { min-height: 46px; font: inherit; font-size: 16px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--text); padding: 6px 10px; }
.badge.warn { background: #fbe8e5; color: var(--danger); }
.badge.info { background: #e8eef7; color: #2b4a73; }
.badge.ok { background: #e7f3ea; color: #1e5b35; }
.badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.vatrow { display: grid; grid-template-columns: .8fr 1.2fr 1.2fr; gap: 0 8px; }
.vatrow[hidden] { display: none; }
.check-line { font-size: .88rem; padding: 8px 10px; border-radius: 8px; background: var(--cream); margin-bottom: 10px; }
.check-line.bad { background: #fbe8e5; color: #8c1d18; }
.docbox { border: 1px dashed var(--line); border-radius: 10px; padding: 10px; margin-bottom: 10px; background: var(--cream); }
.docbox.missing { border-color: #f0c4be; background: #fbe8e5; color: #8c1d18; }
.docimg { width: 100%; height: auto; background: #fff; border-radius: 4px; }
.amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.list .side { text-align: right; }
