@use '@angular/material' as mat;
@use 'sass:map' as map;

/* base.component.scss */
:host {
  --lib-color-primary: var(--mat-sys-primary);
  --lib-color-on-primary: var(--mat-sys-on-primary);
  --lib-color-secondary: var(--mat-sys-secondary);
  --lib-color-on-secondary: var(--mat-sys-on-secondary);
  --lib-color-surface: var(--mat-sys-surface);
  --lib-color-on-surface: var(--mat-sys-on-surface);
  --lib-color-outline: var(--mat-sys-outline);
  --lib-color-outline-variant: var(--mat-sys-outline-variant);
}


@mixin mcl-theming($config-or-theme) {
  $config: mat.m2-get-color-config($config-or-theme);

  @include mat.core();

  @include mat.all-component-themes($config-or-theme);

  /* ===============================================
   Angular Material: tema básico alinhado ao portal
   Cores: #3f8634 (estrutural) e #357ea6 (ações)
   Material Design base + personalidade sutil
   ------------------------------------------------
   Como usar (Angular >= v15 com Sass):
   1) Crie src/styles/_theme.scss com este conteúdo
   2) Em styles.scss: @use "./styles/theme" as *;
   3) Garanta que o Angular Material esteja instalado e configurado
   =============================================== */

  /* --- Variáveis de marca --- */
  :root {
    /* Cores principais */
    --brand-structural: #3f8634; /* verde - áreas estruturais */
    --brand-primary: #357ea6; /* azul  - ações principais */

    /* Neutros de apoio */
    --neutral-0: #ffffff;
    --neutral-50: #fafafa;
    --neutral-100: #f5f5f5;
    --neutral-200: #eeeeee;
    --neutral-300: #e0e0e0;
    --neutral-600: #757575;
    --neutral-800: #424242;
  }

  *, *::before, *::after {
    box-sizing: border-box;
  }
  html {
    -webkit-text-size-adjust: 100%;
  }
  html, body {
    height: 100%;
  }

  body {
    margin: 0;
    background: var(--mat-sys-surface);
    color: var(--mat-sys-on-surface);
    font: 400 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
  }

  /* Seleção de texto */
  ::selection {
    background: color-mix(in oklab, var(--mat-sys-primary) 30%, transparent);
    color: var(--mat-sys-on-primary);
  }

  /* Links */
  a {
    color: color-mix(in oklab, var(--mat-sys-primary) 96%, #000);
    text-decoration: none;
  }
  a:hover {
    text-decoration: underline;
  }

  /* Imagens e mídia responsiva */
  img, svg, video, canvas {
    height: auto;
    display: block;
  }

  /* Tabelas (neutral outline) */
  table {
    border-collapse: collapse;
    width: 100%;
  }
  th, td {
    border-bottom: 1px solid var(--mat-sys-outline-variant);
    padding: 0.5rem 0.75rem;
  }
  thead th {
    color: var(--mat-sys-on-surface-variant);
    font-weight: 600;
    background: color-mix(in oklab, var(--mat-sys-outline-variant) 18%, transparent);
  }

  /* Form fields base (quando não for Angular Material) */
  input, button, textarea, select {
    font: inherit;
    color: inherit;
  }
  button {
    cursor: pointer;
  }

  /* Focus visible consistente (componentes nativos e estrutura) */
  :where(a, button, [role="button"], input, select, textarea):focus-visible {
    outline: 2px solid var(--mat-sys-primary);
    outline-offset: 2px;
    border-radius: 8px;
  }

  mat-form-field {
    width: 100%;
    display: block; /* evita inline sizing */
  }
  /* --- Overrides rápidos de componentes comuns --- */

  /* Header / Toolbar global */
  .mat-toolbar {
    background: var(--neutral-0) !important;
    color: var(--neutral-800) !important;
    border-bottom: 1px solid var(--neutral-200);
  }

  /* Sidenav (menu lateral): fundo claro + acentos de marca */
  .mat-sidenav {
    background: var(--neutral-0);
    border-right: 1px solid var(--neutral-200);
  }
  .mat-nav-list .mat-list-item {
    border-radius: 8px;
  }
  .mat-nav-list .mat-list-item:hover {
    background: color-mix(in oklab, var(--brand-primary) 8%, white);
  }
  .mat-nav-list .mat-list-item.mat-list-item-focus,
  .mat-nav-list .mat-list-item.mat-mdc-list-item--activated {
    background: color-mix(in oklab, var(--brand-primary) 12%, white) !important;
    color: var(--brand-primary) !important;
  }

  /* Tabs */
  .mat-mdc-tab .mdc-tab__content {
    color: var(--neutral-600);
  }
  .mat-mdc-tab.mdc-tab--active .mdc-tab__content {
    color: var(--brand-primary);
  }
  .mat-mdc-tab-indicator__content--underline {
    border-color: var(--brand-primary) !important;
  }

  /* Tabelas (listagem) */
  .mat-mdc-table thead tr {
    background: var(--neutral-100);
  }
  .mat-mdc-table thead th {
    color: var(--neutral-600);
    font-weight: 600;
  }
  .mat-mdc-table tbody tr:hover {
    background: var(--neutral-50);
  }

  /* Chips / Badges simples */
  .mdc-evolution-chip--selected,
  .mat-mdc-standard-chip.mat-mdc-chip-selected {
    background: color-mix(in oklab, var(--brand-structural) 12%, white);
    color: var(--brand-structural);
  }

  /* Paginação */
  .mat-mdc-paginator .mdc-icon-button,
  .mat-mdc-paginator .mat-mdc-select-value {
    color: var(--neutral-800);
  }
  .mat-mdc-paginator .mdc-icon-button:hover {
    color: var(--brand-primary);
  }

  /* Cards / Containers */
  .mat-mdc-card {
    border: 1px solid var(--neutral-200);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
    border-radius: 14px;
  }

  /* Tipografia básica (sobriedade) */
  .mat-h1, .mat-h2, .mat-h3, .mat-h4, .mat-h5 {
    color: var(--neutral-800);
    font-weight: 600;
  }
  .mat-body-1, .mat-body-2, .mat-subtitle-2 {
    color: var(--neutral-600);
  }

  /* Densidade (opcional): compacta nas listas/tabelas */
  .mat-mdc-table .mdc-data-table__content .mdc-data-table__row > .mdc-data-table__cell,
  .mat-mdc-table .mdc-data-table__header-row > .mdc-data-table__header-cell {
    padding-top: 10px;
    padding-bottom: 10px;
  }

  [mat-dialog-actions] {
    justify-content: end;
    gap: 20px;

    .spacer {
      flex: 1 1 auto;
    }

    button {
      margin: 0 !important;
    }
  }

  .row {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 16px;

    // Coluna padrão - ocupa espaço disponível
    .col {
      flex: 1 1 0;
      min-width: 0; // Evita overflow
    }

    // Sistema de colunas de 1 a 12 (baseado em 12 colunas)
    .col-1 {
      flex: 0 0 calc(8.33333333% - 13.33px); // ~1/12 - gap adjustment
    }

    .col-2 {
      flex: 0 0 calc(16.66666667% - 12px); // ~2/12 - gap adjustment
    }

    .col-3 {
      flex: 0 0 calc(25% - 12px); // ~3/12 - gap adjustment
    }

    .col-4 {
      flex: 0 0 calc(33.33333333% - 10.67px); // ~4/12 - gap adjustment
    }

    .col-5 {
      flex: 0 0 calc(41.66666667% - 9.6px); // ~5/12 - gap adjustment
    }

    .col-6 {
      flex: 0 0 calc(50% - 8px); // ~6/12 - gap adjustment
    }

    .col-7 {
      flex: 0 0 calc(58.33333333% - 6.86px); // ~7/12 - gap adjustment
    }

    .col-8 {
      flex: 0 0 calc(66.66666667% - 5.33px); // ~8/12 - gap adjustment
    }

    .col-9 {
      flex: 0 0 calc(75% - 4px); // ~9/12 - gap adjustment
    }

    .col-10 {
      flex: 0 0 calc(83.33333333% - 2.4px); // ~10/12 - gap adjustment
    }

    .col-11 {
      flex: 0 0 calc(91.66666667% - 1.45px); // ~11/12 - gap adjustment
    }

    .col-12 {
      flex: 0 0 100%; // ~12/12 - ocupa toda a largura
    }

    // Classes auxiliares para auto-dimensionamento
    .col-auto {
      flex: 0 0 auto;
    }

    // Ajustes para mobile - breakpoint padrão de 768px
    @media (max-width: 768px) {
      flex-direction: column;
      gap: 12px; // Gap menor no mobile

      // No mobile, todas as colunas ocupam 100% da largura por padrão
      .col,
      .col-1,
      .col-2,
      .col-3,
      .col-4,
      .col-5,
      .col-6,
      .col-7,
      .col-8,
      .col-9,
      .col-10,
      .col-11,
      .col-12 {
        flex: 0 0 100%;
        max-width: 100%;
      }

      // Classes específicas para mobile quando necessário manter layout
      .col-mobile-6 {
        flex: 0 0 calc(50% - 6px);
      }

      .col-mobile-4 {
        flex: 0 0 calc(33.33333333% - 4px);
      }

      .col-mobile-3 {
        flex: 0 0 calc(25% - 3px);
      }

      // Permite manter layout horizontal no mobile quando necessário
      &.row-mobile-horizontal {
        flex-direction: row;
      }
    }

    // Breakpoint adicional para tablets
    @media (max-width: 992px) and (min-width: 769px) {
      gap: 14px; // Gap intermediário para tablets

      // Classes específicas para tablet
      .col-tablet-6 {
        flex: 0 0 calc(50% - 7px);
      }

      .col-tablet-4 {
        flex: 0 0 calc(33.33333333% - 4.67px);
      }
    }
  }

  .acoes {
    display: flex;
    flex-direction: row-reverse;
    gap: 10px;

    .spacer {
      flex: 1 1 auto;
    }
  }

  .text-center {
    text-align: center;
  }

  .text-right {
    text-align: right;
  }

  .text-left {
    text-align: left;
  }

  .component-loading {
    position: relative;
  }
}
