/* ==========================================================
   AltaViva Contable · estilos
   Diseño mobile-first: barra inferior en celular, lateral en PC.
   ========================================================== */
:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #16202a;
  --muted: #6b7684;
  --border: #e3e7ec;
  --primary: #0f766e;
  --primary-dark: #0b5c56;
  --primary-soft: #d9f4f0;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --success: #067647;
  --success-soft: #dcfae6;
  --warning: #b54708;
  --warning-soft: #fef0c7;
  --info: #175cd3;
  --info-soft: #e0ecff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
  --nav-w: 240px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 1rem; }
.mb { margin-bottom: 1rem; }
.hidden { display: none !important; }
.flex { display: flex; gap: .5rem; align-items: center; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.bold { font-weight: 700; }
.pos { color: var(--success); }
.neg { color: var(--danger); }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  display: none;
  width: var(--nav-w);
  background: #0f1f2b;
  color: #cfd8e3;
  flex-direction: column;
  position: fixed; inset: 0 auto 0 0;
  padding: 1.25rem 1rem;
}
.sidebar .brand { color: #fff; font-weight: 800; font-size: 1.15rem; margin-bottom: 1.5rem; display: flex; align-items: center; gap: .5rem; }
.sidebar .brand span { background: var(--primary); color: #fff; border-radius: 8px; padding: 2px 7px; font-size: .9rem; }
.sidebar nav a {
  display: flex; align-items: center; gap: .65rem;
  color: #cfd8e3; padding: .6rem .75rem; border-radius: 10px; margin-bottom: 2px; font-weight: 500;
}
.sidebar nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar .negocio { margin-top: auto; padding-top: 1rem; border-top: 1px solid rgba(255,255,255,.1); font-size: .85rem; }
.sidebar .negocio select { width: 100%; background: #1a2d3c; color: #fff; border: 1px solid rgba(255,255,255,.15); border-radius: 8px; padding: .45rem; margin: .4rem 0; }
.sidebar .negocio a { color: #9fb0c0; }
.main { flex: 1; width: 100%; padding: 1rem 1rem 5.5rem; max-width: 1100px; margin: 0 auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.topbar .negocio-nombre { font-size: .8rem; color: var(--muted); }
.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: #fff; border-top: 1px solid var(--border);
  display: flex; justify-content: space-around; padding: .35rem 0 calc(.35rem + env(safe-area-inset-bottom));
}
.bottombar a { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: .68rem; font-weight: 600; padding: .25rem .5rem; min-width: 56px; }
.bottombar a.active { color: var(--primary); }
.bottombar a:hover { text-decoration: none; }
.bottombar svg, .sidebar svg { width: 22px; height: 22px; }
@media (min-width: 900px) {
  .sidebar { display: flex; }
  .bottombar { display: none; }
  .main { margin-left: var(--nav-w); padding: 1.5rem 2rem 2rem; max-width: none; }
  .main > .container { max-width: 1100px; margin: 0 auto; }
  h1 { font-size: 1.7rem; }
}

/* ---------- Tarjetas ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem; }
.card.tight { padding: 0; overflow: hidden; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .75rem; }
.grid { display: grid; gap: .75rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(2, 1fr); }
.grid-4 { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 700px) { .grid-3 { grid-template-columns: repeat(3, 1fr); } .grid-4 { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem; }
.stat .lbl { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.stat .val { font-size: 1.35rem; font-weight: 800; margin-top: .15rem; }
.stat .sub { font-size: .78rem; color: var(--muted); }
@media (min-width: 700px) { .stat .val { font-size: 1.6rem; } }

/* ---------- Formularios ---------- */
label, .label { display: block; font-size: .78rem; font-weight: 700; color: var(--muted); margin-bottom: .3rem; text-transform: uppercase; letter-spacing: .03em; }
.field { margin-bottom: .9rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=datetime-local], input[type=tel], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: .65rem .75rem; font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,118,110,.15); }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--primary); }
textarea { min-height: 80px; resize: vertical; }
.check { display: flex; align-items: center; gap: .5rem; text-transform: none; font-size: .9rem; font-weight: 500; color: var(--text); }
.input-money { position: relative; }
.input-money input { padding-left: 1.6rem; font-variant-numeric: tabular-nums; }
.input-money::before { content: "$"; position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 600; }
.help { font-size: .78rem; color: var(--muted); margin-top: .25rem; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: 1px solid transparent; border-radius: 10px; padding: .6rem 1rem; font: inherit; font-weight: 700; font-size: .9rem;
  cursor: pointer; background: var(--primary); color: #fff; white-space: nowrap; line-height: 1.2;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn svg { width: 18px; height: 18px; }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #f3f5f7; }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: #fdd1cd; }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-ghost:hover { background: var(--primary-soft); }
.btn-sm { padding: .4rem .7rem; font-size: .8rem; }
.btn-lg { padding: .85rem 1.25rem; font-size: 1rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.fab { position: fixed; right: 1rem; bottom: 4.6rem; z-index: 25; border-radius: 999px; padding: .85rem 1.15rem; box-shadow: 0 6px 20px rgba(15,118,110,.35); }
@media (min-width: 900px) { .fab { display: none; } }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .65rem .75rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; background: #fafbfc; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f7fafa; }
tfoot td { font-weight: 700; background: #fafbfc; }

/* Lista tipo móvil */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .75rem 1rem; border-bottom: 1px solid var(--border); color: inherit; }
.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: #f7fafa; text-decoration: none; }
.list-item .t { font-weight: 600; }
.list-item .s { font-size: .8rem; color: var(--muted); }
.list-item .amt { font-weight: 800; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- Badges / alertas ---------- */
.badge { display: inline-block; border-radius: 999px; padding: .15rem .6rem; font-size: .72rem; font-weight: 700; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-muted { background: #eef1f4; color: var(--muted); }
.alert { padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1rem; font-size: .9rem; font-weight: 500; }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-info { background: var(--info-soft); color: var(--info); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.empty svg { width: 40px; height: 40px; opacity: .4; margin-bottom: .5rem; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; background: linear-gradient(160deg, #0f1f2b 0%, #0f766e 100%); }
.auth .box { background: #fff; border-radius: 18px; padding: 2rem 1.5rem; width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.auth .logo { font-weight: 900; font-size: 1.5rem; margin-bottom: .25rem; }
.auth .logo span { color: var(--primary); }

/* ---------- Filtros ---------- */
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; margin-bottom: 1rem; }
.filters .field { margin: 0; flex: 1; min-width: 130px; }
.tabs { display: flex; gap: .25rem; overflow-x: auto; margin-bottom: 1rem; }
.tabs a { padding: .45rem .85rem; border-radius: 999px; background: #fff; border: 1px solid var(--border); font-size: .85rem; font-weight: 600; color: var(--text); white-space: nowrap; }
.tabs a.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tabs a:hover { text-decoration: none; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(15,31,43,.55); display: none; align-items: flex-end; justify-content: center; z-index: 50; padding: 0; }
.modal.open { display: flex; }
.modal .dialog { background: #fff; width: 100%; max-width: 560px; border-radius: 18px 18px 0 0; padding: 1.25rem 1rem calc(1.25rem + env(safe-area-inset-bottom)); max-height: 92vh; overflow-y: auto; }
@media (min-width: 700px) { .modal { align-items: center; padding: 1rem; } .modal .dialog { border-radius: 18px; padding: 1.5rem; } }
.modal .dialog h2 { margin-bottom: 1rem; }

/* ---------- Venta rápida ---------- */
.pos-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 900px) { .pos-grid { grid-template-columns: 1.3fr 1fr; align-items: start; } }
.prod-results { position: absolute; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); z-index: 30; max-height: 260px; overflow-y: auto; }
.prod-results div { padding: .6rem .75rem; cursor: pointer; display: flex; justify-content: space-between; gap: .5rem; }
.prod-results div:hover { background: var(--primary-soft); }
.cart-row { display: grid; grid-template-columns: 1fr 70px 100px 28px; gap: .4rem; align-items: center; padding: .5rem 0; border-bottom: 1px solid var(--border); }
.cart-row input { padding: .4rem .5rem; text-align: right; }
.cart-row .nm { font-size: .9rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cart-row .rm { background: none; border: 0; color: var(--danger); cursor: pointer; font-size: 1.1rem; }
.totales { font-size: .95rem; }
.totales div { display: flex; justify-content: space-between; padding: .3rem 0; }
.totales .tot { font-size: 1.35rem; font-weight: 900; border-top: 2px solid var(--text); margin-top: .3rem; padding-top: .5rem; }

/* ---------- Gráficas ---------- */
.bars { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding-top: .5rem; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.bars .bar i { display: block; width: 100%; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; transition: height .3s; }
.bars .bar i.g { background: #f79009; }
.bars .bar b { font-size: .62rem; color: var(--muted); font-weight: 600; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.hbar { display: grid; grid-template-columns: 1fr 3fr auto; gap: .5rem; align-items: center; font-size: .85rem; padding: .3rem 0; }
.hbar .track { background: #eef1f4; border-radius: 6px; height: 12px; overflow: hidden; }
.hbar .track i { display: block; height: 100%; background: var(--primary); border-radius: 6px; }
.legend { display: flex; gap: 1rem; font-size: .78rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }

/* ---------- Impresión ---------- */
@media print {
  .no-print, .sidebar, .bottombar, .fab { display: none !important; }
  body { background: #fff; }
  .main { margin: 0; padding: 0; }
  .card { box-shadow: none; border: 0; }
}

.mobile-only { display: flex; }
@media (min-width: 900px) { .mobile-only { display: none !important; } }

/* ---------- Factura ---------- */
.factura { background: #fff; color: #111; max-width: 800px; margin: 0 auto; }
.factura .f-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; border-bottom: 2px solid #111; padding-bottom: .75rem; margin-bottom: .75rem; }
.factura .f-emp { font-size: 1.25rem; font-weight: 900; }
.factura .f-num { text-align: right; }
.factura .f-n { font-size: 1.3rem; font-weight: 900; }
.factura .f-cli { margin-bottom: .75rem; }
.factura .f-items { margin-bottom: .75rem; }
.factura .f-items th { background: #f0f0f0; color: #333; }
.factura .f-items td, .factura .f-items th { border-bottom: 1px solid #ddd; }
.factura .f-total td { font-size: 1.1rem; font-weight: 900; border-top: 2px solid #111; }
.factura .f-notas { margin-top: .75rem; padding: .5rem .75rem; background: #f7f7f7; border-radius: 6px; }
.factura .f-pie { margin-top: 1.25rem; text-align: center; border-top: 1px dashed #bbb; padding-top: .5rem; }
@media print { .factura { max-width: none; } @page { margin: 12mm; } }
