.tab-form-container {
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

.tab-form {
  flex: 1;
  padding: 10px 10px 10px;
  overflow-y: hidden;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.form-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.form-field.full-width {
  grid-column: 1 / -1;
}

.custom-field {
  position: relative;
}

/* Select nativo */
.native-select-field {
  position: relative;
  margin-bottom: 1rem;

  label {
    position: absolute;
    top: -0.8rem;
    left: 0.5rem;
    background-color: var(--surface);
    padding: 0 0.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 900;
    z-index: 1;
  }

  .native-select {
    width: 100%;
    padding: 0.75rem 2.5rem 0.75rem 0.75rem;
    border: 1px solid var(--divider);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: var(--font-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6,9 12,15 18,9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 1rem;

    &:hover {
      border-color: var(--primary);
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }

    &:focus {
      outline: none;
      border-color: var(--primary);
      box-shadow: 0 0 0 2px rgba(241, 180, 13, 0.1);
    }

    option {
      background: var(--surface);
      color: var(--text-primary);
      padding: 8px 12px;
    }
  }
}

/* Tema escuro para select nativo */
:host-context(.dark-theme) .native-select-field {
  label {
    background-color: var(--surface);
    color: var(--text-secondary);
  }

  .native-select {
    background: var(--surface) url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23FFC82E' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6,9 12,15 18,9'%3e%3c/polyline%3e%3c/svg%3e") no-repeat right 0.5rem center;
    background-size: 1rem;
    color: var(--text-primary);
    border-color: var(--divider);

    &:hover {
      border-color: #FFC82E;
    }

    &:focus {
      border-color: #FFC82E;
      box-shadow: 0 0 0 2px rgba(255, 200, 46, 0.2);
    }

    option {
      background: var(--surface);
      color: var(--text-primary);
    }
  }
}

.error-message {
  color: var(--idt-danger);
  font-size: 12px;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Slide Toggle Field */
.slide-toggle-field {
  position: relative;
  padding: 1rem 0;
  
  app-slide-toggle {
    display: block;
    width: 100%;
  }
}

/* Remote Select Field */
.remote-select-field {
  position: relative;
  margin-bottom: 0.5rem;

  app-remote-select {
    display: block;
    width: 100%;
  }

  .error-message {
    color: var(--error-color, #ef4444);
    font-size: 0.75rem;
    margin-top: 0.25rem;
  }
}

/* Kilometer Input Field */
.kilometer-input-field {
  position: relative;
  margin-bottom: 0.5rem;

  app-kilometer-input {
    display: block;
    width: 100%;
  }

  .error-message {
    color: var(--error-color, #ef4444);
    font-size: 0.75rem;
    margin-top: 0.25rem;
  }
}

/* Color Input Field */
.color-input-field {
  position: relative;
  margin-bottom: 0.5rem;

  app-color-input {
    display: block;
    width: 100%;
  }

  .error-message {
    color: var(--error-color, #ef4444);
    font-size: 0.75rem;
    margin-top: 0.25rem;
  }
}

/* Currency Input Field */
.currency-input-field {
  position: relative;
  margin-bottom: 0.5rem;

  app-currency-input {
    display: block;
    width: 100%;
  }

  .error-message {
    color: var(--error-color, #ef4444);
    font-size: 0.75rem;
    margin-top: 0.25rem;
  }
}

/* Textarea Input Field */
.textarea-input-field {
  position: relative;
  margin-bottom: 0.5rem;

  app-textarea-input {
    display: block;
    width: 100%;
  }

  .error-message {
    color: var(--error-color, #ef4444);
    font-size: 0.75rem;
    margin-top: 0.25rem;
  }
}

/* 🚀 COMPONENTES DINÂMICOS */
.dynamic-component {
  width: 100%;
  height: 100%;
  min-height: 0; /* Remove limitação de altura mínima */
  position: relative;
  overflow: hidden;
  padding: 0;
  margin: 0;
  display: flex; /* Adiciona flex para permitir que o filho ocupe todo o espaço */
  flex-direction: column;

  app-route-stops {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important; /* Remove limitação de altura mínima */
    position: relative;
    flex: 1 !important; /* Garante que ocupe todo o espaço flex disponível */
  }
}

.dynamic-component-container {
  width: 100%;
  height: 100%;
  min-height: 400px;
  position: relative;
}

.component-debug {
  background: orange !important;
  color: black !important;
  padding: 10px !important;
  margin: 10px !important;
  border-radius: 4px;
  font-family: monospace;
}

.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  padding-top: 20px;
  border-top: 1px solid var(--divider);
  background: var(--surface);
  position: sticky;
  bottom: 0;
  margin: 0 -20px -20px;
  padding: 20px;
  z-index: 10;
}

.submit-btn {
  min-width: 120px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  border: none;
  background: linear-gradient(135deg, #FFC82E 0%, #FFB300 100%);
  color: #000000;
  box-shadow: 0 2px 8px rgba(255, 200, 46, 0.3);

  &:hover:not(:disabled) {
    background: linear-gradient(135deg, #FFD700 0%, #FFC82E 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(255, 200, 46, 0.4);
  }

  &:active:not(:disabled) {
    transform: translateY(-1px);
  }

  &:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
    background: #e0e0e0;
    color: #999;
  }

  &.disabled-readonly {
    opacity: 0.4;
    cursor: not-allowed;
    background: #f5f5f5;
    color: #999;
    box-shadow: none;
  }

  i {
    font-size: 0.875rem;
  }
}

.edit-btn {
  min-width: 120px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  border: none;
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);

  &:hover {
    background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(59, 130, 246, 0.4);
  }

  &:active {
    transform: translateY(-1px);
  }

  i {
    font-size: 0.875rem;
  }
}

.cancel-btn {
  min-width: 120px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  border: 1px solid var(--divider);
  background: var(--surface);
  color: var(--text-secondary);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);

  &:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
    border-color: var(--text-secondary);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
  }

  &:active {
    transform: translateY(0);
  }

  i {
    font-size: 0.875rem;
  }
}

.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(var(--surface), 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--text-secondary);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--surface);
  border-top: 4px solid var(--idt-primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Responsividade */
@media (max-width: 768px) {
  .form-fields {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .tab-form {
    padding: 0 16px 16px;
  }

  .form-actions {
    flex-direction: column;
    
    .submit-btn,
    .edit-btn,
    .cancel-btn {
      width: 100%;
    }
  }
}

/* Sub-tab System Styles */
.sub-tab-system {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.sub-tab-headers {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--divider);
  flex-shrink: 0;
}

.sub-tab-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  border-bottom: 3px solid transparent;

  &:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
  }

  &.active {
    background: var(--background);
    color: var(--text-color);
    border-bottom-color: var(--idt-primary-color);
    font-weight: 600;
  }

  i {
    font-size: 16px;
  }
}

/* Sub-tab title color correction for dark theme */
.dark-theme .sub-tab-header.active {
  color: var(--idt-primary-color);
}

.sub-tab-content-container {
  flex: 1;
  // min-height: 0;
  overflow-y: auto;
  background: var(--surface, #ffffff);
}

.sub-tab-content {
  padding: 20px 10px 10px 20px;
  // margin-top: 20px;
  display: none;
  // min-height: 400px;
  height: auto;
  background: var(--surface, #ffffff);

  &.active {
    display: block;
  }

  /* Espaço especial para componentes dinâmicos */
  &:has(.dynamic-component) {
    padding: 0;
    // height: calc(100vh - 200px);
    // min-height: 600px;
  }
}

/* Garantir que o formulário ocupe espaço adequado */
.tab-form {
  height: auto;
  min-height: 400px;
  padding: 0;
  overflow: visible;
}

/* Ajustar form-actions para sub-tabs */
.form-actions {
  position: sticky;
  bottom: 0;
  background: var(--surface, #ffffff);
  border-top: 1px solid var(--divider, #e5e7eb);
  padding: 16px 20px;
  margin: 0;
  z-index: 10;
  flex-shrink: 0;
}

/* Controle de visibilidade mobile-only */
.mobile-only {
  display: none; /* Oculto por padrão no desktop */
}

/* Responsividade para sub-tabs */
@media (max-width: 768px) {
  /* Mostrar elementos mobile-only */
  .mobile-only {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .sub-tab-header {
    padding: 10px 16px;
    font-size: 13px;
    
    i {
      font-size: 14px;
    }
  }
  
  .sub-tab-content {
    padding: 16px;
  }

  /* ✨ Responsividade do Side Card - Mobile */
  .main-layout.with-side-card {
    flex-direction: column;
    gap: 16px;
    
    .side-card {
      order: -1; /* Sempre no topo no mobile */
      position: relative; /* Remove sticky no mobile */
      top: auto;
      width: 100% !important; /* Full width no mobile */
      max-height: none; /* Remove limitação de altura */
      
      .card-header .mobile-collapse-btn {
        display: flex; /* Mostra o botão no mobile */
        align-items: center;
        justify-content: center;
      }
    }
  }

  /* Animação suave para os campos */
  .card-fields-container {
    transition: all 0.3s ease;
    overflow: hidden;
    
    &.mobile-hidden {
      max-height: 0;
      padding: 0;
      opacity: 0;
    }
  }
}

/* Single tab content (quando há apenas uma aba) */
.single-tab-content {
  padding: 20px;
  min-height: 400px;
  background: var(--surface, #ffffff);
}

/* Coming soon placeholder */
.coming-soon {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  text-align: center;
  color: var(--text-secondary);
  gap: 16px;

  i {
    color: var(--idt-primary-color);
    opacity: 0.6;
  }

  h3 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.25rem;
    font-weight: 600;
  }

  p {
    margin: 0;
    font-size: 0.875rem;
    opacity: 0.8;
  }
}

/* ✨ Layout Principal com Card Lateral */
.main-layout {
  display: flex;
  gap: 20px;
  height: 100%;
  width: 100%;

  &.with-side-card {
    .form-section {
      flex: 1;
      min-width: 0; // Permite que o flex-item encolha
      overflow: hidden;
    }
  }
}

.form-section {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
}

/* ✨ Side Card Styles - Layout Atualizado */
.side-card {
  flex-shrink: 0;
  background: var(--surface, #ffffff);
  border-radius: 16px;
  border: 1px solid var(--divider, #e5e7eb);
  box-shadow: 0 4px 12px var(--shadow-color, rgba(0, 0, 0, 0.1));
  overflow: hidden;
  height: fit-content;
  max-height: calc(100vh - 200px);
  position: sticky;
  top: 20px;
  transition: all 0.3s ease;

  &.side-card-right {
    order: 2;
  }

  &.side-card-left {
    order: -1;
  }

  /* Estado recolhido (apenas mobile) */
  &.side-card-collapsed {
    @media (max-width: 768px) {
      max-height: auto; /* Remove limite de altura quando recolhido */
      
      .card-content {
        .card-fields-container.mobile-hidden {
          display: none;
        }
      }
    }
  }
}

.summary-card {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.card-header {
  padding: 20px 24px 16px 24px;
  background: linear-gradient(135deg, #1f2937 0%, #374151 100%);
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;

  .card-header-content {
    flex: 1;
  }

  h3 {
    margin: 0 0 8px 0;
    color: white;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.025em;
  }

  .card-subtitle {
    margin: 0;
    color: #d1d5db;
    font-size: 0.875rem;
    font-weight: 400;
    opacity: 0.9;
  }

  .mobile-collapse-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 8px;
    padding: 8px 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
    margin-left: 16px;

    &:hover {
      background: rgba(255, 255, 255, 0.2);
      border-color: rgba(255, 255, 255, 0.3);
    }

    &:active {
      transform: scale(0.95);
    }

    i {
      transition: transform 0.2s ease;
    }
  }
}

.card-content {
  padding: 0;
  flex: 1;
  overflow-y: auto;
}

.card-image {
  margin: 0;
  border-radius: 0;
  overflow: hidden;
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  border: none;
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;

  img {
    width: 100%;
    height: 200px;
    object-fit: contain;
    display: block;
    padding: 20px;
  }
}

.card-fields-container {
  padding: 24px;
}

.card-field {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--divider-light, #f3f4f6);
  display: flex;
  justify-content: space-between;
  align-items: center;

  &:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
  }

  label {
    display: block;
    font-size: 0.9375rem;
    color: var(--text-secondary, #6b7280);
    font-weight: 900;
    margin: 0;
    flex: 1;
  }
}

.card-value {
  font-size: 0.9375rem;
  color: var(--text-primary, #1f2937);
  font-weight: 600;
  text-align: right;
  flex: 1;
  word-break: break-word;

  &.card-currency {
    color: var(--text-primary, #1f2937);
    font-weight: 700;
    font-size: 1rem;
  }

  &.card-mileage {
    color: var(--idt-primary-color, #3b82f6);
    font-weight: 600;
    font-size: 1rem;
  }

  &.card-distance {
    color: #059669;
    font-weight: 700;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    
    &::before {
      content: "🛣️";
      font-size: 0.875rem;
      opacity: 0.8;
    }
  }

  &.card-duration {
    color: #7c3aed;
    font-weight: 700;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    
    &::before {
      content: "⏱️";
      font-size: 0.875rem;
      opacity: 0.8;
    }
  }

  &.card-currency {
    color: #dc2626;
    font-weight: 700;
    font-size: 1.125rem;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    
    &::before {
      content: "💰";
      font-size: 0.875rem;
      opacity: 0.8;
    }
  }

  &.card-status {
    .status-badge {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 8px 16px;
      border-radius: 20px;
      font-size: 0.875rem;
      font-weight: 500;
      border: none;
      text-transform: none;
      letter-spacing: 0;
      transition: all 0.2s ease;

      i {
        font-size: 0.75rem;
      }
      
      &:hover {
        transform: translateY(-1px);
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
      }
    }
  }

  &.card-plate {
    font-family: 'Courier New', monospace;
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary, #1f2937);
  }
}

.custom-card {
  padding: 20px;
}

/* ✨ Responsividade do Card Lateral */
@media (max-width: 1200px) {
  .main-layout.with-side-card {
    flex-direction: column;
    gap: 16px;

    .side-card {
      position: relative;
      top: auto;
      max-height: none;
      order: 0;
      width: 100% !important;
    }

    .form-section {
      order: 1;
    }
  }
}

@media (max-width: 768px) {
  .main-layout {
    gap: 12px;
  }

  .side-card {
    border-radius: 12px;

    .card-content {
      .card-fields-container {
        padding: 16px;
      }
    }

    .card-header {
      padding: 16px 20px 12px 20px;

      h3 {
        font-size: 1.125rem;
      }

      .card-subtitle {
        font-size: 0.8125rem;
      }
    }
  }

  .card-image {
    height: 150px;

    img {
      height: 150px;
      padding: 15px;
    }
  }

  .card-field {
    margin-bottom: 16px;
    padding-bottom: 12px;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;

    label {
      text-align: left;
    }

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

/* 🔴 INDICADOR DE CAMPO OBRIGATÓRIO */
.required-indicator {
  color: var(--idt-danger, #dc3545);
  margin-left: 4px;
  font-weight: 700;
  font-size: 16px;
  line-height: 1;
}

/* 🌙 TEMA ESCURO - Melhorias nos campos formatados */
@media (prefers-color-scheme: dark) {
  .card-value {
    &.card-distance {
      color: #10b981;
    }

    &.card-duration {
      color: #a78bfa;
    }

    &.card-currency {
      color: #f87171;
    }
  }
}

:root[data-theme="dark"] {
  .card-value {
    &.card-distance {
      color: #10b981;
    }

    &.card-duration {
      color: #a78bfa;
    }

    &.card-currency {
      color: #f87171;
    }
  }
}