/**
 * SecureChat Styles
 * Modern, clean, and secure design
 */

:root {
  --primary-color: #4F46E5;
  --primary-dark: #4338CA;
  --primary-light: #6366F1;
  --success-color: #10B981;
  --error-color: #EF4444;
  --warning-color: #F59E0B;
  --bg-primary: #FFFFFF;
  --bg-secondary: #F9FAFB;
  --bg-tertiary: #F3F4F6;
  --text-primary: #111827;
  --text-secondary: #6B7280;
  --border-color: #E5E7EB;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: var(--bg-secondary);
  color: var(--text-primary);
}

#app {
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

/* Screens */
.screen {
  display: none;
  width: 100%;
  height: 100%;
}

.screen.active {
  display: flex;
}

/* Auth Screen */
#auth-screen {
  justify-content: center;
  align-items: center;
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
  padding: 20px;
  min-height: 100vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.auth-container {
  background: var(--bg-primary);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 40px;
  width: 100%;
  max-width: 450px;
  margin: auto;
  animation: slideIn 0.3s ease;
  /* Ensure it doesn't overflow on small screens */
  max-height: 95vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.logo {
  text-align: center;
  margin-bottom: 30px;
}

.logo svg {
  margin-bottom: 10px;
}

.logo h1 {
  font-size: clamp(24px, 5vw, 32px); /* Responsive font size */
  color: var(--text-primary);
  margin-bottom: 8px;
  word-wrap: break-word;
}

.tagline {
  font-size: clamp(12px, 3vw, 14px); /* Responsive font size */
  color: var(--text-secondary);
  word-wrap: break-word;
}

.auth-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border-color);
}

.tab {
  flex: 1;
  padding: 14px 12px; /* Larger touch target */
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  min-height: 44px; /* iOS touch target */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

.tab.active {
  color: var(--primary-color);
  border-bottom-color: var(--primary-color);
}

.tab:hover {
  color: var(--primary-color);
}

.tab:active {
  opacity: 0.7;
}

.auth-form {
  display: none;
}

.auth-form.active {
  display: block;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--text-primary);
}

