/* =============================================================
   TR Frontend Manager — Responsive Overrides
   Mobile-first breakpoints: 480 / 600 / 768 / 1024 / 1280
   ============================================================= */

/* ── Mobile: collapse table to cards ──────────────────────── */
@media (max-width: 599px) {
  .tr-fm-table thead {
    display: none;
  }

  .tr-fm-table,
  .tr-fm-table tbody,
  .tr-fm-table tr,
  .tr-fm-table td {
    display: block;
    width: 100%;
  }

  .tr-fm-table tr {
    border: 1px solid var(--tr-fm-border);
    border-radius: var(--tr-fm-radius);
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: var(--tr-fm-surface);
  }

  .tr-fm-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--tr-fm-border);
    font-size: 0.875rem;
  }

  .tr-fm-table td:last-child {
    border-bottom: 0;
  }

  .tr-fm-table td::before {
    content: attr(data-label);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--tr-fm-text-muted);
    margin-right: 0.5rem;
    flex-shrink: 0;
  }

  /* Hide checkbox column — bulk select doesn't work in card mode */
  .tr-fm-table .tr-fm-table__check {
    display: none;
  }

  /* Product cell: allow info to wrap below the label */
  .tr-fm-table td[data-label] {
    flex-wrap: wrap;
    row-gap: 0.375rem;
  }

  /* Product cell thumbnail + info stack naturally */
  .tr-fm-product-cell {
    flex: 1;
  }

  .tr-fm-product-cell__name,
  .tr-fm-product-cell__cats {
    max-width: 100%;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }

  /* Actions cell: left-align and wrap buttons */
  .tr-fm-table__actions {
    text-align: left;
    white-space: normal;
    flex-wrap: wrap;
    gap: 0.375rem;
    display: flex;
  }

  .tr-fm-table__actions .tr-fm-btn + .tr-fm-btn {
    margin-left: 0;
  }

  /* Bulk bar hidden on mobile (no checkboxes) */
  .tr-fm-bulk-bar {
    display: none !important;
  }

  /* Tabs scroll horizontally instead of wrapping */
  .tr-fm-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }
  .tr-fm-tabs::-webkit-scrollbar { display: none; }

  /* Search bar: stack button below input */
  .tr-fm-search-bar__inner {
    flex-wrap: wrap;
  }

  .tr-fm-search-bar__input {
    flex-basis: 100%;
    order: -1;
  }
}

/* ── Medium screens: 2-col stat grid ──────────────────────── */
@media (min-width: 480px) and (max-width: 767px) {
  .tr-fm-content {
    padding: 1.25rem;
  }

  .tr-fm-section {
    padding: 1.25rem;
  }
}

/* ── Tablet+: show sidebar ─────────────────────────────────── */
@media (min-width: 1024px) {
  .tr-fm-wrap {
    align-items: flex-start;
  }

  .tr-fm-sidebar {
    height: 100vh;
    position: sticky;
    transform: none !important;
  }

  .tr-fm-main {
    padding-top: 0;
  }

  .tr-fm-mobile-bar {
    display: none;
  }

  .tr-fm-overlay {
    display: none !important;
  }
}

/* ── Product form grid: 2-col on wide, stacked on mobile ───── */
.tr-fm-form__grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

.tr-fm-field-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

.tr-fm-order-detail__grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

