/* ==========================================================================
   Apple Design Direct Messages Styles - InstaFlux
   Clean, modern, compact, fluid, lightweight & zero-lag
   ========================================================================== */

:root {
  --apple-font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "SF Pro", system-ui, -system-ui, "Helvetica Neue", Helvetica, Arial, sans-serif;
  --apple-bg: #fbfbfd;
  --apple-subtle-bg: #f5f5f7;
  --apple-hover-bg: #f2f2f7;
  --apple-card-bg: #ffffff;
  --apple-card-border: rgba(0, 0, 0, 0.06);
  --apple-card-border-hover: rgba(0, 0, 0, 0.12);
  --apple-card-shadow: 0 1px 3px rgba(0, 0, 0, 0.03), 0 4px 12px rgba(0, 0, 0, 0.015);
  --apple-card-hover-shadow: 0 6px 20px -2px rgba(0, 0, 0, 0.06), 0 2px 6px rgba(0, 0, 0, 0.02);
  --apple-text-primary: #1d1d1f;
  --apple-text-secondary: #86868b;
  --apple-text-tertiary: #aeaeb2;
  --apple-accent: #7f35bd;
  --apple-accent-hover: #6d28a7;
  --apple-accent-light: rgba(127, 53, 189, 0.08);
  --apple-accent-border: rgba(127, 53, 189, 0.22);
  --apple-green: #34c759;
  --apple-green-light: rgba(52, 199, 89, 0.09);
  --apple-amber: #ff9500;
  --apple-amber-light: rgba(255, 149, 0, 0.09);
  --apple-red: #ff3b30;
  --apple-red-light: rgba(255, 59, 48, 0.09);
  --apple-ease: cubic-bezier(0.16, 1, 0.3, 1);
}

.direct-container {
  box-sizing: border-box;
  width: min(1040px, calc(100% - 36px));
  margin: 0 auto;
  padding: 22px 0 18px;
  color: var(--apple-text-primary);
  font-family: var(--apple-font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  letter-spacing: -0.011em;
}

#viewMensagensDirect.app-view.active {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 65px);
  background: var(--apple-bg);
}

.direct-header,
.direct-header-actions,
.direct-batch-bar,
.direct-batch-actions,
.direct-conversation-head,
.direct-message-meta,
.direct-reply-actions {
  display: flex;
  align-items: center;
}

.direct-header,
#directBatchBar {
  justify-content: space-between;
  gap: 16px;
}

.direct-header {
  margin-bottom: 4px;
}

.direct-header h2 {
  margin: 0;
  color: var(--apple-text-primary);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.024em;
  line-height: 1.25;
}

.direct-header p {
  margin: 3px 0 0;
  color: var(--apple-text-secondary);
  font-size: 13px;
  font-weight: 400;
  letter-spacing: -0.01em;
}

.direct-header-actions {
  gap: 7px;
}

/* Apple-style Action Buttons (Pill & Clean) */
.direct-refresh,
.direct-sort,
.direct-filter,
.direct-reply-button,
.direct-queue-button {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  height: 34px;
  border: 1px solid var(--apple-card-border);
  border-radius: 9999px;
  background: var(--apple-card-bg);
  color: var(--apple-text-primary);
  font-family: var(--apple-font);
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: -0.01em;
  padding: 0 13px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  transition: background 0.16s var(--apple-ease),
              border-color 0.16s var(--apple-ease),
              transform 0.16s var(--apple-ease),
              box-shadow 0.16s var(--apple-ease);
  user-select: none;
}

.direct-sort,
.direct-filter {
  width: 34px;
  min-width: 34px;
  padding: 0;
  font-size: 12px;
}

.direct-filter[aria-pressed="true"] {
  border-color: var(--apple-accent-border);
  background: var(--apple-accent-light);
  color: var(--apple-accent);
  font-weight: 600;
}

.direct-sort[aria-pressed="true"] {
  border-color: var(--apple-accent-border);
  background: var(--apple-accent-light);
  color: var(--apple-accent);
}

