/* Tickets — List, Detail, Conversation Thread, Reply & Attachments */

/* Ticket List Column Header */
.col-header {
  padding: 16px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--surface-border-subtle);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.col-title-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.col-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.search-input {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  padding: 8px 32px 8px 12px;
  color: var(--text);
  font-size: 13px;
  width: 100%;
  outline: none;
  transition: all 0.15s;
}

.search-input::-webkit-search-cancel-button,
.search-input::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}

.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 102, 255, 0.12);
}

body.dark-theme .search-input {
  background: var(--field-bg);
  border-color: var(--surface-border);
  color: var(--text);
}

body.dark-theme .search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--focus-ring);
}

.search-clear-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  line-height: 1;
}

.search-clear-btn:hover {
  color: var(--text);
  background: var(--surface-hover, rgba(0, 0, 0, 0.06));
}

body.dark-theme .search-clear-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

#ticket-page {
  font-size: 14px;
  font-weight: 600;
  min-width: 96px;
  text-align: center;
  white-space: nowrap;
}

.ticket-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 14px;
  min-width: 0;
}

/* Ticket Cards */
.ticket-card {
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.ticket-card:hover {
  border-color: #94A3B8;
  background: var(--surface-hover);
}

.ticket-card.selected {
  border-color: #bdccdc;
  background: #f8fafc;
  box-shadow: inset 3px 0 0 #a8bfd9;
}

body.dark-theme .ticket-card {
  background: var(--surface);
  border-color: var(--surface-border);
}

body.dark-theme .ticket-card:hover {
  border-color: var(--text-subtle);
  background: var(--surface-hover);
}

body.dark-theme .ticket-card.selected {
  background: var(--surface-active);
  border-color: var(--primary);
  box-shadow: inset 2px 0 0 var(--primary);
}

.card-meta-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-muted);
  gap: 8px;
  min-width: 0;
}

.card-sender-email {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-meta-top > span:last-child {
  flex-shrink: 0;
}

.card-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ticket-card:hover .card-title {
  color: var(--primary);
}

.card-preview {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-badges {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

/* Detail Empty State */
.detail-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 12px;
  background: var(--surface);
}

/* Detail Topbar */
.detail-topbar {
  padding: 16px 28px 12px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--surface-border-subtle);
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.detail-breadcrumbs {
  font-size: 12.5px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
}

.bc-sep {
  color: var(--text-muted);
  flex-shrink: 0;
}

.bc-active {
  color: var(--primary);
  font-weight: 500;
  max-width: 500px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.detail-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 16px;
  min-width: 0;
}

.detail-subject {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  margin: 0;
}

.detail-workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
  background: var(--bg);
  min-height: 0;
  container-type: inline-size;
}

.detail-main-flow {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 20px 24px;
  gap: 16px;
  min-height: 0;
  min-width: 360px;
}

.flow-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
  min-height: 0;
}

.flow-card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--surface-border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  flex-shrink: 0;
}

.flow-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

/* Detail Sidebar: Right Actions & Meta */
.detail-sidebar-card {
  width: 290px;
  flex-shrink: 0;
  margin: 20px 24px 20px 0;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 14px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
  height: fit-content;
  max-height: calc(100% - 40px);
  overflow-y: auto;
}

.action-buttons-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Responsive workspace stacking when detail pane is under 760px */
@container (max-width: 760px) {
  .detail-workspace {
    flex-direction: column;
    overflow-y: auto;
  }

  .detail-main-flow {
    flex: none;
    width: 100%;
    min-width: 0;
    padding: 16px;
    overflow: visible;
  }

  .flow-card {
    flex: none;
    height: auto;
    overflow: visible;
  }

  .thread-scroll {
    flex: none;
    height: auto;
    overflow: visible;
    background: transparent;
  }

  .detail-sidebar-card {
    width: 100%;
    margin: 0 0 20px 0;
    padding: 16px;
    max-height: none;
    flex-shrink: 0;
  }

  .detail-sidebar-card .action-buttons-group {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }

  .detail-sidebar-card .action-buttons-group .btn {
    flex: 1;
    min-width: 120px;
  }

  .detail-sidebar-card .sidebar-meta-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
  }
}

.reply-auth-alert {
  padding: 10px 14px;
  background: var(--warning-subtle);
  border: 1px solid rgba(245, 159, 0, 0.3);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
  color: var(--text);
  margin-bottom: 8px;
}

body.dark-theme .reply-auth-alert {
  background: rgba(210, 153, 34, 0.15);
  border-color: rgba(210, 153, 34, 0.35);
  color: var(--text);
}

.sidebar-meta-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.meta-item {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.meta-label {
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.meta-value {
  font-size: 13.5px;
  color: var(--text);
  font-weight: 600;
  word-break: break-word;
}

.meta-divider {
  height: 1px;
  background: var(--surface-border-subtle);
  margin: 4px 0;
}

.meta-select {
  width: 100%;
}

/* Conversation Thread */
.thread-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--bg);
  min-width: 0;
  min-height: 0;
}

