/* CSS Variables for Light Mode (Default) */
:root {
  /* Background Colors */
  --bg-primary: #f5f5f5;
  --bg-secondary: #ffffff;
  --bg-header: #2c3e50;
  --bg-ticket-hover: #f8f9fa;
  --bg-ticket-active: #e3f2fd;
  --bg-messages: #fafafa;
  --bg-message-user: #007bff;
  --bg-message-agent: #e9ecef;
  --bg-button-primary: #007bff;
  --bg-button-primary-hover: #0056b3;
  --bg-button-success: #28a745;
  --bg-button-success-hover: #1e7e34;
  --bg-button-danger: #dc3545;
  --bg-button-danger-hover: #c82333;
  --bg-button-secondary: #6c757d;
  --bg-unread-badge: #e74c3c;
  --bg-status-open: #d4edda;
  --bg-status-closed: #f8d7da;
  --bg-login: #ffffff;
  --bg-alert: #e7f3ff;
  --bg-alert-error: #f8d7da;
  --bg-modal-overlay: rgba(0, 0, 0, 0.5);
  --bg-modal-content: #ffffff;
  
  /* Text Colors */
  --text-primary: #333333;
  --text-secondary: #666666;
  --text-header: #ffffff;
  --text-button: #ffffff;
  --text-meta: #666666;
  --text-message-user: #ffffff;
  --text-message-agent: #333333;
  --text-message-sender-user: #b3d7ff;
  --text-status-open: #155724;
  --text-status-closed: #721c24;
  --text-alert: #004085;
  --text-alert-error: #721c24;
  --text-empty-state: #666666;
  --text-link: #007bff;
  
  /* Border Colors */
  --border-light: #e0e0e0;
  --border-medium: #ddd;
  --border-alert-error: #f5c6cb;
  --border-ticket-active: #2196f3;
  --border-input: #ddd;
  --border-modal: #e0e0e0;
  
  /* Shadow Colors */
  --shadow-light: rgba(0, 0, 0, 0.1);
  --shadow-medium: rgba(0, 0, 0, 0.3);
  
  /* Icon Colors */
  --icon-default: #666666;
  --icon-header: #ffffff;
  
  /* Misc */
  --scrollbar-track: #f5f5f5;
  --scrollbar-thumb: #888;
  --scrollbar-thumb-hover: #555;
}

/* Dark Mode Variables */
.darkmode {
  /* Background Colors */
  --bg-primary: #0f1419;
  --bg-secondary: #1e2932;
  --bg-header: #1a2634;
  --bg-ticket-hover: #2a3745;
  --bg-ticket-active: #2a3745;
  --bg-messages: #1a2634;
  --bg-message-user: #007bff;
  --bg-message-agent: #2a3745;
  --bg-button-primary: #007bff;
  --bg-button-primary-hover: #0056b3;
  --bg-button-success: #28a745;
  --bg-button-success-hover: #1e7e34;
  --bg-button-danger: #dc3545;
  --bg-button-danger-hover: #c82333;
  --bg-button-secondary: #6c757d;
  --bg-unread-badge: #e74c3c;
  --bg-status-open: #1a472a;
  --bg-status-closed: #4a1a1a;
  --bg-login: #1e2932;
  --bg-alert: #1a2634;
  --bg-alert-error: #4a1a1a;
  --bg-modal-overlay: rgba(0, 0, 0, 0.7);
  --bg-modal-content: #1e2932;
  
  /* Text Colors */
  --text-primary: #e6e6e6;
  --text-secondary: #a0aec0;
  --text-header: #ffffff;
  --text-button: #ffffff;
  --text-meta: #a0aec0;
  --text-message-user: #ffffff;
  --text-message-agent: #e6e6e6;
  --text-message-sender-user: #b3d7ff;
  --text-status-open: #a3d9b1;
  --text-status-closed: #f5a9a9;
  --text-alert: #a3d8ff;
  --text-alert-error: #f5a9a9;
  --text-empty-state: #a0aec0;
  --text-link: #64b5f6;
  
  /* Border Colors */
  --border-light: #2d3748;
  --border-medium: #4a5568;
  --border-alert-error: #742a2a;
  --border-ticket-active: #2196f3;
  --border-input: #4a5568;
  --border-modal: #2d3748;
  
  /* Shadow Colors */
  --shadow-light: rgba(0, 0, 0, 0.3);
  --shadow-medium: rgba(0, 0, 0, 0.5);
  
  /* Icon Colors */
  --icon-default: #a0aec0;
  --icon-header: #ffffff;
  
  /* Misc */
  --scrollbar-track: #1e2932;
  --scrollbar-thumb: #4a5568;
  --scrollbar-thumb-hover: #718096;
}

