/**
 * TEKAN ADS — Customers CRM (full-width table)
 */

#page-customers.cust-page {
  --cust-accent: var(--ds-color-primary);
}

#page-customers .ds-root {
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-2);
  width: 100%;
  max-width: none;
  margin: 0;
}

/* ─── Header ─── */
.cust-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--ds-space-2);
  flex-wrap: wrap;
}

.cust-header h1 {
  margin: 0;
  font-size: var(--ds-text-h1-size);
  font-weight: var(--ds-text-h1-weight);
  color: var(--ds-color-text);
}

.cust-header__sub {
  margin: 0.35rem 0 0;
  font-size: var(--ds-text-body-size);
  color: var(--ds-color-text-muted);
}

.cust-header__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ds-space-1);
}

/* ─── Import panel ─── */
.cust-import-panel {
  border: 1px solid var(--ds-color-border);
  border-radius: var(--ds-radius-card);
  background: var(--ds-color-surface);
  overflow: hidden;
}

.cust-import-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ds-space-1);
  padding: 0.85rem 1.25rem;
  cursor: pointer;
  user-select: none;
}

.cust-import-panel__head h2 {
  margin: 0;
  font-size: var(--ds-text-section-size);
  font-weight: var(--ds-text-section-weight);
  color: var(--ds-color-text-secondary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.cust-import-panel__body {
  padding: 0 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-2);
}

.cust-import-panel.is-collapsed .cust-import-panel__body {
  display: none;
}

.cust-import-panel.is-collapsed .cust-import-chevron {
  transform: rotate(-90deg);
}

.cust-import-chevron {
  transition: transform 150ms ease;
  color: var(--ds-color-text-muted);
}

.cust-import-guide {
  margin: 0;
  font-size: var(--ds-text-caption-size);
  color: var(--ds-color-text-muted);
  line-height: 1.55;
}

.cust-import-guide code {
  font-size: 0.85em;
  color: var(--ds-color-text-secondary);
}

.cust-dropzone {
  border: 1.5px dashed var(--ds-color-border);
  border-radius: var(--ds-radius-card);
  padding: 2rem 1.5rem;
  text-align: center;
  background: var(--ds-color-bg-subtle);
  transition: border-color 150ms ease, background 150ms ease;
  cursor: pointer;
}

.cust-dropzone.is-dragover {
  border-color: var(--cust-accent);
  background: var(--ds-color-primary-muted);
}

.cust-dropzone__icon {
  width: 2.5rem;
  height: 2.5rem;
  margin: 0 auto 0.75rem;
  border-radius: var(--ds-radius-card);
  background: var(--ds-color-secondary-muted);
  color: var(--cust-accent);
  display: flex;
  align-items: center;
  justify-content: center;
}

.cust-dropzone__title {
  margin: 0 0 0.25rem;
  font-weight: 560;
  color: var(--ds-color-text-secondary);
}

.cust-dropzone__hint {
  margin: 0;
  font-size: var(--ds-text-caption-size);
  color: var(--ds-color-text-muted);
}

.cust-dropzone input[type="file"] {
  display: none;
}

.cust-import-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ds-space-1);
  align-items: center;
}

.cust-import-preview {
  border: 1px solid var(--ds-color-border);
  border-radius: var(--ds-radius-input);
  overflow: auto;
  max-height: 220px;
}

.cust-import-preview table {
  width: 100%;
  font-size: var(--ds-text-caption-size);
}

.cust-import-preview th,
.cust-import-preview td {
  padding: 0.45rem 0.65rem;
  border-bottom: 1px solid var(--ds-color-divider);
  text-align: right;
  white-space: nowrap;
}

.cust-import-preview th {
  background: var(--ds-color-bg-subtle);
  color: var(--ds-color-text-muted);
  font-weight: 560;
  position: sticky;
  top: 0;
}

.cust-import-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.cust-import-stat {
  font-size: var(--ds-text-caption-size);
  padding: 0.25rem 0.6rem;
  border-radius: var(--ds-radius-full);
  background: var(--ds-color-bg-subtle);
  color: var(--ds-color-text-muted);
}

.cust-import-stat--ok { color: var(--ds-color-success); }
.cust-import-stat--warn { color: var(--ds-color-warning); }
.cust-import-stat--err { color: var(--ds-color-danger); }

/* ─── Filters ─── */
.cust-filter-bar {
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-1);
  padding: 1rem 1.25rem;
  border: 1px solid var(--ds-color-border);
  border-radius: var(--ds-radius-card);
  background: var(--ds-color-surface);
}

.cust-filter-bar__row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ds-space-1);
  align-items: flex-end;
}

.cust-filter-bar__search {
  position: relative;
  flex: 2;
  min-width: 200px;
}

.cust-filter-bar__search input {
  width: 100%;
  padding-inline-start: 2.25rem;
}

.cust-filter-bar__search i {
  position: absolute;
  inset-inline-start: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ds-color-text-muted);
  pointer-events: none;
}

.cust-filter-field {
  flex: 1;
  min-width: 120px;
}

.cust-filter-field .ds-select {
  width: 100%;
}

.cust-filter-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-inline-start: auto;
}

.cust-filter-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.35rem;
  border-radius: var(--ds-radius-full);
  background: var(--cust-accent);
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 700;
}

.cust-filter-badge.hidden {
  display: none;
}

