// =============================================================================
// Comments Press Zone - Modals, Node Tree & Permissions SCSS
// =============================================================================
// Contains styles for:
// - Node Tree (drag-and-drop structure management)
// - Modal dialogs (admin-only)
// - Permissions table and grid
// - Settings page header
// =============================================================================


// =============================================================================
// NODE TREE COMPONENT
// =============================================================================

.presszone-comments-node-tree {
  &__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;

    h1 {
      margin: 0 0 4px 0;
    }

    p {
      color: $presszone-comments-text-muted;
      margin: 0;
      font-size: 14px;

      @include dark-mode-class {
        color: $presszone-comments-text-muted-dark;
      }
    }
  }

  &__header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
  }

  &__content {
    background: $presszone-comments-surface;
    border-radius: $presszone-comments-radius-lg;
    padding: 16px;

    @include dark-mode-class {
      background: $presszone-comments-surface-dark;
    }
  }
}

// =============================================================================
// UNDO BUTTON VARIANT
// =============================================================================

.presszone-comments-btn--undo {
  background: rgba(245, 158, 11, 0.15);
  color: $presszone-comments-warning;
  border: 1px solid $presszone-comments-warning;

  @include dark-mode-class {
    color: $presszone-comments-warning-dark;
    border-color: $presszone-comments-warning-dark;
  }

  &:hover:not(:disabled) {
    background: rgba(245, 158, 11, 0.25);
  }
}

// =============================================================================
// NODE LIST
// =============================================================================

.presszone-comments-node-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

// =============================================================================
// NODE ITEM
// =============================================================================

.presszone-comments-node-item {
  margin-bottom: 4px;

  &__content {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: $presszone-comments-surface-2;
    border-radius: $presszone-comments-radius;

    @include dark-mode-class {
      background: $presszone-comments-surface-2-dark;
    }
  }

  &--dragging &__content {
    box-shadow: $presszone-comments-shadow;

    @include dark-mode-class {
      box-shadow: $presszone-comments-shadow-dark;
    }
  }

  &__handle {
    cursor: grab;
    color: $presszone-comments-text-muted;
    user-select: none;

    @include dark-mode-class {
      color: $presszone-comments-text-muted-dark;
    }
  }

  &__icon {
    font-size: 16px;
  }

  &__title {
    flex: 1;
    font-weight: 500;
  }

  &__type {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 12px;
    background: $presszone-comments-primary-dim;
    color: $presszone-comments-primary;
    text-transform: uppercase;

    @include dark-mode-class {
      background: $presszone-comments-primary-dim-dark;
      color: $presszone-comments-primary-dark;
    }

    // Node type color coding
    &--category {
      background: $presszone-comments-badge-category-bg;
      color: $presszone-comments-badge-category-text;

      @include dark-mode-class {
        background: $presszone-comments-badge-category-bg-dark;
        color: $presszone-comments-badge-category-text-dark;
      }
    }

    &--link {
      background: $presszone-comments-badge-link-bg;
      color: $presszone-comments-badge-link-text;

      @include dark-mode-class {
        background: $presszone-comments-badge-link-bg-dark;
        color: $presszone-comments-badge-link-text-dark;
      }
    }

    &--comments-section {
      background: $presszone-comments-badge-section-bg;
      color: $presszone-comments-badge-section-text;

      @include dark-mode-class {
        background: $presszone-comments-badge-section-bg-dark;
        color: $presszone-comments-badge-section-text-dark;
      }
    }

    &--page {
      background: $presszone-comments-badge-page-bg;
      color: $presszone-comments-badge-page-text;

      @include dark-mode-class {
        background: $presszone-comments-badge-page-bg-dark;
        color: $presszone-comments-badge-page-text-dark;
      }
    }
  }

  &__inactive {
    font-size: 11px;
    color: $presszone-comments-warning;

    @include dark-mode-class {
      color: $presszone-comments-warning-dark;
    }
  }

  &__actions {
    display: flex;
    gap: 4px;
    opacity: 1;
    transition: opacity $presszone-comments-duration-fast;
  }

  &__arrows {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-inline-end: 8px;
  }
}

// =============================================================================
// ARROW BUTTONS
// =============================================================================

