/**
 * Customers UI modernization — scoped under #customersView only.
 * Offers page is the visual reference. No !important.
 */

#customersView.customers-modern {
  --customers-gap: var(--ds-space-4, 16px);
  --customers-radius: 10px;
  --customers-control-h: 36px;
  --customers-touch-h: 44px;
  max-width: 100%;
  min-width: 0;
}

#customersView .customers-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: var(--ds-color-muted, var(--muted, #6b7280));
}

#customersView .customers-icon svg {
  display: block;
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#customersView .customers-overflow__summary .customers-icon {
  color: var(--ds-color-ink, #24262d);
}

#customersView .customers-overflow__summary .customers-icon svg circle[fill] {
  fill: currentColor;
  stroke: none;
}

#customersView .customers-page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: var(--ds-space-4, 16px);
}

#customersView .customers-page-header__sub {
  margin: 4px 0 0;
}

#customersView .customers-page-header__actions {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

#customersView .customers-new-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--customers-control-h);
}

#customersView .customers-modern-toolbar {
  display: grid;
  gap: 10px;
  margin-bottom: var(--ds-space-3, 12px);
}

#customersView .customers-toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

#customersView .customers-archive-search.search,
#customersView .customers-archive-search.ds-search,
#customersView label.customers-archive-search {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  flex: 1 1 240px;
  flex-grow: 1;
  flex-shrink: 1;
  flex-basis: 240px;
  align-self: center;
  min-width: min(100%, 220px);
  max-width: 420px;
  min-height: var(--customers-control-h);
  height: var(--customers-control-h);
  max-height: var(--customers-control-h);
  padding: 0 12px;
  box-sizing: border-box;
  overflow: hidden;
  border: 1px solid var(--ds-color-line, var(--line, #e8ecef));
  border-radius: 8px;
  background: var(--ds-color-surface, #fff);
}

#customersView .customers-archive-search .customers-icon {
  flex-shrink: 0;
}

#customersView .customers-archive-search input,
#customersView .customers-archive-search .ds-input {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  box-shadow: none;
  font-size: 14px;
  line-height: 1.2;
}

#customersView .customers-archive-search input:focus-visible,
#customersView .customers-archive-search .ds-input:focus-visible {
  outline: none;
  box-shadow: none;
}

#customersView .customers-list-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: var(--ds-space-3, 12px);
  font-size: 13px;
  color: var(--ds-color-muted, var(--muted, #6b7280));
}

#customersView .customers-table-wrap {
  width: 100%;
  border: 1px solid color-mix(in srgb, var(--ds-color-line, #e8ecef) 90%, transparent);
  border-radius: var(--customers-radius);
  background: var(--ds-color-surface, #fff);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

#customersView .customers-table,
#customersView .customers-table.ds-table-desktop {
  /* .ds-table-desktop { display:block } sütunları içeriğe sıkıştırıp sağda boşluk bırakıyor */
  display: table;
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 13px;
}

#customersView .customers-table th:nth-child(1),
#customersView .customers-table td:nth-child(1) {
  width: 30%;
}

#customersView .customers-table th:nth-child(2),
#customersView .customers-table td:nth-child(2) {
  width: 16%;
}

#customersView .customers-table th:nth-child(3),
#customersView .customers-table td:nth-child(3) {
  width: 26%;
}

#customersView .customers-table th:nth-child(4),
#customersView .customers-table td:nth-child(4) {
  width: 10%;
}

#customersView .customers-table th:nth-child(5),
#customersView .customers-table td:nth-child(5) {
  width: 12%;
}

#customersView .customers-table th:nth-child(6),
#customersView .customers-table td:nth-child(6) {
  width: 6%;
  text-align: right;
}