/* ─── Table ─── */
.cust-table-shell {
  border: 1px solid var(--ds-color-border);
  border-radius: var(--ds-radius-card);
  background: var(--ds-color-surface);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.cust-table-scroll {
  overflow: auto;
  max-height: calc(100vh - 340px);
  min-height: 320px;
}

.cust-table {
  width: 100%;
  min-width: 900px;
}

.cust-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--ds-color-bg-subtle);
  font-size: var(--ds-text-caption-size);
  font-weight: 560;
  color: var(--ds-color-text-muted);
  text-transform: none;
  letter-spacing: 0;
  border-bottom: 1px solid var(--ds-color-border);
  padding: 0.75rem 1rem;
  white-space: nowrap;
}

.cust-table tbody td {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--ds-color-divider);
  font-size: var(--ds-text-body-size);
  color: var(--ds-color-text-secondary);
  vertical-align: middle;
}

.cust-table tbody tr {
  cursor: pointer;
  transition: background 120ms ease;
}

.cust-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.cust-table tbody tr.cust-row--selected {
  background: var(--ds-color-primary-muted);
}

.cust-row__person {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.cust-avatar {
  width: 2rem;
  height: 2rem;
  border-radius: var(--ds-radius-full);
  background: linear-gradient(135deg, var(--ds-color-primary-muted), var(--ds-color-secondary-muted));
  color: var(--cust-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--ds-text-caption-size);
  font-weight: 700;
  flex-shrink: 0;
}

.cust-row__name {
  font-weight: 560;
  color: var(--ds-color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cust-row__sub {
  font-size: var(--ds-text-caption-size);
  color: var(--ds-color-text-muted);
}

.cust-groups {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.cust-group-tag {
  font-size: 0.6875rem;
  padding: 0.15rem 0.45rem;
  border-radius: var(--ds-radius-full);
  background: var(--ds-color-primary-muted);
  color: var(--cust-accent);
  max-width: 6rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cust-row-actions {
  display: flex;
  gap: 0.2rem;
  opacity: 0;
  transition: opacity 120ms ease;
}

.cust-table tbody tr:hover .cust-row-actions {
  opacity: 1;
}

.cust-table-empty {
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--ds-color-text-muted);
}

.cust-table-empty i {
  display: block;
  margin: 0 auto 0.75rem;
  opacity: 0.45;
}

/* ─── Footer / pagination ─── */
.cust-table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ds-space-1);
  flex-wrap: wrap;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--ds-color-divider);
  background: var(--ds-color-bg-subtle);
}

.cust-table-footer__meta {
  font-size: var(--ds-text-caption-size);
  color: var(--ds-color-text-muted);
}

.cust-pagination {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ─── Drawer ─── */
.cust-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 900;
  display: none;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}

.cust-drawer-backdrop.is-open {
  display: block;
  opacity: 1;
  pointer-events: auto;
}

.cust-drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  inset-inline-end: 0;
  width: min(480px, 100vw);
  z-index: 901;
  background: var(--ds-color-surface);
  border-inline-start: 1px solid var(--ds-color-border);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.35);
  display: none;
  flex-direction: column;
}

.cust-drawer.is-open {
  display: flex;
}

.cust-drawer__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ds-space-1);
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--ds-color-divider);
  flex-shrink: 0;
}

.cust-drawer__head h2 {
  margin: 0;
  font-size: var(--ds-text-section-size);
  font-weight: var(--ds-text-section-weight);
  color: var(--ds-color-text);
}

.cust-drawer__body {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.5rem;
}

.cust-drawer__foot {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--ds-color-divider);
  display: flex;
  gap: var(--ds-space-1);
  flex-shrink: 0;
}

.cust-form-hint {
  margin: 0 0 var(--ds-space-2);
  font-size: var(--ds-text-caption-size);
  color: var(--ds-color-text-muted);
  line-height: 1.5;
}

.cust-form-sections {
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-1);
}

.cust-form-section {
  position: relative;
  border: 1px solid var(--ds-color-border);
  border-radius: var(--ds-radius-input);
  overflow: visible;
  background: var(--ds-color-bg-subtle);
}

/* Elevate section while group/suggest dropdown is open so it paints above next sections */
.cust-form-section:has(.ajax-multi-select-dropdown:not(.hidden)),
.cust-form-section:has(.field-suggest-dropdown:not(.hidden)),
.cust-form-section.has-dropdown-open {
  z-index: 8;
}

.cust-form-section__toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border: none;
  background: transparent;
  color: var(--ds-color-text-secondary);
  font-size: var(--ds-text-card-title-size);
  font-weight: var(--ds-text-card-title-weight);
  cursor: pointer;
  text-align: right;
}

.cust-form-section__toggle i {
  transition: transform 150ms ease;
  opacity: 0.6;
}

.cust-form-section.is-open .cust-form-section__toggle i {
  transform: rotate(180deg);
}

.cust-form-section__body {
  display: none;
  padding: 0 1rem 1rem;
  gap: 0.75rem;
}

.cust-form-section.is-open .cust-form-section__body {
  display: flex;
  flex-direction: column;
}

.cust-form-section.is-open.cust-form-section--grid .cust-form-section__body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 480px) {
  .cust-form-section.is-open.cust-form-section--grid .cust-form-section__body {
    grid-template-columns: 1fr;
  }
}

/* Group picker dropdown — must float above collapsible sections in drawer */
.cust-drawer .ajax-multi-select {
  position: relative;
  z-index: 1;
}

.cust-drawer .ajax-multi-select-input-wrap {
  position: relative;
}

.cust-drawer .ajax-multi-select-dropdown,
.cust-drawer .field-suggest-dropdown {
  z-index: var(--ds-z-dropdown, 1000);
  background: var(--ds-color-card);
  border: 1px solid var(--ds-color-border-strong);
  border-radius: var(--ds-radius-input);
  box-shadow: var(--ds-shadow-lg);
}
