/* Bridge Helpdesk - Main Stylesheet */

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --secondary: #64748b;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --light: #f8fafc;
  --dark: #1e293b;
  --border: #e2e8f0;
  --text: #334155;
  --text-light: #64748b;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background-color: var(--light);
  color: var(--text);
  line-height: 1.6;
}

/* Navigation */
.navbar {
  background: var(--dark);
  color: white;
  padding: 0 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand a {
  color: white;
  text-decoration: none;
  font-size: 1.25rem;
  font-weight: 600;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.nav-links a {
  color: #94a3b8;
  text-decoration: none;
  padding: 0.5rem 0;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.nav-links a:hover,
.nav-links a.active {
  color: white;
  border-bottom-color: var(--primary);
}

.nav-admin {
  background: var(--primary);
  padding: 0.5rem 1rem !important;
  border-radius: 4px;
  border-bottom: none !important;
}

.nav-admin:hover {
  background: var(--primary-dark);
}

.nav-user {
  color: #94a3b8;
  font-size: 0.875rem;
}

.nav-logout {
  color: #94a3b8;
  font-size: 0.875rem;
}

/* Container */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Alerts */
.alert {
  padding: 1rem 1.25rem;
  border-radius: 6px;
  margin-bottom: 1.5rem;
}

.alert-success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.alert-error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.alert-info {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

.alert-warning {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}

.alert-warning a {
  color: #92400e;
  font-weight: 500;
}

.unprocessed-alert {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Page Header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

.page-header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--light);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

/* Cards */
.card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  border: 1px solid var(--border);
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-body {
  padding: 1.25rem;
}

/* Filters */
.filters {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.filter-group label {
  font-size: 0.875rem;
  color: var(--text-light);
}

.filter-group select,
.filter-group input {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.875rem;
  background: white;
}

/* Ticket List */
.ticket-list {
  display: flex;
  flex-direction: column;
}

.ticket-row {
  display: grid;
  grid-template-columns: 140px 1fr 120px 100px 100px 140px;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  transition: background 0.2s;
}

.ticket-row:hover {
  background: var(--light);
}

.ticket-row:last-child {
  border-bottom: none;
}

.ticket-header {
  display: grid;
  grid-template-columns: 140px 1fr 120px 100px 100px 140px;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--light);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-light);
  border-bottom: 1px solid var(--border);
}

.ticket-number {
  font-family: monospace;
  font-size: 0.875rem;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Unread indicator */
.ticket-row.unread {
  background: #eff6ff;
  font-weight: 500;
}

.ticket-row.unread:hover {
  background: #dbeafe;
}

.unread-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  background: var(--primary);
  color: white;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.ticket-subject {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ticket-customer {
  font-size: 0.875rem;
  color: var(--text-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ticket-date {
  font-size: 0.875rem;
  color: var(--text-light);
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
}

.badge-open {
  background: #dbeafe;
  color: #1e40af;
}

.badge-pending {
  background: #fef3c7;
  color: #92400e;
}

.badge-resolved {
  background: #dcfce7;
  color: #166534;
}

.badge-closed {
  background: #f1f5f9;
  color: #475569;
}

.badge-low {
  background: #f1f5f9;
  color: #475569;
}

.badge-normal {
  background: #dbeafe;
  color: #1e40af;
}

.badge-high {
  background: #fef3c7;
  color: #92400e;
}

.badge-urgent {
  background: #fee2e2;
  color: #991b1b;
}

/* Ticket Detail */
.ticket-detail {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 1.5rem;
}

.ticket-main {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.ticket-sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.ticket-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.info-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-light);
  font-weight: 500;
}

.info-value {
  font-size: 0.9375rem;
}

/* Message Thread */
.message-thread {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.message {
  padding: 1rem 1.25rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.message-inbound {
  background: white;
  border-left: 4px solid var(--secondary);
}

.message-outbound {
  background: #eff6ff;
  border-left: 4px solid var(--primary);
}

.message-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.75rem;
}

.message-from {
  font-weight: 500;
}

.message-direction {
  font-size: 0.75rem;
  color: var(--text-light);
  margin-left: 0.5rem;
}

.message-date {
  font-size: 0.8125rem;
  color: var(--text-light);
}

.message-header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.message-action {
  font-size: 0.75rem;
  color: var(--text-light);
  text-decoration: none;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  transition: all 0.2s;
}

.message-action:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: #eff6ff;
}

.message-body {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.7;
}

.message-attachments {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
}

.attachments-header {
  font-weight: 500;
  color: var(--text-light);
  margin-bottom: 0.5rem;
}

.attachments-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.attachment-image {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-width: 400px;
}

.attachment-image img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: opacity 0.2s;
}

.attachment-image img:hover {
  opacity: 0.9;
}

.attachment-image .attachment-filename {
  font-size: 0.75rem;
  color: var(--text-light);
}

.attachment-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--light);
  border: 1px solid var(--border);
  border-radius: 4px;
  text-decoration: none;
  color: var(--text);
  transition: all 0.2s;
  max-width: fit-content;
}

.attachment-link:hover {
  background: white;
  border-color: var(--primary);
  color: var(--primary);
}

.attachment-icon {
  flex-shrink: 0;
}

.attachment-filename {
  word-break: break-all;
}

.attachment-size {
  color: var(--text-light);
  font-size: 0.8125rem;
  white-space: nowrap;
}

.attachment-blocked {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: #fee2e2;
  border: 1px solid #fecaca;
  border-radius: 4px;
  color: #991b1b;
  max-width: fit-content;
}

.attachment-warning {
  font-size: 0.8125rem;
  font-style: italic;
}

/* Reply Form */
.reply-form {
  margin-top: 1.5rem;
}

.reply-form textarea {
  width: 100%;
  min-height: 150px;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.9375rem;
  resize: vertical;
  margin-bottom: 1rem;
}

.reply-form textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.reply-actions {
  display: flex;
  gap: 0.75rem;
}

/* Status Actions */
.status-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.status-actions .btn {
  width: 100%;
  justify-content: center;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-light);
}

.empty-state h3 {
  margin-bottom: 0.5rem;
  color: var(--text);
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

.pagination a,
.pagination span {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  text-decoration: none;
  color: var(--text);
  font-size: 0.875rem;
}

.pagination a:hover {
  background: var(--light);
}

.pagination .active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Responsive */
@media (max-width: 1024px) {
  .ticket-detail {
    grid-template-columns: 1fr;
  }

  .ticket-sidebar {
    order: -1;
  }
}

@media (max-width: 768px) {
  .ticket-row,
  .ticket-header {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .ticket-header {
    display: none;
  }

  .filters {
    flex-direction: column;
  }
}

/* AI Draft Section */
.draft-section {
  margin-top: 1.5rem;
  padding: 1.25rem;
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
  border: 2px solid #0ea5e9;
  border-radius: 8px;
}

.draft-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.draft-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.75rem;
  background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
  color: white;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.draft-badge::before {
  content: "✨";
  margin-right: 0.25rem;
}

.draft-info {
  font-size: 0.8125rem;
  color: var(--text-light);
}

.draft-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.draft-textarea {
  width: 100%;
  min-height: 200px;
  padding: 1rem;
  border: 1px solid #0ea5e9;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.9375rem;
  line-height: 1.7;
  resize: vertical;
  background: white;
}

.draft-textarea:focus {
  outline: none;
  border-color: #0284c7;
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.2);
}

.draft-citations {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem;
  background: white;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.citations-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-light);
}

.citation-tag {
  display: inline-flex;
  padding: 0.25rem 0.5rem;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 4px;
  font-size: 0.75rem;
  color: #0369a1;
}

.draft-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* AI Generated Message indicator */
.message-ai {
  position: relative;
}

.message-ai::after {
  content: "AI";
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.125rem 0.375rem;
  background: #0ea5e9;
  color: white;
  border-radius: 4px;
  font-size: 0.625rem;
  font-weight: 600;
}

/* Markdown Editor */
.markdown-editor {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: white;
}

.md-toolbar {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem;
  background: var(--light);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.md-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 0.5rem;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 0.8125rem;
  font-family: inherit;
  transition: all 0.15s ease;
}

.md-btn:hover {
  background: white;
  border-color: var(--border);
}

.md-btn:active,
.md-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.md-separator {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 0.25rem;
}

.md-preview-toggle {
  margin-left: auto;
}

.md-content {
  position: relative;
  min-height: 200px;
}

.md-input {
  width: 100%;
  min-height: 200px;
  padding: 1rem;
  border: none;
  resize: vertical;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  background: white;
}

.md-input:focus {
  outline: none;
}

.md-preview {
  padding: 1rem;
  min-height: 200px;
  background: white;
  overflow-y: auto;
}

/* Markdown Preview Styles */
.md-preview h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0 0 1rem 0;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.md-preview h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 1.5rem 0 0.75rem 0;
}

.md-preview h3 {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 1.25rem 0 0.5rem 0;
}

.md-preview p {
  margin: 0 0 1rem 0;
}

.md-preview ul,
.md-preview ol {
  margin: 0 0 1rem 0;
  padding-left: 1.5rem;
}

.md-preview li {
  margin: 0.25rem 0;
}

.md-preview strong {
  font-weight: 600;
}

.md-preview em {
  font-style: italic;
}

.md-preview code {
  background: var(--light);
  padding: 0.125rem 0.375rem;
  border-radius: 4px;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  font-size: 0.875em;
}

.md-preview pre {
  background: var(--light);
  padding: 1rem;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0 0 1rem 0;
}

.md-preview pre code {
  background: none;
  padding: 0;
}

.md-preview a {
  color: var(--primary);
  text-decoration: none;
}

.md-preview a:hover {
  text-decoration: underline;
}

.md-preview blockquote {
  border-left: 3px solid var(--border);
  margin: 0 0 1rem 0;
  padding: 0.5rem 0 0.5rem 1rem;
  color: var(--text-light);
}

.md-preview hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

/* =====================
   Chat Panel Styles
   ===================== */

.chat-panel {
  display: flex;
  flex-direction: column;
  height: 500px;
  max-height: 60vh;
}

.chat-header {
  padding: 0.75rem 1rem 0.5rem;
  flex-shrink: 0;
}

.chat-header h3 {
  font-size: 1rem;
  margin: 0;
}

.chat-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0 1rem 0.75rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-selector {
  flex: 1;
  min-width: 0;
  padding: 0.375rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.8125rem;
  background: white;
}

.btn-sm {
  padding: 0.375rem 0.625rem;
  font-size: 0.75rem;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: var(--light);
}

.chat-message {
  max-width: 85%;
  padding: 0.625rem 0.875rem;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.5;
  word-wrap: break-word;
}

.chat-message-user {
  align-self: flex-end;
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-message-assistant {
  align-self: flex-start;
  background: white;
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-message-meta {
  font-size: 0.6875rem;
  opacity: 0.7;
  margin-top: 0.25rem;
}

.chat-message-user .chat-message-meta {
  text-align: right;
}

.chat-message-content {
  white-space: pre-wrap;
}

.chat-message-content p {
  margin: 0 0 0.5rem 0;
}

.chat-message-content p:last-child {
  margin-bottom: 0;
}

.chat-input-container {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  background: white;
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.875rem;
  font-family: inherit;
  resize: none;
  min-height: 38px;
  max-height: 100px;
}

.chat-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.chat-send-btn {
  padding: 0.5rem 1rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}

.chat-send-btn:hover:not(:disabled) {
  background: var(--primary-dark);
}

.chat-send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.chat-loading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 0.875rem;
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  font-size: 0.875rem;
  color: var(--text-light);
  align-self: flex-start;
}

.chat-loading-dots {
  display: flex;
  gap: 4px;
}

.chat-loading-dots span {
  width: 6px;
  height: 6px;
  background: var(--text-light);
  border-radius: 50%;
  animation: chatBounce 1.4s infinite ease-in-out both;
}

.chat-loading-dots span:nth-child(1) {
  animation-delay: -0.32s;
}

.chat-loading-dots span:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes chatBounce {
  0%, 80%, 100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1);
  }
}

.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-light);
  text-align: center;
  padding: 2rem;
}

.chat-empty p {
  margin: 0.5rem 0 0 0;
  font-size: 0.875rem;
}

.chat-error {
  padding: 0.75rem 1rem;
  background: #fee2e2;
  color: #991b1b;
  border-radius: 6px;
  font-size: 0.8125rem;
  margin: 0.5rem 1rem;
}

.chat-citations {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-light);
}

.chat-citations span {
  display: inline-block;
  background: var(--light);
  padding: 0.125rem 0.375rem;
  border-radius: 3px;
  margin-right: 0.25rem;
  margin-bottom: 0.25rem;
}

/* Streaming cursor animation */
.streaming-cursor {
  display: inline-block;
  width: 8px;
  height: 16px;
  background: var(--primary);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: cursorBlink 1s infinite;
}

@keyframes cursorBlink {
  0%, 50% {
    opacity: 1;
  }
  51%, 100% {
    opacity: 0;
  }
}

.chat-message.streaming .chat-message-content {
  white-space: pre-wrap;
}