.direct-refresh:hover:not(:disabled),
.direct-sort:hover:not(:disabled),
.direct-filter:hover:not(:disabled),
.direct-reply-button:hover:not(:disabled),
.direct-queue-button:hover:not(:disabled) {
  border-color: var(--apple-card-border-hover);
  background: var(--apple-subtle-bg);
  color: var(--apple-text-primary);
}

.direct-refresh:active:not(:disabled),
.direct-sort:active:not(:disabled),
.direct-filter:active:not(:disabled),
.direct-reply-button:active:not(:disabled),
.direct-queue-button:active:not(:disabled) {
  transform: scale(0.97);
}

.direct-refresh:disabled,
.direct-reply-button:disabled,
.direct-queue-button:disabled,
.direct-filter:disabled,
.direct-sort:disabled,
.direct-batch-actions > button:disabled,
.direct-queue-menu button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  box-shadow: none;
}

/* Status Banner */
.direct-status {
  min-height: 18px;
  margin: 10px 0 14px;
  color: var(--apple-text-secondary);
  font-size: 12.5px;
  line-height: 1.45;
  letter-spacing: -0.01em;
  font-weight: 450;
}

.direct-status[data-state="error"] {
  color: var(--apple-red);
  font-weight: 500;
}

.direct-status[data-state="success"] {
  color: #248a3d;
}

/* Modern Conversations Grid */
.direct-conversations {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 470px), 1fr));
  align-items: start;
  gap: 12px;
  width: 100%;
}

/* Pagination */
.direct-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 16px 0 22px;
}

.direct-pagination[hidden] {
  display: none;
}

.direct-page-button {
  min-height: 32px;
  height: 32px;
  border: 1px solid var(--apple-card-border);
  border-radius: 9999px;
  background: var(--apple-card-bg);
  color: var(--apple-text-primary);
  padding: 0 13px;
  font-family: var(--apple-font);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: -0.01em;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  transition: all 0.16s var(--apple-ease);
  user-select: none;
}

.direct-page-button:hover:not(:disabled) {
  border-color: var(--apple-card-border-hover);
  background: var(--apple-subtle-bg);
}

.direct-page-button:active:not(:disabled) {
  transform: scale(0.97);
}

.direct-page-button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
  box-shadow: none;
}

.direct-page-summary {
  color: var(--apple-text-secondary);
  font-size: 11.5px;
  font-weight: 450;
  letter-spacing: -0.01em;
  text-align: center;
}

/* Apple Conversation Card (Zero-lag & Containment) */
.direct-conversation-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--apple-card-border);
  border-radius: 16px;
  background: var(--apple-card-bg);
  box-shadow: var(--apple-card-shadow);
  transition: transform 0.18s var(--apple-ease),
              box-shadow 0.18s var(--apple-ease),
              border-color 0.18s var(--apple-ease);
  contain: content;
}

.direct-conversation-card:hover {
  border-color: var(--apple-card-border-hover);
  box-shadow: var(--apple-card-hover-shadow);
  transform: translateY(-1px);
}

/* Conversation Header */
.direct-conversation-head {
  width: 100%;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 11px;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease;
  user-select: none;
}

.direct-conversation-head:hover {
  background: rgba(0, 0, 0, 0.018);
}

.direct-conversation-head:active {
  background: rgba(0, 0, 0, 0.035);
}

.direct-person-avatar {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #f4ebff 0%, #ebe0ff 100%);
  color: var(--apple-accent);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: -0.01em;
  box-shadow: inset 0 0 0 1px rgba(127, 53, 189, 0.12);
}

.direct-person-copy {
  min-width: 0;
  flex: 1;
}

.direct-person-name {
  display: block;
  overflow: hidden;
  color: var(--apple-text-primary);
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.direct-preview {
  display: block;
  overflow: hidden;
  margin-top: 2px;
  color: var(--apple-text-secondary);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: -0.01em;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.direct-conversation-time,
.direct-message-time {
  flex: 0 0 auto;
  color: var(--apple-text-tertiary);
  font-size: 11px;
  font-weight: 450;
  letter-spacing: -0.01em;
}

/* Expanded Conversation Content */
.direct-conversation-content {
  border-top: 1px solid rgba(0, 0, 0, 0.05);
  padding: 12px 14px 14px;
  background: #fafafc;
}

/* Thread & Messages (iOS iMessage Style) */
.direct-thread {
  max-height: 320px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  padding: 2px 2px 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.14) transparent;
}

.direct-thread::-webkit-scrollbar {
  width: 5px;
}

.direct-thread::-webkit-scrollbar-track {
  background: transparent;
}

.direct-thread::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.14);
  border-radius: 9999px;
}

