:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --border: #e3e7ee;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #e8eefc;
  --danger: #c0262d;
  --danger-soft: #fdecec;
  --ok: #157f3b;
  --ok-soft: #e6f4ea;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --sidebar: #12223b;
  --sidebar-text: #c9d3e3;
  --sidebar-active: #24406b;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--primary); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .marca { padding: 18px 16px; font-weight: 700; font-size: 16px; color: #fff; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar .marca small { display: block; font-weight: 400; font-size: 12px; color: var(--sidebar-text); margin-top: 2px; }
.menu { padding: 8px 0 16px; flex: 1; }
.menu details { border-bottom: 1px solid rgba(255,255,255,.04); }
.menu summary {
  list-style: none; cursor: pointer; padding: 10px 16px; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em; color: #8fa3c2; user-select: none;
}
.menu summary::-webkit-details-marker { display: none; }
.menu summary::after { content: '▸'; float: right; transition: transform .15s; }
.menu details[open] summary::after { transform: rotate(90deg); }
.menu a {
  display: flex; justify-content: space-between; align-items: center; gap: 6px;
  padding: 7px 16px 7px 26px; color: var(--sidebar-text); text-decoration: none; font-size: 13.5px;
}
.menu a:hover { background: rgba(255,255,255,.05); color: #fff; }
.menu a.activo { background: var(--sidebar-active); color: #fff; }
.menu a.pronto { opacity: .55; }
.menu a .tag { font-size: 10px; border: 1px solid currentColor; border-radius: 10px; padding: 0 6px; opacity: .8; }
.menu .inicio { padding-left: 16px; font-weight: 600; }
.sidebar .pie { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; }
.sidebar .pie a { color: var(--sidebar-text); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: none; align-items: center; gap: 12px; padding: 10px 16px; background: var(--sidebar); color: #fff;
}
.topbar button { background: none; border: none; color: #fff; font-size: 22px; cursor: pointer; padding: 0; }
.contenido { padding: 24px 28px; max-width: 1280px; width: 100%; }

.encabezado { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.encabezado .sub { color: var(--muted); margin-top: 4px; }
.barra { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.panel + .panel { margin-top: 16px; }

/* ---------- Controles ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: #fff;
  color: var(--text); padding: 7px 14px; border-radius: 6px; cursor: pointer; font: inherit; font-weight: 500;
  white-space: nowrap; text-decoration: none;
}
.btn:hover { background: #f8f9fb; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primario { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primario:hover { background: var(--primary-hover); }
.btn.peligro { color: var(--danger); border-color: #f1c4c6; }
.btn.peligro:hover { background: var(--danger-soft); }
.btn.chico { padding: 4px 10px; font-size: 13px; }
.btn.link { border: none; background: none; color: var(--primary); padding: 4px 6px; }

input, select, textarea {
  font: inherit; color: inherit; border: 1px solid #cfd6e1; border-radius: 6px; padding: 7px 10px;
  background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
input[type='checkbox'] { width: auto; accent-color: var(--primary); transform: scale(1.1); }
textarea { min-height: 70px; resize: vertical; }
.buscar { max-width: 320px; }
label.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }

.form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form .campo { display: flex; flex-direction: column; gap: 5px; }
.form .campo.ancho { grid-column: 1 / -1; }
.form .campo > span { font-weight: 500; font-size: 13px; }
.form .campo > span .req { color: var(--danger); }
.form .ayuda { color: var(--muted); font-size: 12px; }

/* ---------- Tablas ---------- */
.tabla-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafbfc; font-weight: 600; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfd; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.acciones { text-align: right; white-space: nowrap; }
tr.inactivo td { color: var(--muted); }
.vacio { padding: 28px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 500; background: #eef0f4; color: #475467; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.no { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--primary-soft); color: var(--primary); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- Modal ---------- */
.modal-fondo {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .45); display: flex; align-items: flex-start;
  justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto;
}
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 640px; box-shadow: 0 20px 40px rgba(0,0,0,.2); }
.modal.ancho { max-width: 960px; }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal header h2 { margin: 0; }
.modal header button { border: none; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal .cuerpo { padding: 20px; }
.modal footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.error-form { background: var(--danger-soft); color: var(--danger); padding: 9px 12px; border-radius: 6px; margin-bottom: 14px; }

/* ---------- Toast ---------- */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #1c2430; color: #fff; padding: 10px 16px; border-radius: 6px; box-shadow: var(--shadow); max-width: 380px; animation: entra .2s ease-out; }
.toast.error { background: var(--danger); }
@keyframes entra { from { transform: translateY(10px); opacity: 0; } }

/* ---------- Login ---------- */
.login-fondo { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(160deg, #12223b, #24406b); }
.login { background: #fff; width: 100%; max-width: 380px; border-radius: 12px; padding: 32px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.login h1 { margin-bottom: 4px; }
.login p { color: var(--muted); margin: 0 0 22px; }
.login .form { grid-template-columns: 1fr; }
.login .btn { width: 100%; justify-content: center; padding: 10px; margin-top: 6px; }

/* ---------- Roles ---------- */
.roles-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 16px; align-items: start; }
.lista-roles { padding: 6px; }
.lista-roles button {
  display: block; width: 100%; text-align: left; border: none; background: none; padding: 10px 12px;
  border-radius: 6px; cursor: pointer; font: inherit;
}
.lista-roles button:hover { background: #f4f6f9; }
.lista-roles button.activo { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.lista-roles button small { display: block; color: var(--muted); font-weight: 400; }
.matriz td, .matriz th { padding: 6px 10px; }
.matriz td.c, .matriz th.c { text-align: center; width: 70px; }
.matriz tr.grupo td { background: #f4f6f9; font-weight: 600; font-size: 13px; }
.matriz .especial { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; }

/* ---------- Auditoría ---------- */
.diff { font-size: 12.5px; margin: 0; padding: 0; list-style: none; }
.diff li { margin: 2px 0; }
.diff .antes { color: var(--danger); text-decoration: line-through; }
.diff .despues { color: var(--ok); }

/* ---------- Inicio ---------- */
.tarjetas { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.tarjeta { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); text-decoration: none; color: inherit; }
.tarjeta:hover { border-color: var(--primary); }
.tarjeta strong { display: block; margin-bottom: 4px; }
.tarjeta span { color: var(--muted); font-size: 13px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .topbar { display: flex; }
  .sidebar { position: fixed; left: -260px; z-index: 40; transition: left .2s; }
  .sidebar.abierta { left: 0; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .contenido { padding: 16px; }
  .form { grid-template-columns: 1fr; }
  .roles-layout { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 1100px) {
  .roles-layout { grid-template-columns: minmax(0, 1fr); }
  .lista-roles { display: flex; flex-wrap: wrap; gap: 4px; }
  .lista-roles button { width: auto; }
}

/* ---------- Inventario ---------- */
.tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.tab {
  border: none; background: none; font: inherit; padding: 9px 14px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.activo { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.picker {
  max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px;
  margin-top: 8px; display: flex; flex-direction: column; gap: 4px;
}
.picker label.check { gap: 10px; }
.datos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 18px; }
.grilla td { padding: 5px 6px; vertical-align: middle; }
.grilla input, .grilla select { padding: 5px 7px; min-width: 90px; }
tr.fila-error td { background: var(--danger-soft); }
@media (max-width: 860px) { .datos { grid-template-columns: 1fr 1fr; } }
td.nowrap, th.nowrap { white-space: nowrap; }
td.col-error { min-width: 280px; }

/* ---------- Comercial ---------- */
.grilla tfoot td { border-top: 1px solid var(--border); padding: 8px 6px; }

/* ---------- Hoja imprimible (remitos, presupuestos) ---------- */
.hoja { background: #fff; color: #111; max-width: 820px; margin: 0 auto; padding: 36px 40px; border: 1px solid var(--border); border-radius: 4px; }
.hoja-cabecera { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid #111; padding-bottom: 14px; margin-bottom: 18px; font-size: 13px; }
.hoja-empresa { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.hoja-titulo { font-size: 22px; font-weight: 700; letter-spacing: .08em; }
.hoja-bloque { margin: 14px 0; line-height: 1.6; }
.hoja-tabla { width: 100%; border-collapse: collapse; margin: 16px 0; }
.hoja-tabla th, .hoja-tabla td { border: 1px solid #999; padding: 7px 10px; background: none; color: #111; font-size: 13px; text-transform: none; letter-spacing: 0; }
.hoja-firmas { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; margin-top: 70px; text-align: center; font-size: 12px; }
.hoja-firmas div { border-top: 1px solid #111; padding-top: 6px; }

@media print {
  .sidebar, .topbar, .no-print, .toasts { display: none !important; }
  body { background: #fff; }
  .contenido { padding: 0; max-width: none; }
  .hoja { border: none; padding: 0; max-width: none; }
}
.hoja-tabla tr:last-child td { border-bottom: 1px solid #999; }
td.num, td:first-child { white-space: nowrap; }
.nominas-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 14px; }
.nominas-grid .campo { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
tr.echeq-fila td { background: var(--primary-soft); padding: 8px 10px; }
.echeq-datos { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 12px; }
.echeq-datos .campo { display: flex; flex-direction: column; gap: 3px; font-size: 12px; }
@media (max-width: 860px) { .echeq-datos { grid-template-columns: 1fr; } }
table.balance tr.grupo-dep td { background: #f4f6f9; border-top: 1px solid var(--border); }
table.balance th.num { white-space: normal; min-width: 90px; }
table.balance tfoot td { border-top: 2px solid var(--border); }
.tilde-echeq { display: flex; align-items: center; justify-content: flex-start; gap: 6px; margin-top: 4px; font-size: 12px; white-space: nowrap; }
.tilde-echeq[hidden] { display: none; }
.tilde-echeq input { width: auto; margin: 0; }
.nominas div { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; white-space: nowrap; }