/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-size: 100% !important;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  min-height: 100vh;
}

/* Main Container */
.support-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  background: var(--bg-header);
  color: var(--text-header);
  padding: 12px 16px;
  border-radius: 8px 8px 0 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.header h1 {
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.user-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.logout-btn {
  background: var(--bg-button-danger);
  color: var(--text-button);
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  transition: background-color 0.2s ease;
}

.logout-btn:hover {
  background: var(--bg-button-danger-hover);
}

/* Main Content Layout */
.main-content {
  display: flex;
  flex: 1;
  background: var(--bg-secondary);
  border-radius: 0 0 8px 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px var(--shadow-light);
  min-height: 70vh;
  flex-direction: column;
}

/* Sidebar */
.sidebar {
  width: 100%;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  min-height: 250px;
  max-height: 400px;
  overflow: hidden;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-secondary);
}

.sidebar-header h2 {
  font-size: 1.125rem;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

/* Ticket List */
.ticket-list {
  flex: 1;
  overflow-y: auto;
  max-height: 300px;
}

.ticket-list::-webkit-scrollbar {
  width: 6px;
}

.ticket-list::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
  border-radius: 3px;
}

.ticket-list::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 3px;
}

.ticket-list::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

.ticket-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  display: block;
  text-decoration: none;
  color: inherit;
}

.ticket-item:hover {
  background: var(--bg-ticket-hover);
  transform: translateX(2px);
}

.ticket-item.active {
  background: var(--bg-ticket-active);
  border-left: 4px solid var(--border-ticket-active);
  padding-left: 20px;
}

.ticket-subject {
  font-weight: 600;
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.9375rem;
  line-height: 1.4;
}