.msg-card {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 12px;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
  max-width: 100%;
  min-width: 0;
  min-height: fit-content;
  flex-shrink: 0;
  box-sizing: border-box;
}

.msg-card.msg-employee {
  background: #F0F7FF;
  border: 1px solid #D0EBFF;
  border-left: 4px solid var(--primary);
}

.msg-card.msg-initial {
  border-left: 4px solid var(--aitu-cyan);
}

body.dark-theme .msg-card {
  background: var(--surface);
  border-color: var(--surface-border);
}

body.dark-theme .msg-card.msg-employee {
  background: var(--control-bg);
  border-color: var(--surface-border);
  border-left: 4px solid var(--primary);
}

.msg-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 12px;
  font-size: 13px;
  min-width: 0;
}

.msg-author {
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  min-width: 0;
  max-width: 100%;
}

.msg-author-email {
  word-break: break-all;
  max-width: 100%;
}

.msg-badge {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 6px;
  font-weight: 700;
  flex-shrink: 0;
}

.msg-badge-cust {
  background: var(--surface-hover);
  color: var(--text-secondary);
}

.msg-badge-emp {
  background: var(--primary-subtle);
  color: var(--primary);
}

.msg-time {
  font-size: 12px;
  color: var(--text-muted);
}

.msg-body {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.msg-body a,
.msg-link {
  color: var(--primary);
  text-decoration: underline;
  word-break: break-all;
  overflow-wrap: anywhere;
}

.msg-body a:hover,
.msg-link:hover {
  color: var(--primary-hover);
}

/* Reply Composer */
.reply-box {
  padding: 16px 24px;
  background: var(--surface);
  border-top: 1px solid var(--surface-border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

body.dark-theme .reply-box {
  background: var(--surface);
  border-top-color: var(--surface-border-subtle);
}

.reply-sender-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--surface-border-subtle);
  border-radius: 8px;
}

body.dark-theme .reply-sender-bar {
  background: var(--field-bg);
  border-color: var(--surface-border);
}

.reply-textarea {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  min-height: 80px;
  outline: none;
  transition: border 0.15s;
}

.reply-textarea:focus {
  border-color: var(--aitu-cyan);
  box-shadow: 0 0 0 3px rgba(42, 173, 225, 0.15);
}

body.dark-theme .reply-textarea {
  background: var(--field-bg);
  border-color: var(--surface-border);
  color: var(--text);
}

body.dark-theme .reply-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.reply-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.reply-files-preview {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0;
}

.reply-from-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.reply-mailbox-select {
  padding: 5px 10px;
  font-size: 12.5px;
  border-radius: 6px;
  min-width: 250px;
  max-width: 400px;
  cursor: pointer;
}

.reply-footer-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.reply-files-count {
  font-size: 12px;
  color: var(--text-muted);
}

.reply-file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-hover);
  border: 1px solid var(--surface-border);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.reply-file-chip .remove-file-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  color: #EF4444;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px;
  border-radius: 4px;
  margin-left: 6px;
  transition: all 0.15s ease;
}

.reply-file-chip .remove-file-btn:hover {
  background: rgba(239, 68, 68, 0.14);
  color: #DC2626;
  transform: scale(1.08);
}

/* Attachments Panel */
.attachments-panel {
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--surface-border-subtle);
  display: none;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
  max-height: 160px;
  overflow-y: auto;
}

.attachments-count {
  color: var(--text-muted);
  font-weight: normal;
}

.attachments-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.attachments-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attachment-card {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text);
  transition: all 0.2s;
}

.attachment-card:hover {
  border-color: var(--primary);
  background: var(--surface);
}

.attachment-name {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.attachment-size {
  font-size: 11px;
  color: var(--text-muted);
}

.attachment-download-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: var(--primary-fill);
  color: #ffffff;
  border-radius: 4px;
  text-decoration: none;
  font-size: 11px;
  font-weight: 500;
}

.attachment-download-btn:hover {
  background: var(--primary-fill-hover);
}

.attachment-purged-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  background: var(--warning-subtle);
  color: var(--warning);
  border: 1px solid rgba(245, 159, 0, 0.3);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}

/* Image Thumbnails & Lightbox */
.attachment-image-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  transition: all 0.2s;
  cursor: pointer;
}

.attachment-image-card:hover {
  border-color: var(--aitu-cyan);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.attachment-thumb {
  width: 50px;
  height: 50px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--bg);
}

.attachment-image-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-right: 6px;
}

.lightbox-container {
  display: flex;
  flex-direction: column;
  max-width: 90vw;
  max-height: 88vh;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.lightbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background: var(--bg);
  border-bottom: 1px solid var(--surface-border);
}

.lightbox-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  max-width: 60vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lightbox-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: #111;
  overflow: auto;
}

.lightbox-image {
  max-width: 85vw;
  max-height: 75vh;
  object-fit: contain;
  border-radius: 6px;
}

#modal-lightbox {
  background: rgba(0, 0, 0, 0.88);
  z-index: 9999;
}

.lightbox-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.lightbox-close-btn {
  padding: 4px 10px;
}