.presszone-comments-btn-arrow {
  background: $presszone-comments-surface-2;
  border: 1px solid $presszone-comments-border;
  border-radius: 4px;
  width: 20px;
  height: 16px;
  font-size: 8px;
  line-height: 1;
  cursor: pointer;
  color: $presszone-comments-text-muted;
  transition: all $presszone-comments-duration-fast;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;

  @include dark-mode-class {
    background: $presszone-comments-surface-2-dark;
    border-color: $presszone-comments-border-dark;
    color: $presszone-comments-text-muted-dark;
  }

  &:hover:not(:disabled) {
    background: $presszone-comments-primary-dim;
    border-color: $presszone-comments-primary;
    color: $presszone-comments-primary;

    @include dark-mode-class {
      background: $presszone-comments-primary-dim-dark;
      border-color: $presszone-comments-primary-dark;
      color: $presszone-comments-primary-dark;
    }
  }

  &:disabled {
    opacity: 0.3;
    cursor: not-allowed;
  }
}

// =============================================================================
// SAVING INDICATOR
// =============================================================================

.presszone-comments-saving-indicator {
  position: fixed;
  bottom: 24px;
  inset-inline-end: 24px;
  background: $presszone-comments-surface;
  padding: 12px 20px;
  border-radius: $presszone-comments-radius;
  box-shadow: $presszone-comments-shadow;
  font-size: 14px;

  @include dark-mode-class {
    background: $presszone-comments-surface-dark;
    box-shadow: $presszone-comments-shadow-dark;
  }
}

// =============================================================================
// MODAL COMPONENT
// Admin-only modal styles - scoped to prevent frontend conflicts
// =============================================================================

.presszone-comments-admin {
  .presszone-comments-modal-overlay {
    position: fixed;
    inset: 0;
    background: $presszone-comments-overlay;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: $presszone-comments-z-modal;

    @include dark-mode-class {
      background: $presszone-comments-overlay-dark;
    }
  }

  .presszone-comments-modal {
    background: $presszone-comments-surface;
    border-radius: $presszone-comments-radius-xl;
    width: 100%;
    max-width: 500px;
    height: 600px; // Fixed height to prevent jitter when switching tabs
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: $presszone-comments-shadow;
    overflow: hidden;

    @include dark-mode-class {
      background: $presszone-comments-surface-dark;
      box-shadow: $presszone-comments-shadow-dark;
    }

    &__header {
      display: flex;
      justify-content: space-between;
      align-items: flex-start;
      padding: 20px 24px 0; // Reduced bottom padding for tabs
      border-bottom: none;
      flex-shrink: 0;
    }

    &__content {
      padding: 16px 24px 24px; // Reduced top padding
      flex: 1;
      overflow-y: auto; // Scroll internally
    }

    &__form {
      padding: 16px 24px 24px; // Consistent with content
    }

    &__actions {
      display: flex;
      gap: 12px;
      padding: 16px 24px;
      border-top: 1px solid $presszone-comments-border;
      background: $presszone-comments-surface-2;

      @include dark-mode-class {
        border-top-color: $presszone-comments-border-dark;
        background: $presszone-comments-surface-2-dark;
      }
    }
  }
}

// =============================================================================
// PERMISSIONS COMPONENT
// =============================================================================

.presszone-comments-permissions {
  &__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;

    h1 {
      margin: 0 0 4px 0;
    }

    p {
      color: $presszone-comments-text-muted;
      margin: 0;
      font-size: 14px;

      @include dark-mode-class {
        color: $presszone-comments-text-muted-dark;
      }
    }
  }

  &__actions {
    display: flex;
    gap: 8px;
  }
}

// =============================================================================
// PERMISSION LEGEND
// =============================================================================

.presszone-comments-perm-legend {
  display: flex;
  gap: 24px;
  margin-bottom: 16px;
  font-size: 14px;

  &__item {
    display: flex;
    align-items: center;
    gap: 8px;
  }
}

// =============================================================================
// ROLE HEADER & TOOLTIPS
// =============================================================================

.presszone-comments-perm-table__role-header {
  white-space: nowrap;
}

.presszone-comments-role-name {
  margin-inline-end: 4px;
}