.ticket-meta {
  font-size: 0.8125rem;
  color: var(--text-meta);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.unread-badge {
  background: var(--bg-unread-badge);
  color: var(--text-button);
  border-radius: 10px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  position: absolute;
  top: 12px;
  right: 16px;
  min-width: 20px;
  text-align: center;
  animation: pulse 2s infinite;
}

.ticket-status {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.status-open {
  background: var(--bg-status-open);
  color: var(--text-status-open);
}

.status-closed {
  background: var(--bg-status-closed);
  color: var(--text-status-closed);
}

/* Chat Area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 400px;
}

.chat-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-secondary);
  position: sticky;
  top: 0;
  z-index: 10;
}

.chat-header h3 {
  margin-bottom: 6px;
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.3;
}

.messages-container {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  background: var(--bg-messages);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.messages-container::-webkit-scrollbar {
  width: 6px;
}

.messages-container::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
  border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

/* Messages */
.message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: fadeIn 0.3s ease;
}

.message.user {
  align-self: flex-end;
}

.message.agent {
  align-self: flex-start;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  position: relative;
  word-wrap: break-word;
  line-height: 1.4;
  box-shadow: 0 1px 2px var(--shadow-light);
}

.message.user .message-bubble {
  background: var(--bg-message-user);
  color: var(--text-message-user);
  border-bottom-right-radius: 4px;
}

.message.agent .message-bubble {
  background: var(--bg-message-agent);
  color: var(--text-message-agent);
  border-bottom-left-radius: 4px;
}

.message-sender {
  font-weight: 600;
  font-size: 0.8125rem;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.message.user .message-sender {
  color: var(--text-message-sender-user);
}

.message-time {
  font-size: 0.75rem;
  opacity: 0.7;
  margin-top: 4px;
  text-align: right;
}

.message-text {
  white-space: pre-wrap;
  word-break: break-word;
}

/* Message Input */
.message-input-container {
  padding: 16px;
  border-top: 1px solid var(--border-light);
  background: var(--bg-secondary);
  position: sticky;
  bottom: 0;
}

.message-input-form {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.message-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border-input);
  border-radius: 20px;
  resize: none;
  font-family: inherit;
  font-size: 0.9375rem;
  line-height: 1.4;
  background: var(--bg-secondary);
  color: var(--text-primary);
  min-height: 44px;
  max-height: 120px;
  transition: border-color 0.2s ease;
}

.message-input:focus {
  outline: none;
  border-color: var(--bg-button-primary);
  box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

.send-button {
  background: var(--bg-button-primary);
  color: var(--text-button);
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.send-button:hover {
  background: var(--bg-button-primary-hover);
  transform: translateY(-1px);
}

.send-button:active {
  transform: translateY(0);
}

/* Empty States */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 32px;
  text-align: center;
  color: var(--text-empty-state);
}

.empty-state i {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.3;
}

.empty-state p {
  font-size: 1rem;
  margin-bottom: 8px;
  line-height: 1.4;
}

.empty-state p:last-child {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* Buttons */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9375rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--bg-button-primary);
  color: var(--text-button);
}

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

.btn-success {
  background: var(--bg-button-success);
  color: var(--text-button);
}

.btn-success:hover {
  background: var(--bg-button-success-hover);
}

.btn-danger {
  background: var(--bg-button-danger);
  color: var(--text-button);
}

.btn-danger:hover {
  background: var(--bg-button-danger-hover);
}

.btn-secondary {
  background: var(--bg-button-secondary);
  color: var(--text-button);
}

/* Ticket Actions */
.ticket-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

/* Login Container */
.login-container {
  max-width: 400px;
  margin: 40px auto;
  padding: 32px;
  background: var(--bg-login);
  border-radius: 8px;
  box-shadow: 0 4px 20px var(--shadow-light);
  text-align: center;
}

.login-container h2 {
  text-align: center;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 1.5rem;
}

.alert {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 20px;
  font-size: 0.9375rem;
  line-height: 1.4;
}

.alert-error {
  background: var(--bg-alert-error);
  color: var(--text-alert-error);
  border: 1px solid var(--border-alert-error);
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-modal-overlay);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-content {
  background: var(--bg-modal-content);
  border-radius: 12px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 30px var(--shadow-medium);
  animation: modalSlideIn 0.3s ease;
}

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

.modal-header h3 {
  font-size: 1.25rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 20px;
  border-top: 1px solid var(--border-modal);
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* Forms */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--text-primary);
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-input);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.9375rem;
  background: var(--bg-secondary);
  color: var(--text-primary);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-control:focus {
  outline: none;
  border-color: var(--bg-button-primary);
  box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

textarea.form-control {
  min-height: 120px;
  resize: vertical;
  line-height: 1.5;
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Responsive Design */
@media (min-width: 768px) {
  .support-container {
    padding: 20px;
  }
  
  .header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
  }
  
  .header h1 {
    font-size: 1.5rem;
  }
  
  .main-content {
    flex-direction: row;
    min-height: calc(100vh - 160px);
  }
  
  .sidebar {
    width: 320px;
    border-right: 1px solid var(--border-light);
    border-bottom: none;
    max-height: none;
  }
  
  .ticket-list {
    max-height: none;
  }
  
  .chat-area {
    flex: 1;
  }
  
  .message {
    max-width: 70%;
  }
  
  .logout-btn {
    padding: 8px 16px;
    font-size: 0.9375rem;
  }
}

@media (min-width: 1024px) {
  .support-container {
    max-width: 1200px;
  }
  
  .sidebar {
    width: 350px;
  }
  
  .header h1 {
    font-size: 1.75rem;
  }
}

@media (max-width: 767px) {
  .header {
    border-radius: 8px;
    margin-bottom: 12px;
  }
  
  .main-content {
    border-radius: 8px;
  }
  
  .chat-header {
    padding: 12px;
  }
  
  .chat-header h3 {
    font-size: 1rem;
  }
  
  .ticket-actions {
    flex-direction: column;
  }
  
  .ticket-actions .btn {
    width: 100%;
  }
  
  .modal-content {
    max-height: 80vh;
  }
  
  .modal-footer {
    flex-direction: column;
  }
  
  .modal-footer .btn {
    width: 100%;
  }
  
  .messages-container {
    padding: 12px;
  }
  
  .message {
    max-width: 90%;
  }
  
  .message-bubble {
    padding: 8px 12px;
  }
  
  .empty-state {
    padding: 24px;
  }
  
  .empty-state i {
    font-size: 2.5rem;
  }
}

/* Touch-friendly enhancements */
@media (hover: none) and (pointer: coarse) {
  .btn, .ticket-item, .send-button {
    min-height: 44px;
  }
  
  .message-input {
    font-size: 16px; /* Prevent iOS zoom on focus */
  }
  
  .form-control {
    font-size: 16px; /* Prevent iOS zoom on focus */
  }
}

/* Print Styles */
@media print {
  .header, .message-input-container, .ticket-actions, .logout-btn, .btn {
    display: none !important;
  }
  
  .main-content {
    box-shadow: none;
    border: 1px solid #ccc;
  }
  
  body {
    background: white;
    color: black;
  }
  
  .message-bubble {
    box-shadow: none;
    border: 1px solid #ccc;
  }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus visible for keyboard navigation */
:focus-visible {
  outline: 2px solid var(--bg-button-primary);
  outline-offset: 2px;
}

/* High contrast mode */
@media (prefers-contrast: high) {
  :root {
    --bg-primary: #000000;
    --bg-secondary: #000000;
    --text-primary: #ffffff;
    --border-light: #ffffff;
  }
}