:root {
  --bg: #f5f6f7; --card: #fff; --line: #d9dce1; --muted: #e4e5e8; --txt: #1f2328; --soft: #5b616b;
  --accent: #2346c9; --accent-bg: #dbe4fb; --err: #b42318; --ok: #1a7f37; --r: 4px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 13px; color: var(--txt);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
.wrap { max-width: 1260px; margin: 0 auto; padding: 0 16px 40px; }

.topbar { background: var(--muted); display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 16px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; }
.tabs a { padding: 6px 12px; border-radius: 16px; color: var(--soft); text-decoration: none; font-weight: 500; }
.tabs a.on { background: var(--card); color: var(--txt); }
label.periodo { flex-direction: row; display: flex; color: var(--txt); align-items: center; gap: 8px; }
.periodo select { width: 96px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 12px; }
.card-h { padding: 14px 12px; font-size: 14px; cursor: pointer; display: flex; align-items: center; gap: 8px; user-select: none; }
.chev::before { content: "⌃"; display: inline-block; transition: transform .15s; }
.card.closed .chev::before { transform: rotate(180deg); }
.card.closed .card-b { display: none; }
.card-b { padding: 0 12px 22px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 20px; }
@media (max-width: 860px) { .grid3 { grid-template-columns: 1fr; } }

label { display: flex; flex-direction: column; gap: 6px; color: var(--soft); }
label b { color: var(--err); font-weight: 400; }
input, select, textarea { font: inherit; color: var(--txt); background: #fff; border: 1px solid var(--line);
  border-radius: var(--r); padding: 8px; min-height: 32px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
input[readonly] { background: #fafafa; }
textarea { resize: vertical; }
.help { display: inline-grid; place-items: center; width: 14px; height: 14px; border: 1px solid var(--soft);
  border-radius: 50%; font-size: 10px; margin-left: 4px; cursor: help; }
.link-sm { font-size: 11px; color: var(--txt); margin-left: 6px; }

.venc-row { display: flex; }
.venc-row input { border-radius: var(--r) 0 0 var(--r); flex: 1 1 130px; min-width: 0; }
.seg { display: flex; border: 1px solid var(--line); border-left: 0; border-radius: 0 16px 16px 0; overflow: hidden; }
.seg button { border: 0; border-left: 1px solid var(--line); background: #fff; padding: 0 9px; font: inherit; color: var(--soft); cursor: pointer; white-space: nowrap; }
.seg button.on { background: var(--accent-bg); color: var(--accent); }

/* Conceptos */
.lin-head, .linea { display: grid; grid-template-columns: 20px 1fr 110px 110px 70px 170px 24px 12px; gap: 10px; align-items: start; }
.lin-head { color: var(--txt); padding-bottom: 8px; }
.lin-head span:nth-child(3), .lin-head span:nth-child(4), .lin-head span:nth-child(5), .lin-head span:nth-child(6) { font-size: 12px; }
.linea { margin-bottom: 8px; }
.linea .sel { width: 12px; min-height: 0; margin-top: 10px; }
.linea .concepto { min-height: 32px; height: 32px; overflow: hidden; }
.inp-pre { display: flex; border: 1px solid var(--line); border-radius: var(--r); background: #fff; }
.inp-pre span { background: var(--bg); padding: 0 7px; display: grid; place-items: center; font-size: 12px; }
.inp-pre input { border: 0; min-width: 0; text-align: right; padding: 6px; }
.qty { display: flex; align-items: center; border: 1px solid var(--line); border-radius: var(--r); background: #fff; }
.qty button { border: 0; background: var(--bg); width: 22px; height: 30px; cursor: pointer; }
.qty input { border: 0; text-align: center; min-width: 0; padding: 6px 2px; }
.iva-grp { display: grid; grid-template-columns: 64px 1fr; gap: 4px; }
.iva-grp select { padding: 6px 4px; }
.icon { border: 0; background: none; cursor: pointer; padding-top: 8px; opacity: .7; }
.lin-foot { margin-top: 12px; }
@media (max-width: 860px) {
  .lin-head { display: none; }
  .linea { grid-template-columns: 1fr 1fr; padding-bottom: 10px; border-bottom: 1px solid var(--muted); }
  .linea .sel, .linea > span { display: none; }
  .linea .concepto, .linea .iva-grp { grid-column: 1 / -1; }
}

/* Totales */
.totales { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 12px; }
.tot { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 12px 18px;
  display: flex; flex-direction: column; gap: 14px; font-size: 14px; }
.tot strong { text-align: right; font-size: 17px; font-variant-numeric: tabular-nums; }
.tot.total { background: var(--muted); border-color: var(--muted); }
.tot.total strong { font-size: 22px; }
@media (max-width: 860px) { .totales { grid-template-columns: 1fr 1fr; } }

.btn { font: inherit; border: 1px solid var(--line); background: #fff; padding: 8px 16px; border-radius: var(--r); cursor: pointer; }
.btn.pill { border-radius: 18px; background: var(--muted); border-color: var(--muted); font-weight: 600; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }
.acciones { display: flex; gap: 10px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.estado { margin-right: auto; color: var(--soft); font-weight: 600; }
.msg { margin: 0; }
.msg.ok { color: var(--ok); } .msg.err, .error { color: var(--err); }

/* Login */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 340px; padding: 24px; display: grid; gap: 14px; }
.login-card h1 { margin: 0; font-size: 18px; }