#customersView .customers-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ds-color-muted, #6b7280);
  padding: 10px 12px;
  border-bottom: 1px solid var(--ds-color-line, #e8ecef);
  white-space: nowrap;
  background: color-mix(in srgb, var(--ds-color-surface, #fff) 92%, var(--ds-color-line, #e8ecef));
}

#customersView .customers-table th:nth-child(6) {
  text-align: right;
}

#customersView .customers-table td {
  padding: 10px 12px;
  border-bottom: 1px solid color-mix(in srgb, var(--ds-color-line, #e8ecef) 70%, transparent);
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
}

#customersView .customers-table__row:hover td {
  background: color-mix(in srgb, var(--ds-color-accent-soft, #e4f4f1) 55%, transparent);
}

#customersView .customers-cell-primary {
  display: block;
  font-weight: 600;
  color: var(--ds-color-ink, #24262d);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#customersView .customers-cell-secondary,
#customersView .customers-table .task-meta {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  font-weight: 400;
  color: var(--ds-color-muted, #6b7280);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#customersView .customers-status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #eef6f3;
  color: var(--ds-color-accent-strong, #0b5f59);
}

#customersView .customers-row-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

#customersView .customers-view-btn {
  min-height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  background: var(--ds-color-surface, #fff);
  color: var(--ds-color-ink, #24262d);
  border: 1px solid var(--ds-color-line, #e8ecef);
  box-shadow: none;
}

#customersView .customers-view-btn:hover:not(:disabled) {
  background: color-mix(in srgb, var(--ds-color-accent-soft, #e4f4f1) 70%, #fff);
  border-color: color-mix(in srgb, var(--ds-color-accent, #0f766e) 35%, var(--ds-color-line, #e8ecef));
  color: var(--ds-color-ink, #24262d);
}

#customersView .customers-overflow {
  position: relative;
}

#customersView .customers-overflow__summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--ds-color-line, #e8ecef);
  background: var(--ds-color-surface, #fff);
  cursor: pointer;
}

#customersView .customers-overflow__summary::-webkit-details-marker {
  display: none;
}

#customersView .customers-overflow__summary:focus-visible {
  outline: 2px solid var(--ds-color-accent, #0f766e);
  outline-offset: 2px;
}

#customersView .customers-overflow__menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 40;
  width: 180px;
  min-width: 168px;
  max-width: 200px;
  box-sizing: border-box;
  padding: 6px;
  border-radius: 10px;
  border: 1px solid var(--ds-color-line, #e8ecef);
  background: var(--ds-color-surface, #fff);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

#customersView .customers-overflow__menu.is-fixed-open {
  z-index: 1200;
}

#customersView .customers-overflow__item {
  display: flex;
  width: 100%;
  align-items: center;
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ds-color-ink, #24262d);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

#customersView .customers-overflow__item:hover,
#customersView .customers-overflow__item:focus-visible {
  background: color-mix(in srgb, var(--ds-color-accent-soft, #e4f4f1) 80%, #fff);
  outline: none;
}

#customersView .customers-overflow__item--danger {
  color: #b42318;
}

#customersView .customers-overflow__item--danger:hover,
#customersView .customers-overflow__item--danger:focus-visible {
  background: #fef3f2;
}

#customersView .customers-mobile-list {
  display: none;
  flex-direction: column;
  gap: 8px;
}

#customersView .customers-mobile-card {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--ds-color-line, #e8ecef);
  border-radius: var(--customers-radius);
  background: var(--ds-color-surface, #fff);
  cursor: pointer;
}

#customersView .customers-mobile-card__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

#customersView .customers-mobile-card__title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--ds-color-ink, #24262d);
}

#customersView .customers-mobile-card__meta {
  margin: 0;
  font-size: 12px;
  line-height: 1.35;
  color: var(--ds-color-muted, #6b7280);
}

#customersView .customers-mobile-card__chev {
  flex-shrink: 0;
  color: var(--ds-color-muted, #6b7280);
}

#customersView .customers-mobile-card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}

#customersView .customers-mobile-more {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--customers-touch-h);
  height: var(--customers-touch-h);
  min-width: var(--customers-touch-h);
  border-radius: 8px;
  border: 1px solid var(--ds-color-line, #e8ecef);
  background: var(--ds-color-surface, #fff);
  cursor: pointer;
}

#customersView .customers-action-sheet {
  position: fixed;
  inset: 0;
  z-index: 1400;
}

#customersView .customers-action-sheet__backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(15, 23, 42, 0.36);
  cursor: pointer;
}

#customersView .customers-action-sheet__panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  gap: 8px;
  padding: 10px 14px calc(14px + env(safe-area-inset-bottom, 0px));
  border-radius: 16px 16px 0 0;
  background: var(--ds-color-surface, #fff);
  box-shadow: 0 -8px 28px rgba(15, 23, 42, 0.12);
}

#customersView .customers-action-sheet__grab {
  width: 36px;
  height: 4px;
  margin: 2px auto 4px;
  border-radius: 999px;
  background: #d1d5db;
}

#customersView .customers-action-sheet__title {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ds-color-muted, #6b7280);
}

#customersView .customers-action-sheet__actions {
  display: grid;
  gap: 4px;
}

#customersView .customers-action-sheet__actions .ghost-button,
#customersView .customers-action-sheet__actions .primary-button,
#customersView .customers-action-sheet__item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: var(--customers-touch-h);
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--ds-color-line, #e8ecef);
  background: var(--ds-color-surface, #fff);
  color: var(--ds-color-ink, #24262d);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

#customersView .customers-action-sheet__item--danger {
  color: #b42318;
  border-color: color-mix(in srgb, #b42318 25%, #e8ecef);
}

#customersView .customers-action-sheet__cancel {
  min-height: var(--customers-touch-h);
  width: 100%;
}

@media (max-width: 767px) {
  #customersView .customers-page-header__title {
    font-size: 1.25rem;
  }

  #customersView .customers-new-btn {
    min-height: var(--customers-touch-h);
  }

  #customersView .customers-archive-search.search,
  #customersView .customers-archive-search.ds-search,
  #customersView label.customers-archive-search {
    flex: 1 1 100%;
    flex-grow: 0;
    max-width: none;
    width: 100%;
    min-height: var(--customers-touch-h);
    height: var(--customers-touch-h);
    max-height: var(--customers-touch-h);
  }

  #customersView .customers-table-wrap > table.customers-table,
  #customersView .customers-table.ds-table-desktop {
    display: none;
  }

  #customersView .customers-mobile-list,
  #customersView .mobile-customer-cards.customers-mobile-list {
    display: flex;
  }

  #customersView .customers-table-wrap {
    border: 0;
    background: transparent;
    overflow: visible;
  }
}

