:root {
  --azul: #0b3d91;
  --azul-claro: #eaf1fb;
  --verde: #1a7d4b;
  --gris: #f4f6f8;
  --texto: #1f2937;
  --borde: #dbe2ea;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--gris);
  color: var(--texto);
}
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 260px;
  background: var(--azul);
  color: white;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
}
.sidebar h1 { margin: 0; font-size: 22px; }
.sidebar .sub { font-size: 12px; opacity: 0.8; margin-bottom: 24px; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-btn {
  text-align: left;
  background: none;
  border: none;
  color: white;
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13.5px;
}
.nav-btn:hover { background: rgba(255,255,255,0.1); }
.nav-btn.active { background: white; color: var(--azul); font-weight: 600; }
.ambiente-badge {
  margin-top: 16px;
  padding: 8px;
  background: #f0a500;
  color: #3a2900;
  border-radius: 6px;
  font-size: 12px;
  text-align: center;
  font-weight: 600;
}

.btn-nuevo-dte {
  background: #1a7d4b;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  margin-bottom: 16px;
  width: 100%;
}
.btn-nuevo-dte:hover { background: #15613a; }

.menu-nuevo-dte { display: flex; flex-direction: column; gap: 8px; padding: 16px; }
.menu-nuevo-dte button {
  text-align: left; background: var(--azul-claro); color: var(--azul); border: none;
  border-radius: 8px; padding: 12px 14px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.menu-nuevo-dte button:hover { background: #d3e3f7; }
.menu-nuevo-dte button .desc { display: block; font-weight: 400; font-size: 12px; color: #4b5563; margin-top: 2px; }

.content { flex: 1; padding: 28px 36px; overflow-y: auto; }
.view { display: none; }
.view.active { display: block; }
h2 { margin-top: 0; color: var(--azul); }
h3 { color: var(--azul); margin-top: 28px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin: 20px 0; }
.card {
  background: white; border: 1px solid var(--borde); border-radius: 10px;
  padding: 16px; text-align: center;
}
.card .num { font-size: 26px; font-weight: 700; color: var(--azul); }
.card .label { font-size: 12px; color: #6b7280; margin-top: 4px; }
.hint { color: #6b7280; font-size: 13px; }
.checkbox-inline { display: flex; align-items: center; gap: 6px; font-weight: normal; margin: 10px 0; }
.checkbox-inline input { width: auto; }

.doc-form { background: white; border: 1px solid var(--borde); border-radius: 10px; padding: 20px; max-width: 900px; }
fieldset { border: 1px solid var(--borde); border-radius: 8px; margin-bottom: 16px; padding: 14px; }
legend { font-weight: 600; color: var(--azul); padding: 0 6px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label { display: flex; flex-direction: column; font-size: 12.5px; color: #4b5563; gap: 4px; }
input, select { padding: 8px; border: 1px solid var(--borde); border-radius: 6px; font-size: 13.5px; }

.items-table { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.item-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 1fr auto; gap: 8px; align-items: end; }
.item-row.liquidacion-row { grid-template-columns: 1fr 2fr 1fr 1fr auto; }
.item-row button { background: #fde2e2; border: none; color: #b91c1c; border-radius: 6px; padding: 8px; cursor: pointer; }

.btn-primary, .btn-secondary, .btn-download {
  cursor: pointer; border: none; border-radius: 6px; font-size: 13.5px; padding: 10px 16px; font-weight: 600;
}
.btn-primary { background: var(--azul); color: white; }
.btn-secondary { background: var(--azul-claro); color: var(--azul); margin-top: 4px; }
.btn-download { background: var(--verde); color: white; text-align: left; padding: 14px; border-radius: 8px; }

.result { margin-top: 18px; max-width: 900px; }
.result pre {
  background: #0b1220; color: #d1e8ff; padding: 16px; border-radius: 8px;
  max-height: 420px; overflow: auto; font-size: 12px;
}
.result .ok { color: var(--verde); font-weight: 600; }
.result .err { color: #b91c1c; font-weight: 600; }

.filters { margin-bottom: 12px; display: flex; gap: 12px; align-items: end; }
.tabla-docs { width: 100%; border-collapse: collapse; background: white; }
.tabla-docs th, .tabla-docs td { border-bottom: 1px solid var(--borde); padding: 8px 10px; font-size: 13px; text-align: left; }
.tabla-docs th { background: var(--azul-claro); color: var(--azul); }
.estado-PROCESADO { color: var(--verde); font-weight: 600; }
.estado-BORRADOR { color: #9a6b00; font-weight: 600; }
.estado-RECHAZADO, .estado-ANULADO { color: #b91c1c; font-weight: 600; }

.periodo-label { display: inline-flex; flex-direction: column; margin-bottom: 10px; font-size: 13px; }
.libros-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; max-width: 900px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.6);
  display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px;
}
.modal-box {
  background: white; border-radius: 10px; width: 100%; max-width: 900px; max-height: 90vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--borde); font-weight: 600; color: var(--azul);
}
.modal-body { flex: 1; overflow: auto; padding: 0; }
.modal-body iframe { width: 100%; height: 75vh; border: none; }
.modal-body pre {
  margin: 0; padding: 16px; background: #0b1220; color: #d1e8ff; font-size: 12px; white-space: pre-wrap; word-break: break-word;
}

.auth-overlay {
  position: fixed; inset: 0; background: linear-gradient(135deg, var(--azul), #123a70);
  display: flex; align-items: center; justify-content: center; z-index: 2000; padding: 20px;
}
.auth-box {
  background: white; border-radius: 12px; padding: 32px; width: 100%; max-width: 380px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3); text-align: center;
}
.auth-box h1 { margin: 0; color: var(--azul); }
.auth-form { display: flex; flex-direction: column; gap: 12px; text-align: left; margin-top: 12px; }
.auth-form label { display: flex; flex-direction: column; font-size: 12.5px; color: #4b5563; gap: 4px; }
.auth-form input { padding: 10px; border: 1px solid var(--borde); border-radius: 6px; font-size: 14px; }
.auth-form .err { color: #b91c1c; font-size: 12.5px; margin: 4px 0 0; min-height: 1em; }

.usuario-conectado { color: white; font-size: 12px; opacity: 0.85; margin-top: 10px; text-align: center; }
.btn-cerrar-sesion {
  margin-top: 8px; width: 100%; background: rgba(255,255,255,0.12); color: white; border: 1px solid rgba(255,255,255,0.3);
  border-radius: 6px; padding: 8px; font-size: 12.5px; cursor: pointer;
}
.btn-cerrar-sesion:hover { background: rgba(255,255,255,0.22); }
