/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

.computing-units-selection {
  display: grid;
  grid-template-columns: 1fr;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.computing-units-selection.metrics-visible {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  width: 100%;
  gap: 10px;
}

/* Add specific styling for the dropdown button when metrics are visible */
.metrics-visible .computing-units-dropdown-button {
  margin-left: auto;
}

.computing-units-dropdown {
  min-width: 350px;
  max-width: 350px;
  max-height: 50vh;
  overflow-y: auto;

  .computing-unit-option {
    .computing-unit-row {
      display: flex;
      justify-content: space-between;
      align-items: center;

      .computing-unit-name {
        display: flex;
        align-items: center;
        gap: 5px;
        max-width: calc(100% - 20px);

        span {
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }

        .unit-status-indicator {
          font-size: 0.85em;
          margin-left: 4px;
          opacity: 0.8;
          font-style: italic;
        }
      }

      .computing-unit-terminate-icon {
        visibility: visible;
      }
    }

    &:hover {
      .computing-unit-terminate-icon {
        visibility: visible;
      }
    }

    &.unit-connecting {
      color: #1890ff; // Blue
    }

    &.unit-disconnected {
      color: #ff4d4f; // Red
    }

    &.unit-terminating {
      color: #faad14; // Yellow/Orange
    }

    // Make disabled units visually distinct
    &[disabled] {
      opacity: 0.6;
      cursor: not-allowed !important;

      .unit-status-indicator {
        opacity: 1;
        font-weight: 500;
      }

      // Still allow termination of non-running units
      .computing-unit-terminate-icon {
        opacity: 1;
        cursor: pointer !important;

        &:hover {
          color: #ff4d4f;
        }
      }
    }
  }

  .create-computing-unit {
    display: flex;
    align-items: center;
    gap: 5px;
  }
}

.create-computing-unit {
  display: flex;
  gap: 10px;
  justify-content: start;
  align-items: center;
}

.computing-unit-option {
  padding: 0 !important;
  display: block;
  width: 100%;
}

.computing-unit-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 5px 12px; /* match nz-menu-item padding */
  box-sizing: border-box;
  gap: 10px;
}

.computing-unit-name {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-grow: 1;
}

.computing-unit-terminate-icon {
  flex-shrink: 0;
  color: #ff4d4f;
  cursor: pointer;
  margin-left: auto;
  opacity: 0.85;
}

.computing-unit-terminate-icon:hover {
  opacity: 1;
  transform: scale(1.1);
}

.memory-selection,
.cpu-selection,
.gpu-selection {
  width: 100%;
}

.jvm-memory-slider {
  width: 100%;
  margin: 10px 0;
}

.memory-warning {
  margin-top: 10px;
  font-size: 0.9em;
}

.create-compute-unit-container {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  justify-content: start;
  align-items: center;
}

.select-unit {
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: center;
  align-items: start;
}

.select-unit.name-field {
  grid-column: span 2;
}

.unit-name-input {
  width: 100%;
}

.computing-units-dropdown-button {
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  padding: 0 8px;
}

.button-content {
  display: flex;
  align-items: center;
  width: 100%;
  height: 100%;
}

.unit-name-text,
.connect-text {
  margin-left: 4px;
  margin-right: 4px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
}

/* Ensure the dropdown icon is aligned properly */
.button-content i.ant-dropdown-trigger {
  margin-left: auto;
}

/* Badge alignment fix */
:host ::ng-deep .ant-badge-status-dot {
  position: relative;
  top: -1px;
  vertical-align: middle;
}

.metrics-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 32px;
  width: 120px;
  min-width: 120px;
  padding: 0;
  border: none;
  flex-shrink: 0; /* Prevent shrinking */
}

.metric-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 12px;
}

.metric-label {
  font-size: 10px;
  width: 45px;
  flex-shrink: 0;
  line-height: 1;
}

.metric-bar-wrapper {
  flex-grow: 1;
  width: 90px; /* Fixed width for consistent bar size */
  min-width: 60px; /* Ensure minimum width for the bar */
  display: flex;
  align-items: center;
  padding: 0;
  height: 8px; /* tightly fits the bar */
}

#cpu-progress-bar,
#memory-progress-bar {
  width: 100%;
  margin: 0 !important; /* Remove any margins */
  padding: 0 !important; /* Remove any padding */
  vertical-align: middle;
}

/* Override any Ant Design styles that might affect the progress bar */
:host ::ng-deep .ant-progress {
  width: 100%;
}

:host ::ng-deep .ant-progress-inner {
  width: 100% !important;
}

.resource-metrics {
  width: 250px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(1, 1fr);
  justify-content: start;
  align-items: center;
  gap: 5px;
}

.general-metric {
  display: flex;
  flex-direction: column;
  width: 100%;
  background-color: #f9fafb;
  border-radius: 3px;
  padding: 10px;
  gap: 3px;
}

.metric-unit {
  color: #888;
  font-size: 0.9em;
  margin-left: 4px;
}

.metric-percentage {
  color: #555;
  font-size: 0.9em;
  margin-left: 6px;
  font-weight: 500;
}

.metric-name {
  font-size: 10px;
  margin: 0;
}

.metric-value {
  margin: 0;
}

.shared-memory-group {
  width: 100%;

  .shm-input-row {
    display: flex;
    gap: 8px;
    align-items: center;
    width: 100%;
  }

  .shm-size-input {
    width: 60px;
    min-width: 50px;
    flex-shrink: 0;
  }

  .shm-unit-select {
    width: 80px;
    min-width: 70px;
    flex-shrink: 0;
  }

  .shm-warning {
    margin-top: 4px;
    font-size: 12px;
    color: #faad14;
    white-space: nowrap;
  }
}

.unit-name-edit-input {
  width: 100%;
  max-width: 200px;
  font-size: inherit;
  border: 1px solid #d9d9d9;
  border-radius: 2px;
  padding: 2px 6px;
  background: white;

  &:focus {
    border-color: #40a9ff;
    box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
    outline: none;
  }
}
