/* CRM — formularios compactos (grid + tabs) */

.crm-form {
  --crm-input-h: 42px;
  --crm-gap-y: 0.45rem;
  --crm-gap-x: 0.75rem;
  margin: 0;
}

.crm-form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--crm-gap-y) var(--crm-gap-x);
  align-items: start;
  width: 100%;
  min-width: 0;
}

@media (max-width: 1024px) {
  .crm-form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .crm-form-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

.crm-field {
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
  min-width: 0;
  margin: 0;
}

.crm-field--full,
.crm-field.crm-field--full {
  grid-column: 1 / -1;
}

.crm-form .crm-field > label,
.crm-form-grid .crm-field > label {
  display: block;
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  color: #64748b;
  letter-spacing: 0.01em;
  line-height: 1.25;
}

.crm-form input:not([type="checkbox"]):not([type="hidden"]):not([type="file"]),
.crm-form select,
.crm-form textarea {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  margin: 0;
  padding: 0 0.65rem;
  border: 1px solid #dbe3ef;
  border-radius: 10px;
  font-size: 0.88rem;
  font-family: inherit;
  background: #fff;
  color: #0f172a;
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.crm-form input:not([type="checkbox"]):not([type="file"]):not([type="hidden"]):not(
    [type="datetime-local"]
  ):not([type="date"]):not([type="time"]):not([type="month"]):not([type="week"]),
.crm-form select {
  height: var(--crm-input-h);
  line-height: calc(var(--crm-input-h) - 2px);
}

/* datetime-local: line-height fijo rompe el segmento de hora en Chrome/Edge */
.crm-form input[type="datetime-local"],
.crm-form input[type="date"],
.crm-form input[type="time"],
.crm-form input[type="month"],
.crm-form input[type="week"] {
  height: var(--crm-input-h);
  min-height: var(--crm-input-h);
  line-height: normal;
  padding-top: 0.38rem;
  padding-bottom: 0.38rem;
  box-sizing: border-box;
}

.crm-form select[multiple] {
  height: auto;
  min-height: 5.5rem;
  padding: 0.35rem 0.5rem;
}

.crm-form textarea {
  min-height: 2.75rem;
  max-height: 8rem;
  padding: 0.45rem 0.65rem;
  line-height: 1.35;
  resize: vertical;
}

.crm-form input:focus,
.crm-form select:focus,
.crm-form textarea:focus {
  outline: none;
  border-color: rgba(15, 76, 151, 0.45);
  box-shadow: 0 0 0 3px rgba(15, 76, 151, 0.12);
}

.crm-form input:disabled,
.crm-form select:disabled,
.crm-form textarea:disabled {
  opacity: 0.65;
  background: #f1f5f9;
}

.crm-form input[type="file"] {
  height: auto;
  padding: 0.4rem 0.5rem;
  font-size: 0.82rem;
}

/* Tabs */
.crm-form-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0 0 0.75rem;
  padding: 0.35rem;
  border-radius: 12px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
}

.crm-form-tab {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.45rem 0.7rem;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: #475569;
  font-size: 0.78rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition:
    background 0.25s ease,
    color 0.25s ease,
    box-shadow 0.25s ease;
}

.crm-form-tab:hover {
  color: #0f4c97;
  background: rgba(255, 255, 255, 0.65);
}

.crm-form-tab.is-active {
  background: #fff;
  color: #0f4c97;
  box-shadow: 0 2px 8px rgba(15, 76, 151, 0.12);
}

.crm-form-panels {
  min-width: 0;
}

.crm-form-panel {
  display: none;
  animation: crm-panel-in 0.28s ease both;
}

.crm-form-panel.is-active {
  display: block;
}

@keyframes crm-panel-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.crm-form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px solid #e8eef4;
  grid-column: 1 / -1;
}

.crm-form-actions .btn-primary,
.crm-form-actions .btn-secondary {
  margin: 0;
  min-width: 8.5rem;
  min-height: 40px;
  padding: 0.45rem 1rem;
  font-size: 0.88rem;
}

/* Fieldset compacto dentro de grid */
.crm-form .hr-fieldset {
  grid-column: 1 / -1;
  margin: 0.25rem 0 0;
  padding: 0.65rem 0.75rem 0.75rem;
  border-radius: 12px;
}

.crm-form .hr-fieldset .crm-form-grid {
  margin-top: 0.35rem;
}

.crm-form .hr-fieldset legend {
  font-size: 0.75rem;
  padding: 0 0.3rem;
}

/* Filas especiales (NIT, checkboxes) */
.crm-form .check-row {
  grid-column: 1 / -1;
  margin: 0.15rem 0;
  font-size: 0.84rem;
}

.crm-form .crm-form-block {
  grid-column: 1 / -1;
  min-width: 0;
}

.client-revenue-forms-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem;
  align-items: start;
  margin-top: 1.25rem;
}

@media (max-width: 1100px) {
  .client-revenue-forms-row {
    grid-template-columns: minmax(0, 1fr);
  }
}

.client-revenue-form-col {
  min-width: 0;
}

.client-revenue-form-col > .main-title--sub {
  margin-top: 0;
}

.crm-form .crm-form-block .crm-form-grid {
  margin-top: 0.35rem;
}

.crm-form .crm-form-hint,
.crm-form .main-lead {
  grid-column: 1 / -1;
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  line-height: 1.4;
}

.crm-form .nit-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: var(--crm-gap-x);
  align-items: end;
}

@media (max-width: 640px) {
  .crm-form .nit-row {
    grid-template-columns: 1fr 1fr;
  }

  .crm-form .nit-actions {
    grid-column: 1 / -1;
  }
}

.crm-form .nit-field {
  min-width: 0;
}

/* Tarjetas con formulario: menos padding vertical */
.main-card:has(.crm-form) {
  padding: 1rem 1.15rem 1.1rem;
}

.main-card:has(.crm-form) .main-lead {
  margin-bottom: 0.65rem;
  font-size: 0.86rem;
}

.main-card:has(.crm-form) .main-title--sub {
  margin-bottom: 0.25rem;
}

/* Anular márgenes legacy en formularios CRM */
.crm-form > label,
.crm-form .crm-field > label {
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}

#create-user-form label:not(.check-row),
#client-form label:not(.check-row),
#user-hr-form label:not(.check-row),
#ticket-form label:not(.check-row),
#supplier-form label:not(.check-row),
#product-form label:not(.check-row) {
  margin-top: 0;
}

.user-hr-self-password-title {
  margin: 0 0 0.25rem;
  font-size: 0.92rem;
}

.user-hr-self-password-hint {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
}

#ticket-technician-ids {
  min-height: 5.5rem;
}

.main-view--wide {
  max-width: 1120px;
}

#client-contract-fieldset .mc-types-grid {
  display: grid !important;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.35rem 0.65rem;
}