.form-group input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 16px; /* Prevents zoom on iOS */
  transition: all 0.2s;
  -webkit-appearance: none; /* Remove iOS styling */
  -moz-appearance: none;
  appearance: none;
  background-color: var(--bg-primary);
  /* Prevent autocomplete background color changes */
  -webkit-box-shadow: 0 0 0 1000px var(--bg-primary) inset;
  box-shadow: 0 0 0 1000px var(--bg-primary) inset;
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
  -webkit-box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-group small {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.info-box {
  background: var(--bg-tertiary);
  border-left: 4px solid var(--primary-color);
  padding: 16px;
  border-radius: 8px;
  margin-bottom: 20px;
}

.info-box strong {
  display: block;
  margin-bottom: 8px;
  color: var(--primary-color);
}

.info-box p {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.btn {
  padding: 14px 24px; /* Larger touch target */
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-appearance: none; /* Remove iOS button styling */
  -moz-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent; /* Remove tap highlight */
  touch-action: manipulation; /* Prevents double-tap zoom */
 min-height: 44px; /* iOS touch target guideline */
}

.btn-primary {
  width: 100%;
  background: var(--primary-color);
  color: white;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-primary:active {
  transform: translateY(0);
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--border-color);
}

.btn-danger {
  background: #e74c3c;
  color: white;
}

.btn-danger:hover {
  background: #c0392b;
}
.message {
  margin-top: 20px;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
}

.message.info {
  background: #DBEAFE;
  color: #1E40AF;
}

.message.success {
  background: #D1FAE5;
  color: #065F46;
}

.message.error {
  background: #FEE2E2;
  color: #991B1B;
}

.message.hidden {
  display: none;
}

.hidden {
  display: none !important;
}

/* Chat Screen */
.chat-container {
  display: flex;
  width: 100%;
  height: 100%;
  background: var(--bg-primary);
}

/* Sidebar */
.sidebar {
  width: 350px;
  height: 100%;
  background: var(--bg-primary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.user-info {
  display: flex;
  gap: 12px;
  align-items: center;
}

.avatar {
  width: 40px;
  height: 40px;
  background: var(--bg-tertiary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.username {
  font-weight: 600;
  color: var(--text-primary);
}

.status {
  font-size: 12px;
  color: var(--success-color);
}

.btn-icon {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: var(--bg-tertiary);
}

.logout-btn {
  background: var(--bg-secondary);
  padding: 8px 16px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-primary);
  font-weight: 500;
}

.logout-btn:hover {
  background: #e74c3c;
  color: white;
  transform: translateY(-1px);
}

.search-bar {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.search-bar input {
  width: 100%;
  padding: 10px 16px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 14px;
}

.conversations-list {
  flex: 1;
  overflow-y: auto;
}

.conversation-item {
  display: flex;
  gap: 12px;
  padding: 16px 20px;
  cursor: pointer;
  transition: all 0.2s;
  border-bottom: 1px solid var(--border-color);
}

.conversation-item:hover {
  background: var(--bg-secondary);
}

.conversation-info {
  flex: 1;
  min-width: 0;
}

.conversation-info .username {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.last-message {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.timestamp {
  font-size: 12px;
  color: var(--text-secondary);
}

.empty-state, .search-results-header {
  padding: 20px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
}

.search-results-header {
  font-weight: 600;
  color: var(--text-primary);
  background: var(--bg-tertiary);
  text-align: left;
}

/* Chat Area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-primary);
}

.recipient-info {
  display: flex;
  gap: 12px;
  align-items: center;
}

.chat-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.encryption-badge {
  font-size: 12px;
  padding: 6px 12px;
  background: var(--success-color);
  color: white;
  border-radius: 20px;
  font-weight: 500;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--bg-secondary);
}

.welcome-message {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.welcome-message h2 {
  color: var(--text-primary);
  margin-bottom: 16px;
}

.welcome-message ul {
  list-style: none;
  margin-top: 20px;
}

.welcome-message li {
  margin: 8px 0;
}

.message {
  margin-bottom: 16px;
  display: flex;
  animation: messageSlide 0.3s ease;
}

@keyframes messageSlide {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message.sent {
  justify-content: flex-end;
}

.message.received {
  justify-content: flex-start;
}

.message-content {
  max-width: 60%;
  padding: 12px 16px;
  border-radius: 12px;
  word-wrap: break-word;
}

.message.sent .message-content {
  background: var(--primary-color);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.received .message-content {
  background: var(--bg-primary);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.message.error .message-content {
  background: var(--error-color);
  color: white;
  font-style: italic;
}

.message-meta {
  font-size: 11px;
  margin-top: 4px;
  color: var(--text-secondary);
  display: flex;
  gap: 6px;
  align-items: center;
}

.message.sent .message-meta {
  justify-content: flex-end;
}

.delivery-status {
  color: var(--success-color);
}

.message.read .delivery-status::after {
  content: '✓';
}

.message-input-container {
  display: flex;
  padding: 20px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-primary);
  flex-direction: column;
  gap: 10px;
}

#message-form {
  display: flex;
  gap: 12px;
}

#message-input {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 14px;
}

#message-input:focus {
  outline: none;
  border-color: var(--primary-color);
}

.btn-send {
  padding: 12px 24px;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-send:hover {
  background: var(--primary-dark);
}

.typing-indicator {
  display: none;
  font-size: 12px;
  color: var(--text-secondary);
  font-style: italic;
}

.typing-indicator.active {
  display: block;
}

.key-fingerprint {
  word-break: break-all;
  font-size: 12px;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--bg-primary);
  border-radius: 16px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalSlide 0.3s ease;
}

@keyframes modalSlide {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.modal-header {
  padding: 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 24px;
}

.btn-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s;
}

.btn-close:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.modal-body {
  padding: 24px;
}

.settings-section {
  margin-bottom: 24px;
}

.settings-section h3 {
  margin-bottom: 16px;
  font-size: 18px;
}

.twofa-panel {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-secondary);
}

.twofa-qr {
  width: 200px;
  height: 200px;
  display: block;
  margin: 12px 0;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: #fff;
}

.twofa-recovery-title {
  margin-top: 12px;
  margin-bottom: 8px;
  font-weight: 600;
}

.twofa-recovery-codes {
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: #fff;
  font-size: 12px;
  line-height: 1.5;
  max-height: 160px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin-bottom: 10px;
}

.modal-footer {
  padding: 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    position: absolute;
    z-index: 100;
  }

  .chat-area {
    width: 100%;
  }

  .message-content {
    max-width: 80%;
  }

  .auth-container {
    padding: 30px 20px;
  }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* ========================================
   RESPONSIVE DESIGN - ALL BROWSERS & OS
   ======================================== */

/* Mobile devices (phones) - Portrait */
@media (max-width: 480px) {
  .auth-container {
    padding: 24px 20px;
    border-radius: 12px;
    margin: 10px;
  }

  .logo h1 {
    font-size: 22px;
  }

  .logo svg {
    width: 100px;
    height: 85px;
  }

  .tagline {
    font-size: 11px;
    line-height: 1.4;
  }

  .form-group {
    margin-bottom: 16px;
  }

  .form-group label {
    font-size: 14px;
  }

  .form-group input {
    padding: 12px 14px;
    font-size: 16px; /* Prevent zoom on iOS */
  }

  .form-group small {
    font-size: 11px;
  }

  .info-box {
    padding: 12px;
  }

  .info-box strong {
    font-size: 13px;
  }

  .info-box p {
    font-size: 12px;
  }

  .btn {
    padding: 14px 20px;
    font-size: 15px;
  }

  .tab {
    font-size: 14px;
    padding: 12px 8px;
  }
}

/* Mobile devices - Landscape */
@media (max-height: 500px) and (orientation: landscape) {
  #auth-screen {
    padding: 10px;
  }

  .auth-container {
    padding: 20px;
    max-height: 90vh;
  }

  .logo {
    margin-bottom: 15px;
  }

  .logo svg {
    width: 80px;
    height: 70px;
  }

  .logo h1 {
    font-size: 20px;
    margin-bottom: 4px;
  }

  .tagline {
    font-size: 11px;
  }

  .form-group {
    margin-bottom: 12px;
  }

  .info-box {
    padding: 10px;
  }
}

/* Tablets - Portrait */
@media (min-width: 481px) and (max-width: 768px) {
  .auth-container {
    padding: 32px;
    max-width: 500px;
  }

  .logo h1 {
    font-size: 28px;
  }

  .logo svg {
    width: 110px;
    height: 95px;
  }
}

/* Small laptops and tablets - Landscape */
@media (min-width: 769px) and (max-width: 1024px) {
  .auth-container {
    max-width: 480px;
  }
}

/* High-DPI / Retina displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .form-group input,
  .btn,
  .tab {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
}

/* iOS Safari specific */
@supports (-webkit-touch-callout: none) {
  .form-group input {
    font-size: 16px; /* Prevent zoom */
  }

  /* Fix for iOS Safari bottom bar */
  #auth-screen {
    min-height: -webkit-fill-available;
  }

  .auth-container {
    max-height: -webkit-fill-available;
  }
}

/* Firefox specific */
@-moz-document url-prefix() {
  .form-group input {
    padding: 11px 16px; /* Adjust for Firefox rendering */
  }
}

/* Microsoft Edge specific */
@supports (-ms-ime-align:auto) {
  .btn,
  .tab {
    border: 1px solid transparent; /* Fix Edge button rendering */
  }
}

/* Dark mode support (if OS is in dark mode) */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #1F2937;
    --bg-secondary: #111827;
    --bg-tertiary: #374151;
    --text-primary: #F9FAFB;
    --text-secondary: #9CA3AF;
    --border-color: #4B5563;
  }
 
  .form-group input {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    -webkit-box-shadow: 0 0 0 1000px var(--bg-secondary) inset;
    box-shadow: 0 0 0 1000px var(--bg-secondary) inset;
  }
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High contrast mode for accessibility */
@media (prefers-contrast: high) {
  .form-group input {
    border-width: 3px;
  }

  .btn,
  .tab {
    border: 2px solid currentColor;
  }
}

/* Print styles */
@media print {
  #auth-screen {
    background: white;
  }

  .auth-container {
    box-shadow: none;
    border: 1px solid #000;
  }
}

/* Very small screens  (smartwatches, small phones) */
@media (max-width: 320px) {
  .auth-container {
    padding: 16px;
    margin: 5px;
  }

  .logo h1 {
    font-size: 18px;
  }

  .logo svg {
    width: 80px;
    height: 70px;
  }

  .tagline {
    font-size: 10px;
  }

  .form-group input,
  .btn,
  .tab {
    font-size: 14px;
  }
}

/* Extra large screens */
@media (min-width: 1920px) {
  /* Keep forms at optimal reading size */
  .auth-container {
    max-width: 500px;
  }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
  .btn,
  .tab {
    min-height: 48px; /* Larger touch targets */
    padding: 16px 24px;
  }

  .form-group input {
    min-height: 48px;
    padding: 14px 16px;
  }

  /* Remove hover effects on touch devices */
  .btn:hover,
  .tab:hover {
    transform: none;
  }
}