@media (min-width: 768px) {
  #customersView .customers-mobile-list,
  #customersView .mobile-customer-cards {
    display: none;
  }

  #customersView .customers-action-sheet {
    display: none;
  }
}

/* —— Customer create dialog (opt-in only) —— */
#dealDialog.is-customer-create {
  width: min(820px, calc(100vw - 28px));
  max-height: 90dvh;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid var(--ds-color-line, #e8ecef);
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.14);
}

#dealDialog.is-customer-create .form-grid > label.deal-field-opportunity-only {
  display: none;
}

#dealDialog.is-customer-create form {
  display: grid;
  gap: 16px;
  max-height: 90dvh;
  overflow: auto;
  padding: 20px;
  box-sizing: border-box;
}

#dealDialog.is-customer-create .dialog-heading {
  position: sticky;
  top: 0;
  z-index: 2;
  margin-bottom: 8px;
  padding-bottom: 8px;
  background: var(--ds-color-surface, #fff);
}

#dealDialog.is-customer-create .form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 14px;
}

#dealDialog.is-customer-create .form-grid > label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ds-color-ink, #24262d);
}

#dealDialog.is-customer-create .form-grid input,
#dealDialog.is-customer-create .form-grid select,
#dealDialog.is-customer-create .form-grid textarea {
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--ds-color-line, #e8ecef);
  border-radius: 8px;
  background: var(--ds-color-surface, #fff);
  font: inherit;
  font-weight: 400;
  box-sizing: border-box;
}

#dealDialog.is-customer-create .form-grid textarea {
  min-height: 72px;
  resize: vertical;
}

#dealDialog.is-customer-create .form-grid .full-span {
  grid-column: 1 / -1;
}

#dealDialog.is-customer-create .dialog-actions {
  position: sticky;
  bottom: 0;
  gap: 8px;
  padding-top: 12px;
  background: var(--ds-color-surface, #fff);
  border-top: 1px solid color-mix(in srgb, var(--ds-color-line, #e8ecef) 80%, transparent);
}

#dealDialog.is-customer-create .dialog-actions .primary-button,
#dealDialog.is-customer-create .dialog-actions .ghost-button {
  min-height: 40px;
  border-radius: 8px;
}

@media (max-width: 767px) {
  #dealDialog.is-customer-create {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
    border: 0;
    overflow-x: hidden;
  }

  #dealDialog.is-customer-create form {
    max-height: 100dvh;
    padding: 16px 16px 0;
    overflow-x: hidden;
    overflow-y: auto;
    /* Keep focused/last fields clear of sticky footer + home indicator */
    scroll-padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  }

  #dealDialog.is-customer-create .form-grid {
    grid-template-columns: 1fr;
    /* Scroll clearance for sticky Vazgeç / Müşteriyi Ekle bar */
    padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  }

  #dealDialog.is-customer-create .form-grid input,
  #dealDialog.is-customer-create .form-grid select,
  #dealDialog.is-customer-create .form-grid textarea,
  #dealDialog.is-customer-create .dialog-actions .primary-button,
  #dealDialog.is-customer-create .dialog-actions .ghost-button {
    min-height: 44px;
  }

  #dealDialog.is-customer-create .dialog-actions {
    padding: 12px 0 calc(12px + env(safe-area-inset-bottom, 0px));
  }
}