.direct-thread::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}

.direct-message {
  max-width: 82%;
  border-radius: 15px 15px 15px 4px;
  background: #f2f2f7;
  padding: 8px 12px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

.direct-message[data-direction="outgoing"] {
  align-self: flex-end;
  border-radius: 15px 15px 4px 15px;
  background: linear-gradient(135deg, #7f35bd 0%, #6d28a7 100%);
  color: #ffffff;
}

.direct-message-text {
  color: var(--apple-text-primary);
  font-size: 12.5px;
  line-height: 1.45;
  letter-spacing: -0.01em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.direct-message[data-direction="outgoing"] .direct-message-text {
  color: #ffffff;
}

.direct-message-meta {
  justify-content: space-between;
  gap: 12px;
  margin-top: 4px;
  font-size: 10.5px;
  color: var(--apple-text-tertiary);
}

.direct-message[data-direction="outgoing"] .direct-message-meta {
  color: rgba(255, 255, 255, 0.72);
}

.direct-message[data-direction="outgoing"] .direct-message-time {
  color: rgba(255, 255, 255, 0.72);
}

/* 24h Window Badge */
.direct-reply-window {
  margin: 6px 0 10px;
  border-radius: 8px;
  background: var(--apple-green-light);
  color: #1b7a3a;
  border: 1px solid rgba(52, 199, 89, 0.2);
  padding: 7px 10px;
  font-size: 11.5px;
  line-height: 1.4;
  letter-spacing: -0.01em;
}

.direct-reply-window[data-state="blocked"] {
  background: var(--apple-amber-light);
  color: #9a5b00;
  border: 1px solid rgba(255, 149, 0, 0.2);
}

/* Quick Reply Form */
.direct-reply-form {
  display: grid;
  gap: 8px;
}

.direct-quick-reply-form {
  padding: 0 12px 12px;
}

.direct-quick-reply-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 6px;
}

.direct-quick-input {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  height: 34px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 9999px;
  outline: none;
  padding: 0 12px;
  background: var(--apple-subtle-bg);
  color: var(--apple-text-primary);
  font-family: var(--apple-font);
  font-size: 12px;
  letter-spacing: -0.01em;
  transition: all 0.16s var(--apple-ease);
}

.direct-quick-input::placeholder {
  color: var(--apple-text-tertiary);
}

.direct-quick-input:focus {
  background: #ffffff;
  border-color: var(--apple-accent);
  box-shadow: 0 0 0 3px var(--apple-accent-light);
}

.direct-quick-queue,
.direct-quick-send {
  box-sizing: border-box;
  min-height: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9999px;
  padding: 0 11px;
  font-family: var(--apple-font);
  font-size: 11.5px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.16s var(--apple-ease);
  user-select: none;
}

.direct-quick-queue {
  border: 1px solid var(--apple-accent-border);
  background: var(--apple-accent-light);
  color: var(--apple-accent);
  font-weight: 550;
}

.direct-quick-queue:hover:not(:disabled) {
  background: rgba(127, 53, 189, 0.14);
}

.direct-quick-send {
  border: 0;
  background: var(--apple-accent);
  color: #ffffff;
  font-weight: 600;
  padding: 0 12px;
  box-shadow: 0 1px 3px rgba(127, 53, 189, 0.25);
}

.direct-quick-send:hover:not(:disabled) {
  background: var(--apple-accent-hover);
  box-shadow: 0 2px 6px rgba(127, 53, 189, 0.35);
}

.direct-quick-queue:active:not(:disabled),
.direct-quick-send:active:not(:disabled) {
  transform: scale(0.97);
}

.direct-quick-queue:disabled,
.direct-quick-send:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  box-shadow: none;
}

.direct-reply-feedback {
  min-height: 15px;
  margin-top: 2px;
  color: var(--apple-text-secondary);
  font-size: 11px;
  line-height: 1.35;
  letter-spacing: -0.01em;
}

/* Empty State */
.direct-empty {
  grid-column: 1 / -1;
  border: 1px dashed rgba(0, 0, 0, 0.1);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--apple-text-secondary);
  font-size: 13px;
  font-weight: 450;
  letter-spacing: -0.01em;
  padding: 38px 20px;
  text-align: center;
  line-height: 1.5;
}