.presszone-comments-role-tooltip,
.presszone-comments-cap-tooltip,
.presszone-comments-tooltip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  font-size: 11px;
  color: $presszone-comments-text-muted;
  cursor: help;
  opacity: 0.6;
  transition: opacity $presszone-comments-duration-fast;
  position: relative;

  @include dark-mode-class {
    color: $presszone-comments-text-muted-dark;
  }

  &:hover {
    opacity: 1;
    color: $presszone-comments-primary;

    @include dark-mode-class {
      color: $presszone-comments-primary-dark;
    }
  }
}

// Custom Tooltip Popup using title attribute
.presszone-comments-tooltip {
  &::after {
    content: attr(title);
    position: absolute;
    top: calc(100% + 8px);
    inset-inline-start: 50%;
    transform: translateX(-50%);
    padding: 10px 14px;
    background: $presszone-comments-surface;
    color: $presszone-comments-text;
    font-size: 12px;
    font-weight: 400;
    line-height: 1.5;
    white-space: normal;
    width: max-content;
    max-width: 280px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15), 0 0 0 1px $presszone-comments-border;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
    z-index: $presszone-comments-z-modal;
    pointer-events: none;
    text-align: start;

    @include dark-mode-class {
      background: $presszone-comments-surface-dark;
      color: $presszone-comments-text-dark;
      box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4), 0 0 0 1px $presszone-comments-border-dark;
    }
  }

  &::before {
    content: '';
    position: absolute;
    top: calc(100% + 2px);
    inset-inline-start: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-bottom-color: $presszone-comments-surface;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    z-index: $presszone-comments-z-tooltip;

    @include dark-mode-class {
      border-bottom-color: $presszone-comments-surface-dark;
    }
  }

  &:hover {
    &::after,
    &::before {
      opacity: 1;
      visibility: visible;
    }

    &::after {
      transform: translateX(-50%) translateY(4px);
    }
  }
}

.presszone-comments-perm-table__cap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.presszone-comments-perm-trace__help {
  color: $presszone-comments-text-muted;
  font-size: 13px;
  margin: 0 0 12px 0;

  @include dark-mode-class {
    color: $presszone-comments-text-muted-dark;
  }
}

// =============================================================================
// PERMISSION TABLE WRAPPER
// =============================================================================

.presszone-comments-perm-table-wrapper {
  background: $presszone-comments-surface;
  border-radius: $presszone-comments-radius-lg;
  overflow: auto; // Enable scrolling
  max-width: 100%;
  border: 1px solid $presszone-comments-border;
  position: relative;
  max-height: calc(100vh - 200px); // Limit height to viewport

  @include dark-mode-class {
    background: $presszone-comments-surface-dark;
    border-color: $presszone-comments-border-dark;
  }
}

// =============================================================================
// PERMISSION GRID (DIV-BASED)
// =============================================================================

.presszone-comments-perm-grid-wrapper {
  background: $presszone-comments-surface;
  border-radius: $presszone-comments-radius-lg;
  border: 1px solid $presszone-comments-border;
  overflow: auto;
  max-height: calc(100vh - 200px);
  position: relative;
  box-shadow: $presszone-comments-shadow-sm;

  @include dark-mode-class {
    background: $presszone-comments-surface-dark;
    border-color: $presszone-comments-border-dark;
    box-shadow: $presszone-comments-shadow-sm-dark;
  }
}

