// Variables ESTAIR Modern Design - Exactement identiques à vue-detail
$estair-blue: #4AA8DC;
$estair-blue-dark: #3B82F6;
$estair-green: #8DA969;
$tblr-bg: #f8fafc;
$tblr-surface: #ffffff;
$tblr-surface-secondary: #fafbfc;
$tblr-surface-tertiary: #f1f5f9;
$tblr-border-color: #e6e7e9;
$tblr-border-color-light: #f1f5f9;
$tblr-body-color: #1e293b;
$tblr-muted: #64748b;
$tblr-light: #94a3b8;
$shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);

::ng-deep .mat-tooltip {
  font-size: 14px !important;
}

// Design moderne harmonisé avec vue-detail
.page-wrapper.harmonized-create-view {
  background: $tblr-bg;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 0.875rem;
  line-height: 1.5;
  color: $tblr-body-color;
  min-height: 100vh;

  // Variables utilitaires
  .text-primary { color: $estair-blue !important; }
  .text-success { color: #2fb344 !important; }
  .fw-bold { font-weight: 600 !important; }
  .text-muted { color: $tblr-muted !important; }

  // Loading indicator harmonisé
  .progress-bar-harmonized {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    border-radius: 12px 12px 0 0;
  }

  // ===========================
  // ENTITY HEADER - Identique à vue-detail
  // ===========================
  .entity-header {
    background: $tblr-surface;
    color: $tblr-body-color;
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    position: relative;
    border: 1px solid $tblr-border-color;
    box-shadow: $shadow-md;

    .loading-indicator {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      z-index: 10;
      border-radius: 12px 12px 0 0;
    }

    .entity-content {
      position: relative;
      z-index: 1;
      display: flex;
      align-items: flex-start;
      gap: 1.5rem;
    }

    .entity-avatar {
      width: 4rem;
      height: 4rem;
      background: linear-gradient(135deg, $estair-blue, $estair-green);
      border-radius: 0.75rem;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 1.5rem;
      font-weight: 700;
      color: white;
      box-shadow: 0 2px 8px rgba(74, 168, 220, 0.2);
      flex-shrink: 0;

      mat-icon {
        font-size: 1.5rem;
        width: 1.5rem;
        height: 1.5rem;
      }
    }

    .entity-info {
      flex: 1;
      min-width: 0;
    }

    .entity-title {
      font-size: 1.5rem;
      font-weight: 700;
      margin-bottom: 0.375rem;
      line-height: 1.2;
      color: $tblr-body-color;
    }

    .entity-subtitle {
      font-size: 0.875rem;
      color: $tblr-muted;
      margin-bottom: 1rem;
    }

    .entity-badges {
      display: flex;
      flex-wrap: wrap;
      gap: 0.5rem;
      margin-bottom: 1rem;
    }

    .entity-badge {
      background: $tblr-surface-secondary;
      color: $tblr-muted;
      border: 1px solid $tblr-border-color;
      padding: 0.375rem 0.75rem;
      border-radius: 0.75rem;
      font-size: 0.75rem;
      font-weight: 500;
      display: flex;
      align-items: center;
      gap: 0.375rem;

      &.entity-badge--warning {
        background: #fef3c7;
        color: #92400e;
        border-color: #fcd34d;
      }

      &.entity-badge--info {
        background: #dbeafe;
        color: #1e40af;
        border-color: #60a5fa;
      }

      mat-icon {
        font-size: 14px;
        width: 14px;
        height: 14px;
      }
    }

    .entity-actions {
      display: flex;
      gap: 0.5rem;
      flex-wrap: wrap;
    }

    .entity-action {
      display: flex;
      align-items: center;
      gap: 0.375rem;
      padding: 0.5rem 1rem;
      border-radius: 0.375rem;
      font-size: 0.75rem;
      font-weight: 500;
      cursor: pointer;
      transition: all 0.2s ease;
      border: 1px solid $tblr-border-color;
      background: $tblr-surface;
      color: $tblr-body-color;

      &:hover {
        transform: translateY(-1px);
        box-shadow: $shadow-md;
      }

      &.primary {
        background: $estair-blue;
        border-color: $estair-blue;
        color: white;

        &:hover {
          background: $estair-blue-dark;
          border-color: $estair-blue-dark;
        }

        &:disabled {
          background: $tblr-muted;
          border-color: $tblr-muted;
          cursor: not-allowed;
          transform: none;
        }
      }

      &.danger {
        background: #dc3545;
        border-color: #dc3545;
        color: white;

        &:hover {
          background: #c82333;
          border-color: #c82333;
        }
      }

      mat-icon {
        font-size: 16px;
        width: 16px;
        height: 16px;
      }
    }
  }

  // ===========================
  // PAGE BODY
  // ===========================
  .page-body {
    .container-xl {
      max-width: none !important;
      width: 100% !important;
      margin: 0 auto;
      padding: 0 1rem;
    }
  }

  // ===========================
  // FORM CONTAINER
  // ===========================
  .harmonized-form-container {
    width: 100% !important;

    .form-dynamic {
      width: 100% !important;
    }

    // ===========================
    // ACCORDION HARMONIZED - Identique à vue-detail
    // ===========================
    .accordion-harmonized {
      .expansion-panel-harmonized {
        background: $tblr-surface;
        border: 1px solid $tblr-border-color;
        border-radius: 8px;
        box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
        margin-bottom: 1.5rem;
        transition: box-shadow 0.15s ease;

        &:hover {
          box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }

        .expansion-header-harmonized {
          padding: 1rem 1.25rem;
          border-bottom: 1px solid $tblr-border-color;
          background: $tblr-surface-secondary;
          border-radius: 8px 8px 0 0;

          .panel-title-harmonized {
            font-size: 1rem;
            font-weight: 600;
            color: $tblr-body-color;
            margin: 0;
            display: flex;
            align-items: center;
            gap: 0.5rem;

            .panel-icon {
              color: $estair-blue;
              font-size: 20px;
              width: 20px;
              height: 20px;
            }
          }

          .panel-description-harmonized {
            font-size: 0.875rem;
            color: $tblr-muted;
            margin: 0;
          }
        }

        .panel-content-harmonized {
          padding: 1.25rem;
        }
      }
    }

    // ===========================
    // FORM GRID
    // ===========================
    .form-grid {
      display: grid;
      gap: 1.5rem;
      grid-template-columns: repeat(2, 1fr); /* Max 2 colonnes (50% chacune) */

      &.form-grid-auto {
        grid-template-columns: repeat(2, 1fr); /* Max 2 colonnes (50% chacune) */
      }
    }

    .form-grid-item {
      .form-group {
        margin-bottom: 0;

        .example-full-width {
          width: 100%;

          .mat-form-field-wrapper {
            padding-bottom: 0.25rem;
          }

          .mat-form-field-label {
            font-size: 0.875rem;
            font-weight: 500;
            color: $tblr-body-color;
          }

          .mat-form-field-underline {
            background-color: $tblr-border-color;
          }

          .mat-form-field-ripple {
            background-color: $estair-blue;
          }

          // Input styles harmonisés
          .mat-input-element {
            font-size: 0.875rem;
            color: $tblr-body-color;

            &::placeholder {
              color: $tblr-muted;
            }
          }

          // Select styles harmonisés
          .mat-select {
            font-size: 0.875rem;
            color: $tblr-body-color;
          }

          // Textarea styles harmonisés
          textarea.mat-input-element {
            min-height: 80px;
            resize: vertical;
          }

          // Autocomplete styles
          .search-icon {
            color: $tblr-muted;
          }

          .loading-spinner {
            ::ng-deep .mat-progress-spinner circle {
              stroke: $estair-blue;
            }
          }
        }

        // Error messages harmonisés
        .error {
          color: #dc3545;
          font-size: 0.75rem;
          margin-top: 0.25rem;
          font-weight: 500;
        }
      }
    }

    // ===========================
    // AUTOCOMPLETE HARMONIZED
    // ===========================
    .autocomplete-option {
      .option-content {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding: 0.5rem 0;

        .option-icon {
          color: $estair-blue;
          font-size: 20px;
          width: 20px;
          height: 20px;
        }

        .option-details {
          flex: 1;

          .option-name {
            font-weight: 500;
            color: $tblr-body-color;
            font-size: 0.875rem;
          }
        }
      }
    }

    .no-results-option {
      .no-results {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        color: $tblr-muted;
        font-style: italic;
        padding: 0.5rem 0;

        mat-icon {
          font-size: 18px;
          width: 18px;
          height: 18px;
        }
      }
    }
  }
}

// ===========================
// RESPONSIVE DESIGN
// ===========================
@media (max-width: 768px) {
  .page-wrapper.harmonized-create-view {
    .entity-header {
      padding: 1rem;
      margin-bottom: 1rem;

      .entity-content {
        gap: 1rem;
      }

      .entity-avatar {
        width: 3rem;
        height: 3rem;
        font-size: 1.25rem;
      }

      .entity-title {
        font-size: 1.25rem;
      }

      .entity-actions {
        flex-direction: column;
        gap: 0.375rem;

        .entity-action {
          justify-content: center;
        }
      }
    }

    .harmonized-form-container {
      .form-grid,
      .form-grid-auto {
        grid-template-columns: 1fr; /* Sur mobile, 1 colonne (100%) */
      }
    }
  }
}

// ===========================
// MATERIAL ANGULAR OVERRIDES
// ===========================
::ng-deep {
  // Mat-expansion-panel overrides
  .accordion-harmonized {
    width: 100% !important;
    max-width: none !important;

    .mat-expansion-panel {
      box-shadow: none !important;
      border-radius: 8px !important;
      margin-bottom: 1.5rem !important;
      border: 1px solid $tblr-border-color !important;
      width: 100% !important;

      &:not(.mat-expanded) {
        .mat-expansion-panel-header {
          border-radius: 8px !important;
        }
      }

      .mat-expansion-panel-header {
        padding: 1rem 1.25rem !important;
        background: $tblr-surface-secondary !important;
        border-radius: 8px 8px 0 0 !important;

        .mat-expansion-panel-header-title {
          font-size: 1rem !important;
          font-weight: 600 !important;
          color: $tblr-body-color !important;
        }

        .mat-expansion-panel-header-description {
          font-size: 0.875rem !important;
          color: $tblr-muted !important;
        }
      }

      .mat-expansion-panel-body {
        padding: 0 !important;
      }

      .mat-expansion-panel-content {
        .mat-expansion-panel-body {
          padding: 1.25rem !important;
        }
      }
    }
  }

  // Mat-form-field overrides
  .mat-form-field {
    &.example-full-width {
      .mat-form-field-label {
        font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
        font-size: 0.875rem !important;
        font-weight: 500 !important;
      }

      .mat-input-element,
      .mat-select {
        font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
        font-size: 0.875rem !important;
      }
    }
  }

  // Mat-option overrides
  .mat-option {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
    font-size: 0.875rem !important;
  }
}

// Fix du positionnement du dropdown mat-select
::ng-deep .cdk-overlay-pane {
  margin-top: 0 !important;
}

::ng-deep .mat-select-panel {
  margin-top: -8px !important;
  max-height: 300px !important;
}