/* Floating Batch Bar (Apple Frosted Glass) */
.direct-batch-bar {
  position: relative;
  z-index: 40;
  box-sizing: border-box;
  width: min(1040px, calc(100% - 36px));
  min-height: 52px;
  margin: 10px auto;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.07), 0 1px 3px rgba(0, 0, 0, 0.02);
  padding: 8px 14px 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-family: var(--apple-font);
}

#directBatchBar[hidden] {
  display: none;
}

#directBatchBar:not([hidden]) {
  display: flex !important;
}

.direct-batch-summary {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.direct-batch-summary strong {
  color: var(--apple-text-primary);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.3;
}

.direct-batch-summary span {
  color: var(--apple-text-secondary);
  font-size: 11.5px;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.direct-batch-summary small {
  color: var(--apple-text-tertiary);
  font-size: 10.5px;
  font-weight: 450;
  letter-spacing: -0.01em;
}

.direct-batch-actions {
  position: relative;
}

.direct-batch-actions > button {
  min-height: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: 9999px;
  background: var(--apple-accent);
  color: #ffffff;
  padding: 0 14px;
  font-family: var(--apple-font);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(127, 53, 189, 0.28);
  transition: all 0.16s var(--apple-ease);
  user-select: none;
}

.direct-batch-actions > button:hover:not(:disabled) {
  background: var(--apple-accent-hover);
  box-shadow: 0 3px 8px rgba(127, 53, 189, 0.35);
}

.direct-batch-actions > button:active:not(:disabled) {
  transform: scale(0.97);
}

/* Apple Frosted Popup Menu */
.direct-queue-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  top: auto;
  width: 224px;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.04);
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.direct-queue-menu[hidden] {
  display: none;
}

.direct-queue-menu button {
  width: 100%;
  min-height: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--apple-text-primary);
  padding: 0 10px;
  font-family: var(--apple-font);
  font-size: 12px;
  font-weight: 450;
  letter-spacing: -0.01em;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease;
  user-select: none;
}

.direct-queue-menu button:hover:not(:disabled) {
  background: rgba(0, 0, 0, 0.05);
}

.direct-queue-menu button.direct-load-more[hidden] {
  display: none;
}

.direct-queue-menu button.direct-load-more:disabled {
  cursor: wait;
  opacity: 0.55;
}

/* Mobile & Compact Responsiveness */
@media (max-width: 760px) {
  .direct-container {
    width: min(100% - 24px, 600px);
    padding: 16px 0 96px;
  }

  .direct-header h2 {
    font-size: 19px;
  }

  .direct-header-actions {
    gap: 6px;
  }

  .direct-conversations {
    grid-template-columns: minmax(0, 1fr);
  }

  .direct-pagination {
    flex-wrap: wrap;
    gap: 8px;
  }

  #directBatchBar {
    width: calc(100% - 20px) !important;
    gap: 10px;
    padding: 8px 12px;
    min-height: 48px;
  }

  .direct-quick-reply-form {
    padding: 0 10px 10px;
  }

  .direct-quick-reply-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .direct-quick-send {
    grid-column: 2;
  }

  .direct-batch-summary span {
    max-width: 190px;
    line-height: 1.3;
  }

  .direct-batch-actions > button {
    min-height: 34px;
    height: 34px;
    gap: 6px;
    padding: 0 10px;
    font-size: 11.5px;
  }
}

/* Accessibility / Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .direct-refresh,
  .direct-sort,
  .direct-filter,
  .direct-reply-button,
  .direct-queue-button,
  .direct-conversation-card,
  .direct-quick-queue,
  .direct-quick-send,
  .direct-page-button,
  .direct-batch-actions > button {
    transition: none !important;
  }
}
