/* Control Ganadero — menú lateral y acentos */

$ranch-sidebar-width: 280px;

.vertical:not(.collapsible-vertical) {
    .sidebar-wrapper {
        width: $ranch-sidebar-width;
    }

    #content {
        margin-left: $ranch-sidebar-width;
    }

    /* Al cerrar el menú, el contenido usa todo el ancho */
    &.sidebar-closed > .sidebar-wrapper {
        left: -($ranch-sidebar-width + 20px);
    }

    &.sidebar-closed #content,
    &.sidebar-closed > #content {
        margin-left: 0 !important;
    }
}

.collapsible-vertical .sidebar-closed > .sidebar-wrapper:hover {
    width: $ranch-sidebar-width;
}

/* Fondo sólido del sidebar (antes transparente / “feo”) */
.sidebar-wrapper.sidebar-theme {
    background: #fff !important;
    border: 1px solid #e0e6ed;
    box-shadow: 0 4px 18px rgba(27, 67, 50, 0.08);
    border-radius: 10px 10px 0 0;
}

.sidebar-wrapper #sidebar ul.menu-categories li.menu > a,
.sidebar-wrapper #sidebar ul.menu-categories li.menu > .dropdown-toggle {
  overflow: visible !important;
  white-space: normal !important;

  span {
    overflow: visible !important;
    white-space: normal !important;
    text-overflow: unset !important;
  }
}

.sidebar-wrapper {
  #sidebar {
    background: #fff;
    border-radius: 10px 10px 0 0;

    ul.menu-categories {
      &.ps {
        border-right: none;
        padding-right: 10px;
      }

      li.menu {
        > a,
        > .dropdown-toggle {
          display: flex;
          align-items: flex-start;
          gap: 10px;
          padding: 10px 14px;
          line-height: 1.35;
          white-space: normal;
          border-radius: 8px;
          margin: 2px 6px;

          svg {
            flex-shrink: 0;
            margin-top: 1px;
            margin-right: 0;
          }

          span {
            white-space: normal;
            overflow: visible;
            text-overflow: unset;
            line-height: 1.35;
          }
        }

        /* Rama activa (sección donde estás) */
        &.active > .dropdown-toggle {
          background: linear-gradient(
            135deg,
            rgba(var(--ranch-accent-rgb), 0.14) 0%,
            rgba(var(--ranch-accent-rgb), 0.08) 100%
          ) !important;
          box-shadow: none !important;
          border-left: 3px solid var(--ranch-accent);
          color: var(--ranch-accent-dark) !important;

          svg {
            color: var(--ranch-accent) !important;
            fill: transparent !important;
          }

          span {
            color: var(--ranch-accent-dark) !important;
            font-weight: 700;
          }
        }

        &.menu-section .menu-section-title {
          white-space: nowrap;
        }
      }
    }

    ul.menu-categories li.menu > a.router-link-active,
    ul.menu-categories li.menu > a.active {
      background: linear-gradient(
        135deg,
        rgba(var(--ranch-accent-rgb), 0.12) 0%,
        rgba(var(--ranch-accent-rgb), 0.08) 100%
      ) !important;
      border-left: 3px solid var(--ranch-accent);

      svg {
        color: var(--ranch-accent) !important;
      }

      span {
        color: var(--ranch-accent-dark);
        font-weight: 600;
      }
    }

    ul.submenu {
      margin: 0 6px 6px;
      padding: 4px 0;
      background: #f4f7f5;
      border-radius: 8px;

      > li a {
        border-radius: 6px;
        margin-right: 4px;
      }

      > li a.active,
      > li a.router-link-active {
        color: var(--ranch-accent-dark) !important;
        font-weight: 600;
        background: rgba(var(--ranch-accent-rgb), 0.12);
      }

      > li a.active:before,
      > li a.router-link-active:before {
        background-color: var(--ranch-accent) !important;
      }

      > li.active > .dropdown-toggle {
        color: var(--ranch-accent-dark) !important;
        font-weight: 600;
      }
    }

    ul.sub-submenu {
      background: rgba(255, 255, 255, 0.7);
      border-radius: 6px;
      margin: 2px 8px 6px 20px;

      > li a.active,
      > li a.router-link-active {
        color: var(--ranch-accent-dark) !important;
        font-weight: 600;
      }
    }
  }
}

.ranch-sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px 12px;
  margin-bottom: 4px;
  border-bottom: 1px solid #e0e6ed;
  background: #fff;

  .ranch-sidebar-brand-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--ranch-accent) 0%, var(--ranch-accent-light) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;

    svg {
      color: #fff;
      width: 22px;
      height: 22px;
    }
  }

  .ranch-sidebar-brand-text {
    min-width: 0;

    strong {
      display: block;
      font-size: 14px;
      font-weight: 700;
      color: var(--ranch-accent-dark);
      line-height: 1.2;
    }

    small {
      display: block;
      font-size: 11px;
      color: #888ea8;
      letter-spacing: 0.02em;
    }
  }
}

/* Overlay solo en móvil cuando el menú está abierto como drawer */
@media (min-width: 992px) {
  .main-container > .overlay.show {
    display: none !important;
  }
}

/* Tabs módulo engorda */
.ranch-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  border-bottom: 1px solid #e0e6ed;
  margin-bottom: 1.25rem;
  padding-bottom: 0;

  .ranch-tab {
    appearance: none;
    border: none;
    background: transparent;
    color: #515365;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.65rem 1rem;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    border-radius: 6px 6px 0 0;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s;

    &:hover {
      color: var(--ranch-accent-dark);
      background: rgba(var(--ranch-accent-rgb), 0.06);
    }

    &.is-active {
      color: var(--ranch-accent-dark);
      font-weight: 700;
      border-bottom-color: var(--ranch-accent);
      background: rgba(var(--ranch-accent-rgb), 0.08);
    }
  }
}

.ranch-kpi-grid {
  .card {
    border: 1px solid #e0e6ed;
    box-shadow: none;

    small {
      color: #888ea8;
      font-size: 0.75rem;
      display: block;
      margin-bottom: 0.25rem;
    }

    h5 {
      font-size: clamp(0.82rem, 1.6vw, 1.05rem);
      font-weight: 700;
      color: var(--ranch-accent-dark);
      white-space: normal;
      overflow: visible;
      text-overflow: unset;
      word-break: break-word;
      margin: 0;
      line-height: 1.35;
    }
  }
}

@media (max-width: 991px) {
    .sidebar-wrapper {
        width: min(92vw, $ranch-sidebar-width) !important;
        border-radius: 0;
    }

    #sidebar ul.menu-categories.ps {
        height: calc(100vh - 120px) !important;
    }
}

/* Menú horizontal: acento del rancho + ítem activo */
.horizontal .topbar-nav.header nav.topbar ul.menu-categories li.menu {
  &.active > a > div span,
  &:hover > a > div span {
    color: var(--ranch-accent) !important;
  }

  &.active > a svg,
  &:hover > a svg {
    color: var(--ranch-accent) !important;
  }

  .submenu li a.active,
  .submenu li a.router-link-active {
    color: var(--ranch-accent-dark) !important;
    background: rgba(var(--ranch-accent-rgb), 0.1) !important;
  }

  .submenu li:hover > a {
    color: var(--ranch-accent-dark) !important;
    background: rgba(var(--ranch-accent-rgb), 0.08) !important;
  }
}
