/**
 * Offers UI pilot — scoped under #offersView only.
 * Generic primitives live in design-system.css (.ds-*).
 * mobile.css stays last for layout overrides.
 *
 * Visibility note: desktop table vs mobile list is switched in JS
 * (renderOfferArchive / MobileOffers). No !important needed here.
 */

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

#offersView .offers-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));
}

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

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

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

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

#offersView .offers-page-header__sub {
  margin: 4px 0 0;
}

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

#offersView .offers-new-btn {
  order: 1;
}

#offersView .offers-quick-btn {
  order: 2;
  background: var(--ds-color-surface, #fff);
  color: var(--ds-color-accent-strong, #0b5f59);
  border: 1px solid color-mix(in srgb, var(--ds-color-accent, #0f766e) 32%, var(--ds-color-line, #e8ecef));
  box-shadow: none;
}

#offersView .offers-quick-btn:hover:not(:disabled) {
  background: var(--ds-color-accent-soft, #e4f4f1);
  border-color: color-mix(in srgb, var(--ds-color-accent, #0f766e) 45%, var(--ds-color-line, #e8ecef));
  color: var(--ds-color-accent-strong, #0b5f59);
}

#offersView .offers-tabs.offer-tabs {
  display: flex;
  flex-wrap: nowrap;
  gap: 2px;
  margin-bottom: var(--ds-space-4, 16px);
  border-bottom: 1px solid var(--ds-color-line, var(--line, #e8ecef));
  padding-bottom: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

#offersView .offers-tabs.offer-tabs::-webkit-scrollbar {
  display: none;
}

#offersView .offer-tab.ds-tabs__tab {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 6px 6px 0 0;
  background: transparent;
  color: var(--ds-color-muted, var(--muted, #6b7280));
  font-weight: 500;
  white-space: nowrap;
}

#offersView .offer-tab.ds-tabs__tab:hover {
  color: var(--ds-color-ink, var(--ink, #24262d));
}

#offersView .offer-tab.ds-tabs__tab.active,
#offersView .offer-tab.ds-tabs__tab[aria-selected="true"] {
  color: var(--ds-color-accent-strong, var(--accent-strong, #0b5f59));
  border-bottom-color: var(--ds-color-accent, var(--accent, #0f766e));
  font-weight: 600;
  background: transparent;
  box-shadow: none;
}

#offersView .offer-tab.ds-tabs__tab:focus-visible {
  outline: 2px solid var(--ds-color-accent, var(--accent, #0f766e));
  outline-offset: 2px;
}

#offersView .offers-archive-panel {
  border: 1px solid color-mix(in srgb, var(--ds-color-line, #e8ecef) 90%, transparent);
  border-radius: var(--offers-radius);
  box-shadow: none;
  padding: var(--ds-space-4, 16px);
  background: var(--ds-color-surface, var(--surface, #fff));
}

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

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

#offersView .offers-toolbar-actions {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

#offersView .offers-modern-filters {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  width: 100%;
}

#offersView .offers-modern-filters.is-open,
#offersView .offer-list-toolbar__filters.is-open.offers-modern-filters {
  display: flex;
}

/* Do not use flex-grow in column toolbars — that inflated mobile search height */
#offersView .offers-archive-search.search,
#offersView .offers-archive-search.ds-search,
#offersView label.offers-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(--offers-control-h);
  height: var(--offers-control-h);
  max-height: var(--offers-control-h);
  padding: 0 12px;
  box-sizing: border-box;
  overflow: hidden;
}

#offersView .offers-archive-search .offers-icon {
  flex-shrink: 0;
}

#offersView .offers-archive-search input,
#offersView .offers-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;
}

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

#offersView .offers-filters-toggle,
#offersView .offers-export-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--offers-control-h);
}

#offersView .offers-filters-toggle[aria-expanded="true"] {
  border-color: var(--ds-color-accent, var(--accent, #0f766e));
  color: var(--ds-color-accent-strong, var(--accent-strong, #0b5f59));
}

#offersView .offers-filter-select {
  flex: 1 1 160px;
  min-width: 148px;
  max-width: 240px;
  min-height: var(--offers-control-h);
  border-radius: 8px;
  border: 1px solid var(--ds-color-line, var(--line, #e8ecef));
  background: var(--ds-color-surface, #fff);
  padding: 0 12px;
}

#offersView .offers-filter-select:focus-visible {
  outline: 2px solid var(--ds-color-accent, var(--accent, #0f766e));
  outline-offset: 1px;
}

#offersView .offers-list-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 12px;
  padding: 0 2px;
  color: var(--ds-color-muted, var(--muted, #6b7280));
  font-size: 13px;
}

#offersView .offers-list-summary strong {
  color: var(--ds-color-ink, var(--ink, #24262d));
  font-weight: 600;
  font-size: 13px;
}

#offersView .offers-table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--ds-color-line, var(--line, #e8ecef));
  border-radius: var(--offers-radius);
}

#offersView .offers-table {
  display: table;
  width: 100%;
  min-width: 920px;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 14px;
}

#offersView .offers-table th:nth-child(1),
#offersView .offers-table td:nth-child(1) { width: 14%; }
#offersView .offers-table th:nth-child(2),
#offersView .offers-table td:nth-child(2) { width: 22%; }
#offersView .offers-table th:nth-child(3),
#offersView .offers-table td:nth-child(3) { width: 12%; }
#offersView .offers-table th:nth-child(4),
#offersView .offers-table td:nth-child(4) { width: 16%; }
#offersView .offers-table th:nth-child(5),
#offersView .offers-table td:nth-child(5) { width: 12%; }
#offersView .offers-table th:nth-child(6),
#offersView .offers-table td:nth-child(6) { width: 12%; }
#offersView .offers-table th:nth-child(7),
#offersView .offers-table td:nth-child(7) {
  width: 12%;
  min-width: 148px;
  text-align: right;
}

#offersView .offers-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--ds-color-muted, var(--muted, #6b7280));
  padding: 10px 12px;
  border-bottom: 1px solid var(--ds-color-line, var(--line, #e8ecef));
  background: color-mix(in srgb, var(--ds-color-surface-muted, #f8faf9) 70%, #fff);
  white-space: nowrap;
}

#offersView .offers-table td {
  padding: 10px 12px;
  border-bottom: 1px solid color-mix(in srgb, var(--ds-color-line, #e8ecef) 85%, transparent);
  vertical-align: middle;
}

#offersView .offers-table__row:hover td {
  background: color-mix(in srgb, var(--ds-color-accent-soft, #e4f4f1) 35%, #fff);
}

#offersView .offers-cell-primary,
#offersView .offers-cell-stack {
  display: grid;
  gap: 2px;
  min-width: 0;
}

#offersView .offers-offer-no {
  font-weight: 600;
}

#offersView .offers-offer-date,
#offersView .offers-contact {
  font-size: 12px;
  line-height: 1.3;
}

#offersView .offers-customer {
  font-weight: 500;
}

#offersView .offers-status-select,
#offersView .offers-invoice-select {
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
  max-width: 170px;
}

#offersView .offers-status-select.ds-status--success,
#offersView .offers-invoice-select.is-issued {
  background: color-mix(in srgb, var(--ds-color-success-soft, #eaf8ef) 75%, #fff);
  color: var(--ds-color-success, #15803d);
}

#offersView .offers-status-select.ds-status--info {
  background: color-mix(in srgb, var(--ds-color-info-soft, #eaf1ff) 70%, #fff);
  color: color-mix(in srgb, var(--ds-color-info, #2563eb) 85%, #1e3a5f);
}

#offersView .offers-status-select.ds-status--danger,
#offersView .offers-status-select.is-cancelled {
  background: color-mix(in srgb, var(--ds-color-danger-soft, #fdecea) 75%, #fff);
  color: var(--ds-color-danger, #b42318);
}

#offersView .offers-invoice-select.not-issued {
  background: color-mix(in srgb, var(--ds-color-surface-muted, #eef6f3) 55%, #fff);
  color: var(--ds-color-muted, #6b7280);
}

#offersView .offers-invoice-select.is-draft {
  background: color-mix(in srgb, var(--ds-color-warning-soft, #fff6e5) 80%, #fff);
  color: var(--ds-color-warning, #b45309);
}

#offersView .offers-row-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  flex-wrap: nowrap;
  width: 100%;
}

#offersView .offers-row-actions .crm-icon-action.table-action-button {
  width: 32px;
  height: 32px;
  min-height: 32px;
  min-width: 32px;
  border-radius: 8px;
  box-shadow: none;
  background: var(--ds-color-surface, #fff);
}

#offersView .offers-row-actions .crm-icon-action.table-action-button svg {
  width: 16px;
  height: 16px;
}

#offersView .offers-row-actions .crm-icon-action.is-disabled,
#offersView .offers-row-actions .crm-icon-action:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/*
 * Beat .ds-button (white-on-accent) collision: ghost view must stay readable.
 * Specificity intentionally includes .ds-button / .ghost-button.
 */
#offersView .offers-view-btn,
#offersView .offers-view-btn.ds-button,
#offersView .offers-view-btn.ds-button--ghost,
#offersView .offers-view-btn.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  height: 32px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  color: var(--ds-color-ink, #24262d);
  background: var(--ds-color-surface, #fff);
  border: 1px solid var(--ds-color-line, #e8ecef);
  border-radius: 8px;
  box-shadow: none;
}

#offersView .offers-view-btn:hover:not(:disabled),
#offersView .offers-view-btn.ds-button:hover:not(:disabled) {
  background: var(--ds-color-surface-muted, #eef6f3);
  border-color: color-mix(in srgb, var(--ds-color-accent, #0f766e) 28%, var(--ds-color-line, #e8ecef));
  color: var(--ds-color-ink, #24262d);
}

#offersView .offers-view-btn:focus-visible {
  outline: 2px solid var(--ds-color-accent, #0f766e);
  outline-offset: 2px;
}

#offersView .offers-overflow {
  position: relative;
}

#offersView .offers-overflow__summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  min-width: 32px;
  min-height: 32px;
  border: 1px solid var(--ds-color-line, var(--line, #e8ecef));
  border-radius: 8px;
  background: var(--ds-color-surface, #fff);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  color: var(--ds-color-ink, var(--ink, #24262d));
  padding: 0;
}

#offersView .offers-overflow__summary::-webkit-details-marker {
  display: none;
}

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

#offersView .offers-overflow__menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: var(--ds-z-dropdown, 40);
  min-width: 168px;
  padding: 4px;
  border: 1px solid var(--ds-color-line, var(--line, #e8ecef));
  border-radius: 10px;
  background: var(--ds-color-surface, #fff);
  box-shadow: var(--ds-shadow-md, 0 8px 20px rgba(36, 38, 45, 0.08));
}

#offersView .offers-overflow__menu.is-fixed-open {
  position: fixed;
  right: auto;
  z-index: 80;
}

#offersView .offers-overflow__item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 6px;
  padding: 8px 10px;
  min-height: 36px;
  font: inherit;
  font-size: 13px;
  color: var(--ds-color-ink, var(--ink, #24262d));
  cursor: pointer;
}

#offersView .offers-overflow__item:hover:not(:disabled) {
  background: var(--ds-color-surface-muted, #eef6f3);
}

#offersView .offers-overflow__item:focus-visible {
  outline: 2px solid var(--ds-color-accent, var(--accent, #0f766e));
  outline-offset: 1px;
}

#offersView .offers-overflow__item--danger {
  color: var(--ds-color-danger, #b42318);
}

#offersView .offers-overflow__item:disabled,
#offersView .offers-overflow__item.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#offersView .offers-archive .empty-state,
#offersView .offers-empty {
  border-radius: var(--offers-radius);
  border: 1px dashed var(--ds-color-line, var(--line, #e8ecef));
  color: var(--ds-color-muted, var(--muted, #6b7280));
  min-height: 140px;
}

#offersView .offers-mobile-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#offersView .offers-mobile-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 8px;
  align-items: start;
  border: 1px solid var(--ds-color-line, var(--line, #e8ecef));
  border-radius: 8px;
  background: var(--ds-color-surface, #fff);
  padding: 8px 10px;
}

#offersView .offers-mobile-card__actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  align-self: center;
}

#offersView .offers-mobile-icon-btn,
#offersView .offers-mobile-more {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--offers-touch-h);
  height: var(--offers-touch-h);
  min-width: var(--offers-touch-h);
  min-height: var(--offers-touch-h);
  padding: 0;
  border: 1px solid var(--ds-color-line, #e8ecef);
  border-radius: 10px;
  background: var(--ds-color-surface, #fff);
  color: var(--ds-color-ink, #24262d);
  cursor: pointer;
}

#offersView .offers-mobile-icon-btn .offers-icon,
#offersView .offers-mobile-more .offers-icon {
  width: 18px;
  height: 18px;
  color: inherit;
}

#offersView .offers-mobile-icon-btn .offers-icon svg,
#offersView .offers-mobile-more .offers-icon svg {
  width: 18px;
  height: 18px;
}

#offersView .offers-mobile-icon-btn:focus-visible,
#offersView .offers-mobile-more:focus-visible {
  outline: 2px solid var(--ds-color-accent, #0f766e);
  outline-offset: 2px;
}

#offersView .offers-mobile-card__main {
  display: grid;
  gap: 4px;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0;
  min-width: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

#offersView .offers-mobile-card__main:focus-visible {
  outline: 2px solid var(--ds-color-accent, var(--accent, #0f766e));
  outline-offset: 2px;
  border-radius: 6px;
}

#offersView .offers-mobile-card__top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}

#offersView .offers-mobile-card__no {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
}

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

#offersView .offers-mobile-card__party {
  display: flex;
  flex-wrap: wrap;
  gap: 0 6px;
  margin: 0;
  font-size: 13px;
  line-height: 1.3;
}

#offersView .offers-mobile-card__party .muted-text::before {
  content: "·";
  margin-right: 6px;
  color: var(--ds-color-muted, #6b7280);
}

#offersView .offers-mobile-card__statuses {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

#offersView .offers-mobile-more {
  width: 40px;
  min-width: 40px;
  min-height: 40px;
  align-self: start;
}

#offersView .offers-action-sheet {
  position: fixed;
  inset: 0;
  /* Above .mobile-bottom-nav (z-index: 2000) so last actions stay tappable */
  z-index: 2100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: calc(var(--mobile-bottom-nav-h, 4rem) + var(--mobile-safe-bottom, env(safe-area-inset-bottom, 0px)));
  box-sizing: border-box;
}

#offersView .offers-action-sheet[hidden] {
  display: none;
}

#offersView .offers-action-sheet__backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  padding: 0;
  margin: 0;
  background: rgba(15, 23, 42, 0.42);
  cursor: pointer;
}

#offersView .offers-action-sheet__panel {
  position: relative;
  z-index: 1;
  width: min(100%, 480px);
  max-height: min(70vh, 420px);
  overflow: auto;
  border-radius: 14px 14px 0 0;
  background: var(--ds-color-surface, #fff);
  box-shadow: 0 -6px 24px rgba(15, 23, 42, 0.14);
  padding: 8px 10px 12px;
}

#offersView .offers-action-sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px 8px;
  border-bottom: 1px solid var(--ds-color-line, var(--line, #e8ecef));
  margin-bottom: 4px;
}

#offersView .offers-action-sheet__close {
  min-height: 40px;
  min-width: 64px;
  border: 0;
  border-radius: 8px;
  background: var(--ds-color-surface-muted, #eef6f3);
  color: var(--ds-color-ink, var(--ink, #24262d));
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

#offersView .offers-action-sheet__actions {
  display: grid;
  gap: 0;
}

#offersView .offers-action-sheet__actions .offers-overflow__item {
  min-height: 50px;
  padding: 12px 12px;
  font-size: 15px;
  border-radius: 8px;
}

#offersView .offers-action-sheet__actions .offers-overflow__item.is-primary-action {
  font-weight: 650;
  color: var(--ds-color-accent, var(--accent, #0f766e));
}

@media (max-width: 767px) {
  #offersView .offers-page-header {
    align-items: center;
    gap: 8px;
  }

  #offersView .offers-page-header__sub {
    display: none;
  }

  #offersView .offers-page-header__actions {
    gap: 6px;
  }

  #offersView .offers-page-header__actions .offers-new-btn,
  #offersView .offers-page-header__actions .offers-quick-btn {
    min-height: var(--offers-touch-h);
    padding: 0 10px;
    font-size: 13px;
  }

  #offersView .offer-tab.ds-tabs__tab {
    min-height: 34px;
    padding: 0 10px;
    font-size: 13px;
  }

  #offersView .offers-toolbar-row {
    flex-direction: column;
    align-items: stretch;
    flex-wrap: nowrap;
  }

  #offersView .offers-toolbar-actions {
    margin-left: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  #offersView .offers-archive-search.search,
  #offersView .offers-archive-search.ds-search,
  #offersView label.offers-archive-search {
    flex: 0 0 auto;
    flex-grow: 0;
    flex-shrink: 0;
    flex-basis: auto;
    width: 100%;
    max-width: none;
    min-width: 0;
    min-height: var(--offers-touch-h);
    height: var(--offers-touch-h);
    max-height: var(--offers-touch-h);
  }

  #offersView .offers-archive-search input,
  #offersView .offers-archive-search .ds-input {
    font-size: 16px; /* iOS zoom guard */
  }

  #offersView .offers-modern-filters.is-open {
    flex-direction: column;
    align-items: stretch;
    padding: 10px;
    border: 1px solid var(--ds-color-line, var(--line, #e8ecef));
    border-radius: 10px;
    background: color-mix(in srgb, var(--ds-color-surface-muted, #f8faf9) 80%, #fff);
  }

  #offersView .offers-filter-select,
  #offersView .offers-filters-toggle,
  #offersView .offers-export-btn {
    max-width: none;
    width: 100%;
    min-height: var(--offers-touch-h);
  }

  #offersView .offers-archive-panel {
    padding: 10px;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    box-shadow: none;
  }
}

@media (min-width: 768px) and (max-width: 1100px) {
  #offersView .offers-row-actions .crm-icon-action.table-action-button,
  #offersView .offers-overflow__summary {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
  }

  #offersView .offers-table th:nth-child(7),
  #offersView .offers-table td:nth-child(7) {
    width: 16%;
    min-width: 176px;
  }
}

@media (min-width: 768px) {
  #offersView .offers-action-sheet {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  #offersView .offers-table__row,
  #offersView .offers-overflow__item {
    transition: none;
  }
}