/* —— Customer detail dialog (scoped via .customers-detail-form) —— */
#dealDetailDialog:has(.customers-detail-form) {
  width: min(860px, calc(100vw - 28px));
  max-height: 90dvh;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid var(--ds-color-line, #e8ecef);
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.14);
  padding: 0;
}

#dealDetailDialog .customers-detail-form {
  display: grid;
  gap: 16px;
  max-height: 90dvh;
  overflow: auto;
  padding: 20px;
  box-sizing: border-box;
}

#dealDetailDialog .customers-detail-form .customers-detail-heading {
  position: sticky;
  top: 0;
  z-index: 3;
  margin-bottom: 0;
  padding-bottom: 10px;
  background: var(--ds-color-surface, #fff);
}

#dealDetailDialog .customers-detail-form .customers-detail-close {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--ds-color-line, #e8ecef);
  background: var(--ds-color-surface, #fff);
}

#dealDetailDialog .customers-detail-form .customers-detail-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--ds-color-line, #e8ecef);
  border-radius: 10px;
  background: color-mix(in srgb, var(--ds-color-surface, #fff) 92%, var(--ds-color-line, #e8ecef));
  box-shadow: none;
}

#dealDetailDialog .customers-detail-form .customers-detail-identity {
  display: grid;
  gap: 6px;
  min-width: 0;
}

#dealDetailDialog .customers-detail-form .customers-detail-contact,
#dealDetailDialog .customers-detail-form .customers-detail-owner {
  display: block;
  margin: 0;
  font-size: 14px;
  line-height: 1.35;
  color: var(--ds-color-ink, #24262d);
}

#dealDetailDialog .customers-detail-form .customers-detail-contact {
  font-weight: 600;
}

#dealDetailDialog .customers-detail-form .customers-detail-owner {
  font-weight: 400;
  color: var(--ds-color-muted, #6b7280);
}

#dealDetailDialog .customers-detail-form .customers-status {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #eef6f3;
  color: var(--ds-color-accent-strong, #0b5f59);
}

#dealDetailDialog .customers-detail-form .customers-detail-actions {
  flex-shrink: 0;
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

#dealDetailDialog .customers-detail-form .customers-detail-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 14px;
}

#dealDetailDialog .customers-detail-form .customers-detail-fields > label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ds-color-ink, #24262d);
}

#dealDetailDialog .customers-detail-form .customers-detail-fields input,
#dealDetailDialog .customers-detail-form .customers-detail-fields select,
#dealDetailDialog .customers-detail-form .customers-detail-fields textarea {
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--ds-color-line, #e8ecef);
  border-radius: 8px;
  background: var(--ds-color-surface, #fff);
  font: inherit;
  font-weight: 400;
  box-sizing: border-box;
}

#dealDetailDialog .customers-detail-form .customers-detail-fields textarea {
  min-height: 88px;
  resize: vertical;
}

#dealDetailDialog .customers-detail-form .customers-detail-fields .full-span {
  grid-column: 1 / -1;
}

#dealDetailDialog .customers-detail-form .customers-detail-related {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

#dealDetailDialog .customers-detail-form .detail-section {
  border: 1px solid var(--ds-color-line, #e8ecef);
  border-radius: 10px;
  padding: 12px;
  background: var(--ds-color-surface, #fff);
  box-shadow: none;
}

#dealDetailDialog .customers-detail-form .detail-section h3 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
}

@media (max-width: 767px) {
  #dealDetailDialog:has(.customers-detail-form) {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
    border: 0;
  }

  #dealDetailDialog .customers-detail-form {
    max-height: 100dvh;
    padding: 14px 14px calc(14px + env(safe-area-inset-bottom, 0px));
  }

  #dealDetailDialog .customers-detail-form .customers-detail-hero {
    flex-direction: column;
  }

  #dealDetailDialog .customers-detail-form .customers-detail-actions {
    width: 100%;
    justify-content: stretch;
  }

  #dealDetailDialog .customers-detail-form .customers-detail-actions .btn-compact,
  #dealDetailDialog .customers-detail-form .customers-detail-actions button {
    min-height: 44px;
  }

  #dealDetailDialog .customers-detail-form .customers-detail-fields,
  #dealDetailDialog .customers-detail-form .customers-detail-related {
    grid-template-columns: 1fr;
  }

  #dealDetailDialog .customers-detail-form .customers-detail-fields input,
  #dealDetailDialog .customers-detail-form .customers-detail-fields select,
  #dealDetailDialog .customers-detail-form .customers-detail-fields textarea {
    min-height: 44px;
  }
}
