:root {
  --marca: #0f4c81; --marca-osc: #0b3a63; --fondo: #f4f6f9; --panel: #fff;
  --texto: #1d2733; --suave: #6b7785; --borde: #e2e7ee; --ok: #1f8a4c; --error: #c0392b;
  --ambar: #b7791f; --radio: 8px;
  font-family: Inter, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--fondo); color: var(--texto); font-size: 14px; }
a { color: var(--marca); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Estructura */
.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.lateral { background: var(--marca-osc); color: #dfe8f2; padding: 18px 0; position: sticky;
  top: 0; height: 100vh; overflow-y: auto; }
.lateral .logo { font-weight: 700; font-size: 18px; color: #fff; padding: 0 20px 18px; display: block; }
.lateral h6 { margin: 16px 20px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: #8fa9c4; }
.lateral a { display: block; padding: 7px 20px; color: #dfe8f2; }
.lateral a:hover, .lateral a.activo { background: rgba(255,255,255,.1); text-decoration: none; color: #fff; }
.principal { min-width: 0; }
.barra { display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: var(--panel);
  border-bottom: 1px solid var(--borde); position: sticky; top: 0; z-index: 5; }
.barra form { flex: 1; }
.barra input[type=search] { width: 100%; max-width: 480px; }
.barra .usuario { color: var(--suave); white-space: nowrap; }
.contenido { padding: 24px; max-width: 1400px; }
.cabecera { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 16px; flex-wrap: wrap; }
.cabecera h1 { font-size: 22px; margin: 0; }
.menu-movil { display: none; }

/* Paneles y tarjetas */
.panel { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio);
  padding: 18px; margin-bottom: 16px; }
.panel h2 { font-size: 15px; margin: 0 0 12px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px;
  margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); padding: 16px; }
.kpi .t { color: var(--suave); font-size: 12px; }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 4px; }
.rejilla { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; }

/* Tablas */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--borde); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--suave); font-weight: 600; background: #fafbfc; }
td.n, th.n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr:hover td { background: #fafcff; }
tfoot td { font-weight: 700; }
.tabla-scroll { overflow-x: auto; }

/* Formularios */
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid #cfd7e1; border-radius: 6px;
  background: #fff; width: 100%; }
input[type=checkbox], input[type=radio] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid #b9d3ee; border-color: var(--marca); }
.campos { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px 16px; }
.campo label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 4px; color: #3d4a59; }
.campo .ayuda { font-size: 11px; color: var(--suave); margin-top: 3px; }
.campo .err, .errorlist { color: var(--error); font-size: 12px; margin: 3px 0 0; padding: 0; list-style: none; }
.campo.check label { display: flex; gap: 8px; align-items: center; }
.campo.ancho { grid-column: 1 / -1; }
.filtros { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filtros input, .filtros select { width: auto; }

/* Botones */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 6px;
  border: 1px solid #cfd7e1; background: #fff; color: var(--texto); cursor: pointer; font: inherit;
  white-space: nowrap; }
.btn:hover { background: #f1f4f8; text-decoration: none; }
.btn-p { background: var(--marca); border-color: var(--marca); color: #fff; }
.btn-p:hover { background: var(--marca-osc); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-peligro { color: var(--error); border-color: #e6b0aa; }
.btn-s { padding: 4px 9px; font-size: 12px; }
.acciones { display: flex; gap: 8px; flex-wrap: wrap; }
form.inline { display: inline; }

/* Etiquetas de estado */
.etq { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; }
.etq-gris { background: #eceff3; color: #59636e; } .etq-azul { background: #e3eefb; color: #1b5fa8; }
.etq-verde { background: #e2f4ea; color: #1f7a45; } .etq-rojo { background: #fbe5e3; color: #a93226; }
.etq-ambar { background: #fdf1dc; color: #9a6411; } .etq-morado { background: #efe7fb; color: #6b3fb0; }

/* Mensajes */
.mensajes { list-style: none; padding: 0; margin: 0 0 16px; }
.mensajes li { padding: 10px 14px; border-radius: 6px; margin-bottom: 6px; }
.mensajes .success { background: #e2f4ea; color: #1b6b3d; }
.mensajes .error { background: #fbe5e3; color: #922b21; }
.mensajes .warning, .mensajes .info { background: #fdf1dc; color: #7d520e; }
.aviso { background: #fdf1dc; border: 1px solid #f3d7a1; padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; }

/* Líneas de documento */
.lineas td { padding: 4px; } .lineas input, .lineas textarea { padding: 5px 7px; }
.lineas .c-concepto { min-width: 260px; } .lineas .c-num { width: 95px; }
.autocompletar { position: absolute; background: #fff; border: 1px solid var(--borde); border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0,0,0,.12); z-index: 20; max-height: 260px; overflow-y: auto; min-width: 320px; }
.autocompletar div { padding: 7px 10px; cursor: pointer; } .autocompletar div:hover { background: #eef4fb; }
.totales { margin-left: auto; max-width: 360px; } .totales td { border: 0; padding: 4px 8px; }
.totales tr.total td { font-size: 17px; font-weight: 700; border-top: 2px solid var(--texto); }

/* Gráfico de barras */
.grafico { display: flex; align-items: flex-end; gap: 6px; height: 170px; padding-top: 10px; }
.grafico .mes { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; }
.grafico .barras { flex: 1; display: flex; align-items: flex-end; gap: 2px; width: 100%; justify-content: center; }
.grafico .b { width: 40%; border-radius: 3px 3px 0 0; min-height: 1px; }
.grafico .bv { background: var(--marca); } .grafico .bc { background: #9fb7cf; }
.grafico small { font-size: 10px; color: var(--suave); }

/* Login */
.login { max-width: 380px; margin: 12vh auto; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .lateral { display: none; position: fixed; z-index: 30; width: 250px; }
  .lateral.abierto { display: block; }
  .menu-movil { display: inline-flex; }
  .contenido { padding: 14px; }
  .rejilla { grid-template-columns: 1fr; }
}
