@use "../abstracts/variables" as *;

/**
 * -----------------------------------------------------------------------------
 * Database Observability Component
 * -----------------------------------------------------------------------------
 * Analysis-focused layout for the database dashboard tab.
 * -----------------------------------------------------------------------------
 */

.no-database-observability {
  display: flex;
  flex-direction: column;
  gap: $spacing-md;
  min-width: 0;

  &__body {
    display: flex;
    flex-direction: column;
    gap: $spacing-md;
  }

  &__disabled-help {
    margin-top: $spacing-sm;
    color: $color-text-muted;
    font-size: $font-size-sm;
    line-height: 1.6;
  }

  &__main-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.8fr) minmax(320px, 0.95fr);
    gap: $spacing-md;
    align-items: start;
  }

  &__main-column,
  &__side-column {
    display: flex;
    flex-direction: column;
    gap: $spacing-md;
    min-width: 0;
  }
}

.no-db-overview-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.no-db-overview-card {
  display: flex;
  flex-direction: column;
  min-height: 128px;
  padding: 16px 18px;
  border: 1px solid $color-border;
  border-radius: $radius-card;
  background: $color-card-bg;
  box-shadow: $shadow-soft;
  gap: 10px;

  &__title {
    color: $color-text-soft;
    font-size: $font-size-sm;
    font-weight: 700;
  }

  &__value {
    letter-spacing: -0.02em;
    color: $color-text-strong;
    font-size: 30px;
    font-weight: 800;
    line-height: 1.05;
  }

  &__description {
    color: $color-text-muted;
    font-size: $font-size-sm;
    line-height: 1.6;
  }
}

.no-db-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: $spacing-md;
  border: 1px solid $color-border;
  border-radius: $radius-card;
  background: $color-panel-bg;
  box-shadow: $shadow-soft;
  gap: 14px;

  &--full {
    margin-top: 4px;
  }

  &__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: $spacing-sm;

    &--split {
      align-items: center;
    }
  }

  &__content {
    min-width: 0;
  }

  &__title {
    margin: 0;
    color: $color-text-strong;
    font-size: $font-size-lg;
    font-weight: 700;
  }
}

.no-db-threshold {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  white-space: nowrap;
  color: $color-status-warning-text;
  border-radius: $radius-pill;
  background: $color-status-warning-bg;
  font-size: $font-size-xs;
  font-weight: 700;
}

.no-db-route-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;

  &__path {
    word-break: normal;
    color: $color-text-muted;
    font-size: $font-size-sm;
    overflow-wrap: anywhere;
  }
}

.no-db-route-trigger,
.no-db-modal-trigger {
  padding: 0;
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  color: $color-blue;
  border: 0;
  background: transparent;

  &:hover,
  &:focus {
    color: $color-status-info-text;
  }
}

.no-db-table-actions {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.no-db-hotspots {
  display: flex;
  flex-direction: column;
  gap: $spacing-md;

  &__group {
    display: flex;
    flex-direction: column;
    gap: $spacing-sm;
  }

  &__label {
    margin: 0;
    color: $color-text;
    font-size: $font-size-md;
    font-weight: 700;
  }

  &__list {
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
    list-style: none;
    gap: $spacing-sm;
  }

  &__item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 14px;
    border: 1px solid $color-border-soft;
    border-radius: 12px;
    background: $color-surface-soft;
  }

  &__main {
    word-break: normal;
    color: $color-text-strong;
    font-size: $font-size-sm;
    font-weight: 700;
    overflow-wrap: anywhere;
  }

  &__meta {
    color: $color-text-muted;
    font-size: $font-size-xs;
  }
}

.no-db-records-table {
  thead th.is-sortable {
    cursor: pointer;
    user-select: none;
  }
}

.no-db-table-empty-state {
  margin-top: 10px;
}

.no-db-pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 8px;

  &__status {
    min-width: 80px;
    text-align: center;
  }
}

.no-dashboard-chart {
  &--database-pressure,
  &--database-scatter {
    min-height: 320px;
  }
}