@media (min-width: 600px) {
  .tr-fm-field-row {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 768px) {
  .tr-fm-order-detail__grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 1024px) {
  .tr-fm-form__grid {
    grid-template-columns: 1fr 320px;
  }
}

/* ── Product cell with thumbnail ───────────────────────────── */
.tr-fm-product-cell {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.tr-fm-product-cell__img {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
}

/* ── Profile header card ───────────────────────────────────── */
.tr-fm-profile__header-card {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.tr-fm-profile__avatar {
  border-radius: 50%;
  object-fit: cover;
}

/* ── Section header with back button ──────────────────────── */
.tr-fm-section__header--with-back {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* ── Image / media upload area ─────────────────────────────── */
.tr-fm-product-image-upload,
.tr-fm-media-upload {
  border: 2px dashed var(--tr-fm-border, #e0e0e0);
  border-radius: 8px;
  padding: 1.25rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.tr-fm-product-image-upload__preview,
.tr-fm-media-upload__preview {
  max-width: 100%;
  border-radius: 6px;
}

/* ── Social field inline icon ──────────────────────────────── */
.tr-fm-field--social .tr-fm-label {
  font-weight: 500;
}

/* ── Empty state ───────────────────────────────────────────── */
.tr-fm-empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--tr-fm-text-muted, #888);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

/* ── Messages layout ───────────────────────────────────────── */
.tr-fm-messages__layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

@media (min-width: 768px) {
  .tr-fm-messages__layout {
    grid-template-columns: 260px 1fr;
    align-items: start;
  }
}

.tr-fm-messages__thread-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tr-fm-messages__thread-link {
  display: flex;
  flex-direction: column;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--tr-fm-border, #e0e0e0);
  text-decoration: none;
  color: inherit;
}

.tr-fm-messages__thread.is-active .tr-fm-messages__thread-link,
.tr-fm-messages__thread-link:hover {
  background: var(--tr-fm-bg-hover, #f5f5f5);
}

.tr-fm-messages__thread-preview {
  font-size: 0.8125rem;
  color: var(--tr-fm-text-muted, #888);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

.tr-fm-messages__pane {
  min-height: 300px;
  display: flex;
  flex-direction: column;
}

.tr-fm-messages__history {
  flex: 1;
  overflow-y: auto;
  max-height: 400px;
  padding: 1rem;
  border: 1px solid var(--tr-fm-border, #e0e0e0);
  border-radius: 8px 8px 0 0;
  margin-bottom: 0;
}

.tr-fm-messages__compose {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.tr-fm-messages__textarea {
  flex: 1;
  border-radius: 0 0 8px 8px;
}

.tr-fm-msg {
  margin-bottom: 0.75rem;
}

.tr-fm-msg--mine {
  text-align: right;
}

.tr-fm-msg p {
  display: inline-block;
  background: var(--tr-fm-bg-hover, #f0f0f0);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  max-width: 75%;
  word-break: break-word;
}

.tr-fm-msg--mine p {
  background: var(--tr-fm-primary, #2563eb);
  color: #fff;
}

/* ── Enquiry reply row ─────────────────────────────────────── */
.tr-fm-enquiry-original {
  background: var(--tr-fm-bg-hover, #f9f9f9);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}

.tr-fm-enquiry-reply-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

/* ── Support ticket replies ────────────────────────────────── */
.tr-fm-support-reply {
  padding: 1rem;
  border-left: 3px solid var(--tr-fm-border, #e0e0e0);
  margin-bottom: 1rem;
  background: var(--tr-fm-bg-hover, #f9f9f9);
  border-radius: 0 6px 6px 0;
}

.tr-fm-support-reply--admin {
  border-left-color: var(--tr-fm-primary, #2563eb);
  background: #eff6ff;
}

.tr-fm-support-reply__meta {
  display: flex;
  gap: 0.75rem;
  font-size: 0.8125rem;
  color: var(--tr-fm-text-muted, #888);
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

/* ── Medium screens: hide low-priority product table columns ── */
@media (min-width: 600px) and (max-width: 899px) {
  /* Hide SKU (col 3) and Date (col 7) to prevent overflow */
  .tr-fm-products__table th:nth-child(3),
  .tr-fm-products__table td:nth-child(3),
  .tr-fm-products__table th:nth-child(7),
  .tr-fm-products__table td:nth-child(7) {
    display: none;
  }

  /* Keep search bar from spanning full width */
  .tr-fm-search-bar__inner {
    max-width: 480px;
  }
}

@media (min-width: 900px) {
  .tr-fm-search-bar__inner {
    max-width: 560px;
  }

  .tr-fm-product-cell__name,
  .tr-fm-product-cell__cats {
    max-width: 280px;
  }
}

/* ── Print Styles ──────────────────────────────────────────── */
@media print {
  .tr-fm-sidebar,
  .tr-fm-mobile-bar,
  .tr-fm-form-actions,
  .tr-fm-pagination,
  .tr-fm-btn:not(.no-print) {
    display: none !important;
  }

  .tr-fm-main {
    padding: 0;
  }

  .tr-fm-section {
    border: 1px solid #ccc;
    box-shadow: none;
  }

  .tr-fm-table {
    font-size: 0.8rem;
  }
}
