:root {
  --brand: #1d4a3e;
  --brand-dark: #123329;
  --brand-light: #e8f2ee;
  --accent: #c98a3e;
}

html {
  overflow-x: hidden;
}

body {
  background: #f4f6f5;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: #21302b;
  overflow-x: hidden;
  width: 100%;
}

.app-navbar {
  background: linear-gradient(90deg, var(--brand-dark), var(--brand));
}

.app-navbar .nav-link {
  font-weight: 500;
}

.app-navbar .nav-link:hover {
  color: var(--accent) !important;
}

/* ==========================================================================
   Menú lateral izquierdo (sidebar)
   ========================================================================== */
:root {
  --sidebar-width: 260px;
}

.app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: linear-gradient(180deg, var(--brand-dark), var(--brand));
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transform: translateX(0);
  transition: transform .25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.1rem;
  color: #fff;
  font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,.12);
  flex-shrink: 0;
}
.sidebar-brand a {
  color: #fff;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.btn-sidebar-close {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1.1rem;
}

.sidebar-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: .75rem 0;
}

.sidebar-nav {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-nav .nav-item {
  margin: .1rem .6rem;
}

.app-sidebar .nav-link,
.sidebar-user .nav-link {
  display: flex;
  align-items: center;
  gap: .6rem;
  color: rgba(255,255,255,.85);
  padding: .55rem .75rem;
  border-radius: 8px;
  font-weight: 500;
  font-size: .93rem;
  text-decoration: none;
  transition: background .15s ease, color .15s ease;
}

.app-sidebar .nav-link:hover {
  background: rgba(255,255,255,.08);
  color: #fff;
}

.app-sidebar .nav-link.active {
  background: var(--accent);
  color: #fff;
}

.submenu-toggle {
  justify-content: space-between;
}
.submenu-toggle span:first-of-type,
.submenu-toggle .bi:first-child {
  margin-right: 0;
}
.submenu-caret {
  margin-left: auto;
  font-size: .75rem;
  transition: transform .2s ease;
}
.submenu-toggle.open .submenu-caret {
  transform: rotate(180deg);
}

.submenu-list {
  list-style: none;
  margin: .15rem 0 .25rem 0;
  padding: 0 0 0 1.6rem;
}
.submenu-link {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: rgba(255,255,255,.72);
  padding: .4rem .6rem;
  border-radius: 6px;
  font-size: .87rem;
  text-decoration: none;
}
.submenu-link:hover {
  background: rgba(255,255,255,.08);
  color: #fff;
}
.submenu-divider {
  border-color: rgba(255,255,255,.15);
  margin: .3rem .6rem;
}

.sidebar-section-title {
  padding: .9rem 1.1rem .3rem;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: rgba(255,255,255,.5);
}

.sidebar-user {
  border-top: 1px solid rgba(255,255,255,.12);
  padding: .6rem;
  flex-shrink: 0;
}
.sidebar-user .text-badge {
  color: rgba(255,255,255,.65);
  font-weight: 400;
}

/* Contenido desplazado a la derecha del sidebar */
.content-wrapper {
  margin-left: var(--sidebar-width);
  width: calc(100% - var(--sidebar-width));
  max-width: calc(100% - var(--sidebar-width));
  box-sizing: border-box;
}

/* Las tablas anchas no deben romper el layout: que hagan scroll horizontal
   propio dentro de su contenedor en lugar de desbordar la página */
.content-wrapper .table-responsive {
  -webkit-overflow-scrolling: touch;
}

/* Barra superior solo visible en móvil */
.mobile-topbar {
  position: sticky;
  top: 0;
  z-index: 1030;
  display: flex;
  align-items: center;
  gap: .75rem;
  background: linear-gradient(90deg, var(--brand-dark), var(--brand));
  color: #fff;
  padding: .7rem 1rem;
}
.btn-sidebar-toggle {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1.4rem;
  line-height: 1;
}
.mobile-brand {
  color: #fff;
  text-decoration: none;
  font-weight: 700;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 1035;
}
.sidebar-overlay.show {
  display: block;
}

/* Colapsar el sidebar fuera de pantalla en móvil/tablet */
@media (max-width: 991.98px) {
  .app-sidebar {
    transform: translateX(-100%);
  }
  .app-sidebar.show {
    transform: translateX(0);
  }
  .content-wrapper {
    margin-left: 0;
    width: 100%;
    max-width: 100%;
  }
}

/* Un poco más de aire lateral en pantallas muy angostas */
@media (max-width: 575.98px) {
  .content-wrapper.container-fluid,
  footer.content-wrapper {
    padding-left: .85rem;
    padding-right: .85rem;
  }
  .stat-card {
    padding: 1rem 1.1rem;
  }
  .stat-card .stat-value {
    font-size: 1.6rem;
  }
}

.card {
  border: none;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(18, 51, 41, 0.08);
}

.card-header {
  background: var(--brand-light);
  border-bottom: 1px solid rgba(29, 74, 62, 0.1);
  font-weight: 600;
  color: var(--brand-dark);
  border-radius: 12px 12px 0 0 !important;
}

.btn-primary {
  background-color: var(--brand);
  border-color: var(--brand);
}
.btn-primary:hover, .btn-primary:focus {
  background-color: var(--brand-dark);
  border-color: var(--brand-dark);
}

.btn-accent {
  background-color: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-accent:hover { color: #fff; opacity: .9; }

.stat-card {
  border-radius: 14px;
  padding: 1.25rem 1.5rem;
  color: #fff;
}
.stat-card.bg-1 { background: linear-gradient(135deg, #1d4a3e, #2c6b58); }
.stat-card.bg-2 { background: linear-gradient(135deg, #c98a3e, #e0a75c); }
.stat-card.bg-3 { background: linear-gradient(135deg, #2b5f9e, #4b83c4); }
.stat-card.bg-4 { background: linear-gradient(135deg, #8a2b3e, #b5445c); }
.stat-card .stat-value { font-size: 2rem; font-weight: 700; }
.stat-card .stat-label { font-size: .85rem; opacity: .85; text-transform: uppercase; letter-spacing: .04em; }

.table thead th {
  background: var(--brand-light);
  color: var(--brand-dark);
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  border-bottom: none;
}

.linea-detalle { border: 1px solid #dfe6e2; border-radius: 10px; padding: .9rem; margin-bottom: .75rem; background: #fbfcfb; }
.linea-detalle .remove-linea { cursor: pointer; }

.cabys-resultado { cursor: pointer; }
.cabys-resultado:hover { background: var(--brand-light); }

.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--brand-dark), var(--brand));
}
.login-card { max-width: 400px; width: 100%; border-radius: 16px; }

code.clave { word-break: break-all; font-size: .8rem; }

/* Actualización automática de estados de documentos */
@keyframes estado-flash {
  0%   { box-shadow: 0 0 0 0 rgba(25, 135, 84, .55); }
  100% { box-shadow: 0 0 0 8px rgba(25, 135, 84, 0); }
}
.estado-actualizado { animation: estado-flash 1s ease-out 2; }

.indicador-live { display: inline-flex; align-items: center; gap: .4rem; }
.indicador-live .punto {
  width: 8px; height: 8px; border-radius: 50%;
  background: #198754; display: inline-block;
  animation: punto-pulso 1.4s ease-in-out infinite;
}
@keyframes punto-pulso {
  0%, 100% { opacity: .35; transform: scale(0.85); }
  50%      { opacity: 1;   transform: scale(1); }
}