.no-db-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;

  &__backdrop {
    position: absolute;
    inset: 0;
    background: rgb(15, 23, 42, 0.45);
  }

  &__dialog {
    position: relative;
    z-index: 1;
    display: flex;
    overflow: hidden;
    flex-direction: column;
    width: min(1120px, calc(100vw - 48px));
    max-height: calc(100vh - 48px);
    margin: 24px auto;
    border-radius: $radius-card;
    background: $color-panel-bg;
    box-shadow: $shadow-soft;
  }

  &__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid $color-border;
  }

  &__title {
    margin: 0;
    color: $color-text-strong;
    font-size: $font-size-lg;
    font-weight: 700;
  }

  &__close {
    cursor: pointer;
    color: $color-text-muted;
    border: 0;
    background: transparent;
    font-size: 24px;
    line-height: 1;
  }

  &__body {
    overflow: auto;
    padding: 20px;
  }

  &__summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
  }

  &__summary-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 14px 16px;
    border: 1px solid $color-border-soft;
    border-radius: 12px;
    background: $color-surface-soft;
  }

  &__summary-label {
    color: $color-text-muted;
    font-size: $font-size-xs;
  }

  &__summary-value {
    color: $color-text-strong;
    font-size: $font-size-md;
  }
}

.no-db-routes-empty-state {
  margin-top: 10px;
}

.no-db-routes-table,
.no-db-records-table {
  thead th.is-sortable {
    position: relative;
    cursor: pointer;
    user-select: none;
    transition:
      color 0.2s ease,
      background-color 0.2s ease;

    span {
      display: inline-flex;
      align-items: center;
      gap: 6px;
    }

    &:hover,
    &:focus {
      color: $color-blue;
    }

    &[aria-sort="ascending"] span::after {
      content: "↑";
      color: $color-blue;
      font-size: 12px;
      line-height: 1;
    }

    &[aria-sort="descending"] span::after {
      content: "↓";
      color: $color-blue;
      font-size: 12px;
      line-height: 1;
    }
  }
}

.no-db-table-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 12px;

  &--routes {
    margin-bottom: 6px;
  }

  &__search {
    flex: 1 1 320px;
  }

  .form-text,
  input[type="search"] {
    min-height: 42px;
    padding: 10px 14px;
    color: $color-text;
    border: 1px solid $color-border;
    border-radius: 12px;
    background: $color-panel-bg;

    &:focus {
      border-color: $color-blue;
      outline: 0;
      box-shadow: 0 0 0 3px rgb(59, 130, 246, 0.12);
    }
  }

  &__actions {
    display: flex;
    align-items: center;
    gap: 10px;
  }
}

.no-db-routes-pagination,
.no-db-pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 12px;

  &__status,
  .no-db-routes-pagination__status {
    min-width: 90px;
    text-align: center;
    color: $color-text-muted;
    font-size: $font-size-sm;
  }
}

.no-db-table-tools__actions .button,
.no-db-routes-pagination .button,
.no-db-pagination .button {
  min-width: 94px;
  transition:
    background-color 0.2s ease,
    color 0.2s ease;
  color: $color-text-strong;
  border: 1px solid $color-border;
  border-radius: $radius-pill;
  background: $color-panel-bg;
  box-shadow: none;
  font-weight: 700;
}

.no-db-table-tools__actions .button:hover,
.no-db-table-tools__actions .button:focus,
.no-db-routes-pagination .button:hover,
.no-db-routes-pagination .button:focus,
.no-db-pagination .button:hover,
.no-db-pagination .button:focus {
  color: $color-blue;
  border-color: $color-blue;
  background: $color-surface-soft;
}

.no-db-table-tools__actions .button:disabled,
.no-db-routes-pagination .button:disabled,
.no-db-pagination .button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

@media (max-width: 1200px) {
  .no-db-overview-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .no-database-observability__main-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 767px) {
  .no-db-overview-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .no-db-table-tools {
    align-items: stretch;
  }

  .no-db-pagination {
    flex-wrap: wrap;
    justify-content: center;
  }

  .no-db-modal__dialog {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
    margin: 10px auto;
  }

  .no-db-modal__summary {
    grid-template-columns: minmax(0, 1fr);
  }
}