.presszone-comments-perm-grid {
  display: grid;
  // grid-template-columns set inline in JS
  min-width: 100%;

  &__cell {
    padding: 16px 12px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid $presszone-comments-border;
    background: $presszone-comments-surface;
    font-size: 14px;
    color: $presszone-comments-text;

    @include dark-mode-class {
      border-bottom-color: $presszone-comments-border-dark;
      background: $presszone-comments-surface-dark;
      color: $presszone-comments-text-dark;
    }

    // Header Cells
    &--header {
      background: $presszone-comments-surface-2;
      font-weight: 600;
      position: sticky;
      top: 0;
      z-index: 10;
      border-bottom: 2px solid $presszone-comments-border;
      justify-content: center;

      @include dark-mode-class {
        background: $presszone-comments-surface-2-dark;
        border-bottom-color: $presszone-comments-border-dark;
      }
    }

    // Capability Column (Sticky Left)
    &--cap {
      position: sticky;
      inset-inline-start: 0;
      z-index: 5;
      background: $presszone-comments-surface;
      border-inline-end: 2px solid $presszone-comments-border;
      font-weight: 500;
      justify-content: flex-start;

      @include dark-mode-class {
        background: $presszone-comments-surface-dark;
        border-inline-end-color: $presszone-comments-border-dark;
      }
    }

    // Top-Left Corner (Sticky Both)
    &--sticky-corner {
      position: sticky;
      top: 0;
      inset-inline-start: 0;
      z-index: 20;
      background: $presszone-comments-surface-2;
      border-inline-end: 2px solid $presszone-comments-border;
      justify-content: flex-start;

      @include dark-mode-class {
        background: $presszone-comments-surface-2-dark;
        border-inline-end-color: $presszone-comments-border-dark;
      }
    }

    // Action Cells
    &--action {
      justify-content: center;

      &:hover {
        background: $presszone-comments-surface-2;

        @include dark-mode-class {
          background: $presszone-comments-surface-2-dark;
        }
      }
    }
  }
}

// =============================================================================
// SETTINGS GROUP (HORIZONTAL LAYOUT)
// =============================================================================

.presszone-comments-settings-group--horizontal {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  align-items: flex-end; // Align bottom to match inputs

  > .presszone-comments-form-group {
    flex: 1;
    min-width: 250px;
    margin-bottom: 0; // Remove bottom margin inside group
  }
}

// =============================================================================
// LEGACY PERMISSION TABLE STYLES
// DEPRECATED: Use .presszone-comments-perm-grid instead
// These styles are kept for backwards compatibility but should not be used in new code
// =============================================================================

.presszone-comments-perm-cell {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  font-weight: 700;
  cursor: pointer;
  transition: all $presszone-comments-duration-fast;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  padding: 0;
  font-size: 14px;

  &--allow {
    background: $presszone-comments-success-dim-alt;
    color: $presszone-comments-success;

    @include dark-mode-class {
      background: $presszone-comments-success-dim-dark;
      color: $presszone-comments-success-dark;
    }
  }

  &--inherit {
    background: $presszone-comments-surface-2;
    color: $presszone-comments-text-muted;

    @include dark-mode-class {
      background: $presszone-comments-surface-2-dark;
      color: $presszone-comments-text-muted-dark;
    }
  }

  &--never {
    background: $presszone-comments-error-dim;
    color: $presszone-comments-error;

    @include dark-mode-class {
      background: $presszone-comments-error-dim-dark;
      color: $presszone-comments-error-dark;
    }
  }
}

// =============================================================================
// PERMISSION TRACE COMPONENT
// =============================================================================

.presszone-comments-perm-trace {
  margin-top: 32px;
  background: $presszone-comments-surface;
  border-radius: $presszone-comments-radius-lg;
  padding: 20px;

  @include dark-mode-class {
    background: $presszone-comments-surface-dark;
  }

  h2 {
    margin: 0 0 16px 0;
    font-size: 16px;
  }

  &__form {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;

    .presszone-comments-input,
    .presszone-comments-select {
      width: auto;
      min-width: 150px;
    }
  }

  &__result {
    margin-top: 16px;
    padding: 16px;
    border-radius: $presszone-comments-radius;

    h3 {
      margin: 0 0 12px 0;
    }

    ul {
      margin: 0;
      padding-inline-start: 20px;
      font-size: 13px;
    }

    &--allowed {
      background: $presszone-comments-success-dim-lighter;
      border: 1px solid $presszone-comments-success;

      @include dark-mode-class {
        background: $presszone-comments-success-dim-dark;
        border-color: $presszone-comments-success-dark;
      }
    }

    &--denied {
      background: $presszone-comments-error-dim-lighter;
      border: 1px solid $presszone-comments-error;

      @include dark-mode-class {
        background: $presszone-comments-error-dim-dark;
        border-color: $presszone-comments-error-dark;
      }
    }
  }
}

// =============================================================================
// SETTINGS PAGE HEADER
// =============================================================================

.presszone-comments-settings {
  &__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;

    h1 {
      margin: 0;
    }
  }
}
