/* LexBANK Smart Chat - Styles */

/* iOS Safe Area */
.safe-area-inset {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

html {
  overscroll-behavior: none;
}

body {
  -webkit-overflow-scrolling: touch;
  position: fixed;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#app {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

@media (display-mode: standalone) {
  header { padding-top: env(safe-area-inset-top) !important; }
  .border-t { padding-bottom: env(safe-area-inset-bottom) !important; }
}

@media (hover: none) and (pointer: coarse) {
  button, a, select, input, textarea {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #374151; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #4b5563; }
* { scrollbar-width: thin; scrollbar-color: #374151 transparent; }

/* ============= Smart Chat Styles ============= */

/* Welcome Glow Effect */
.welcome-glow {
  position: relative;
}
.welcome-glow::before {
  content: '';
  position: absolute;
  inset: -20px;
  background: radial-gradient(circle, rgba(76, 110, 245, 0.15) 0%, transparent 70%);
  border-radius: 50%;
  z-index: -1;
  animation: glow-pulse 3s ease-in-out infinite;
}

@keyframes glow-pulse {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.1); }
}

/* Capability Cards */
.capability-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem 0.75rem;
  border: 1px solid #1f2937;
  border-radius: 1rem;
  background: rgba(17, 24, 39, 0.5);
  transition: all 0.2s;
}
.capability-card:hover {
  border-color: rgba(76, 110, 245, 0.4);
  background: rgba(76, 110, 245, 0.05);
}

/* Quick Action Buttons */
.quick-action-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: right;
  padding: 0.75rem 1rem;
  background: rgba(17, 24, 39, 0.5);
  border: 1px solid #1f2937;
  border-radius: 0.875rem;
  transition: all 0.2s;
}
.quick-action-btn:hover {
  background: rgba(31, 41, 55, 0.8);
  border-color: rgba(76, 110, 245, 0.4);
  transform: translateY(-1px);
}
.quick-action-tag {
  font-size: 0.65rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: rgba(76, 110, 245, 0.1);
  border: 1px solid rgba(76, 110, 245, 0.2);
  color: #a5b4fc;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Smart Status Bar */
.smart-status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.75rem;
  border: 1px solid #1e293b;
  background: rgba(15, 23, 42, 0.6);
}
.status-chip {
  font-size: 0.68rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  border: 1px solid #2e3b58;
  background: rgba(8, 15, 33, 0.5);
  color: #94a3b8;
  white-space: nowrap;
}
.status-chip-active {
  background: rgba(76, 110, 245, 0.15);
  border-color: rgba(76, 110, 245, 0.3);
  color: #a5b4fc;
}

/* Message Styles */
.message-row {
  display: flex;
  animation: messageIn 0.3s ease-out;
}
.message-row-user { justify-content: flex-start; }
.message-row-assistant { justify-content: flex-end; }

.message-bubble {
  border-radius: 1.25rem;
  padding: 0.875rem 1rem;
  line-height: 1.6;
}
.message-bubble-user {
  background: rgba(76, 110, 245, 0.12);
  border: 1px solid rgba(76, 110, 245, 0.25);
  color: #e2e8f0;
  border-bottom-right-radius: 0.5rem;
}
[dir="rtl"] .message-bubble-user {
  border-bottom-right-radius: 1.25rem;
  border-bottom-left-radius: 0.5rem;
}
.message-bubble-assistant {
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid rgba(51, 65, 85, 0.5);
  color: #e2e8f0;
  border-bottom-left-radius: 0.5rem;
}
[dir="rtl"] .message-bubble-assistant {
  border-bottom-left-radius: 1.25rem;
  border-bottom-right-radius: 0.5rem;
}

.message-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid #374151;
  background: rgba(17, 24, 39, 0.7);
  border-radius: 999px;
  color: #94a3b8;
  font-size: 0.67rem;
  padding: 0.2rem 0.55rem;
  transition: all 0.15s;
}
.message-action-btn:hover {
  border-color: #5c7cfa;
  color: #c8d4ff;
}

/* Streaming Indicator */
.streaming-indicator {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
  animation: streaming-blink 1s ease-in-out infinite;
}
@keyframes streaming-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Typing Dots */
.typing-dot {
  width: 8px;
  height: 8px;
  background: #6b7280;
  border-radius: 50%;
  animation: typing-bounce 1.2s ease-in-out infinite;
}
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-8px); }
}

/* Follow-up Suggestions */
.follow-up-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  padding: 0.45rem 0.85rem;
  border: 1px solid rgba(76, 110, 245, 0.25);
  background: rgba(76, 110, 245, 0.08);
  border-radius: 999px;
  color: #a5b4fc;
  transition: all 0.2s;
  max-width: 100%;
}
.follow-up-btn:hover {
  background: rgba(76, 110, 245, 0.18);
  border-color: rgba(76, 110, 245, 0.5);
  color: #c7d2fe;
  transform: translateY(-1px);
}

/* Chat Input */
.chat-input {
  width: 100%;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 0.875rem;
  padding: 0.75rem 1rem;
  color: white;
  font-size: 0.875rem;
  line-height: 1.5;
  resize: none;
  transition: all 0.2s;
  outline: none;
  max-height: 8rem;
  overflow-y: auto;
}
.chat-input::placeholder { color: #475569; }
.chat-input:focus {
  border-color: #4c6ef5;
  box-shadow: 0 0 0 3px rgba(76, 110, 245, 0.15);
}
.char-counter {
  position: absolute;
  bottom: 0.5rem;
  left: 0.75rem;
  font-size: 0.6rem;
  color: #475569;
  pointer-events: none;
}
[dir="rtl"] .char-counter {
  left: auto;
  right: 0.75rem;
}

/* Send Button */
.send-btn {
  height: 2.75rem;
  width: 2.75rem;
  flex-shrink: 0;
  background: linear-gradient(135deg, #4c6ef5, #3b5bdb);
  border-radius: 0.875rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(76, 110, 245, 0.25);
}
.send-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #5c7cfa, #4c6ef5);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(76, 110, 245, 0.35);
}
.send-btn:disabled {
  background: #374151;
  cursor: not-allowed;
  box-shadow: none;
}

/* Scroll to bottom */
.scroll-bottom-btn {
  position: absolute;
  bottom: 6rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(76, 110, 245, 0.9);
  color: white;
  border-radius: 50%;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transition: all 0.2s;
  z-index: 10;
}
.scroll-bottom-btn:hover {
  background: rgba(76, 110, 245, 1);
  transform: translateX(-50%) translateY(-2px);
}

/* Conversation Sidebar */
.conv-sidebar {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}
.conv-sidebar-inner {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(320px, 85vw);
  background: #0f172a;
  border-left: 1px solid #1e293b;
  display: flex;
  flex-direction: column;
}
[dir="rtl"] .conv-sidebar-inner {
  right: auto;
  left: 0;
  border-left: none;
  border-right: 1px solid #1e293b;
}
.conv-item {
  padding: 0.75rem;
  border-radius: 0.75rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
}
.conv-item:hover {
  background: rgba(30, 41, 59, 0.6);
  border-color: #1e293b;
}
.conv-item-active {
  background: rgba(76, 110, 245, 0.1);
  border-color: rgba(76, 110, 245, 0.2);
}

/* Mode Dropdown */
.mode-dropdown {
  position: absolute;
  left: 0;
  margin-top: 0.25rem;
  width: 280px;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 0.75rem;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.4);
  z-index: 50;
  overflow: hidden;
  max-height: 400px;
  overflow-y: auto;
}
[dir="rtl"] .mode-dropdown {
  left: auto;
  right: 0;
}

/* Preferences Panel */
.preferences-panel {
  border-radius: 0.875rem;
  border: 1px solid #1e293b;
  background: rgba(15, 23, 42, 0.8);
  padding: 0.75rem;
}

/* ============= Existing Styles ============= */

/* Prose overrides for RTL markdown */
.prose { direction: inherit; text-align: inherit; }
.prose p { margin-top: 0.5em; margin-bottom: 0.5em; }
.prose p:first-child { margin-top: 0; }
.prose p:last-child { margin-bottom: 0; }
.prose ul, .prose ol { padding-inline-start: 1.5em; margin-top: 0.5em; margin-bottom: 0.5em; }
.prose li { margin-top: 0.25em; margin-bottom: 0.25em; }
.prose code {
  background: rgba(0, 0, 0, 0.3);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.85em;
  font-family: 'Courier New', monospace;
}
.prose pre {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 1em;
  overflow-x: auto;
  margin: 0.75em 0;
  direction: ltr;
  text-align: left;
}
.prose pre code { background: none; padding: 0; font-size: 0.85em; }
.prose blockquote {
  border-inline-start: 3px solid #4c6ef5;
  padding-inline-start: 1em;
  margin-inline-start: 0;
  color: #9ca3af;
  font-style: italic;
}
.prose a { color: #748ffc; text-decoration: underline; text-underline-offset: 2px; }
.prose a:hover { color: #91a7ff; }
.prose h1, .prose h2, .prose h3, .prose h4 {
  font-weight: 700;
  margin-top: 1em;
  margin-bottom: 0.5em;
  color: #f3f4f6;
}
.prose h1 { font-size: 1.25em; }
.prose h2 { font-size: 1.15em; }
.prose h3 { font-size: 1.05em; }
.prose table { width: 100%; border-collapse: collapse; margin: 0.75em 0; font-size: 0.9em; }
.prose th, .prose td { border: 1px solid #374151; padding: 0.5em 0.75em; text-align: inherit; }
.prose th { background: rgba(0, 0, 0, 0.3); font-weight: 600; }
.prose hr { border: none; border-top: 1px solid #374151; margin: 1em 0; }

/* Quick entry links */
.entry-link-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  color: #cdd6f7;
  text-decoration: none;
  border: 1px solid #293248;
  background: rgba(17, 24, 39, 0.6);
  border-radius: 999px;
  padding: 0.35rem 0.65rem;
  white-space: nowrap;
  transition: 0.15s ease;
}
.entry-link-chip:hover {
  background: rgba(28, 41, 70, 0.8);
  border-color: #4c6ef5;
}

/* Model provider status pills */
.provider-pill {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  justify-content: space-between;
  border-radius: 0.7rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid #2b354d;
  font-size: 0.72rem;
}
.provider-pill-online {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.38);
  color: #9ef0cd;
}
.provider-pill-offline {
  background: rgba(75, 85, 99, 0.22);
  border-color: rgba(75, 85, 99, 0.42);
  color: #a3afc9;
}

/* Command button */
.command-btn {
  border: 1px solid #2b354b;
  background: rgba(31, 41, 55, 0.7);
  color: #94a3b8;
  border-radius: 0.5rem;
  padding: 0.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.command-btn:hover {
  border-color: #4c6ef5;
  color: #c8d4ff;
}

/* Preferences */
.preference-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.72rem;
  color: #9ca3af;
}
.preference-field select {
  border: 1px solid #2b364f;
  border-radius: 0.6rem;
  background: rgba(17, 24, 39, 0.8);
  color: #e5e7eb;
  padding: 0.4rem 0.5rem;
  font-size: 0.78rem;
}
.toggle-chip, .template-chip {
  border: 1px solid #2f3a56;
  background: rgba(15, 23, 42, 0.75);
  border-radius: 999px;
  padding: 0.32rem 0.58rem;
  color: #cfd8ff;
  font-size: 0.72rem;
  transition: all 0.15s;
}
.toggle-chip-active {
  border-color: rgba(76, 110, 245, 0.7);
  background: rgba(76, 110, 245, 0.22);
}
.template-chip:hover, .toggle-chip:hover { border-color: #4c6ef5; }

/* Toast Container */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}
[dir="rtl"] .toast-container { right: auto; left: 1rem; }
@media (max-width: 640px) {
  .toast-container { top: auto; bottom: 5rem; right: 1rem; left: 1rem; }
}
.toast {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-radius: 0.75rem;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
  pointer-events: auto;
  min-width: 280px;
  max-width: 450px;
  backdrop-filter: blur(8px);
  font-size: 0.8rem;
}
@media (max-width: 640px) { .toast { min-width: auto; max-width: 100%; } }
.toast-success { background: rgba(16, 185, 129, 0.95); color: white; border: 1px solid rgba(16, 185, 129, 0.3); }
.toast-error { background: rgba(239, 68, 68, 0.95); color: white; border: 1px solid rgba(239, 68, 68, 0.3); }
.toast-warning { background: rgba(245, 158, 11, 0.95); color: white; border: 1px solid rgba(245, 158, 11, 0.3); }
.toast-info { background: rgba(59, 130, 246, 0.95); color: white; border: 1px solid rgba(59, 130, 246, 0.3); }
.toast-icon { flex-shrink: 0; font-size: 1.1rem; }
.toast-message { flex: 1; line-height: 1.4; }
.toast-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: inherit;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
  padding: 0;
}
.toast-close:hover { opacity: 1; }
[dir="rtl"] .toast-close { margin-left: 0; margin-right: 0.5rem; }

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

.toast-enter-active { transition: all 0.3s ease-out; }
.toast-leave-active { transition: all 0.2s ease-in; }
.toast-enter-from { opacity: 0; transform: translateY(-20px) scale(0.95); }
.toast-leave-to { opacity: 0; transform: translateX(100px) scale(0.95); }
[dir="rtl"] .toast-leave-to { transform: translateX(-100px) scale(0.95); }
.toast-move { transition: transform 0.3s ease; }

.slide-panel-enter-active { transition: all 0.3s ease-out; }
.slide-panel-leave-active { transition: all 0.2s ease-in; }
.slide-panel-enter-from, .slide-panel-leave-to { opacity: 0; }

.slide-down-enter-active { transition: all 0.2s ease-out; }
.slide-down-leave-active { transition: all 0.15s ease-in; }
.slide-down-enter-from { opacity: 0; transform: translateY(-8px); }
.slide-down-leave-to { opacity: 0; transform: translateY(-8px); }

.fade-up-enter-active { transition: all 0.2s ease-out; }
.fade-up-leave-active { transition: all 0.15s ease-in; }
.fade-up-enter-from { opacity: 0; transform: translateX(-50%) translateY(8px); }
.fade-up-leave-to { opacity: 0; transform: translateX(-50%) translateY(8px); }

/* Skeleton Loading */
.skeleton-container { padding: 1rem; }
.skeleton-message { display: flex; gap: 0.75rem; padding: 1rem 0; }
.skeleton-avatar {
  width: 2.5rem; height: 2.5rem; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(90deg, #1f2937 0%, #374151 50%, #1f2937 100%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}
.skeleton-content { flex: 1; display: flex; flex-direction: column; gap: 0.5rem; }
.skeleton-line {
  height: 1rem; border-radius: 0.25rem;
  background: linear-gradient(90deg, #1f2937 0%, #374151 50%, #1f2937 100%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}
.skeleton-line-short { width: 25%; }
.skeleton-line-medium { width: 60%; }
.skeleton-line-long { width: 100%; height: 4rem; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Focus ring */
textarea:focus, button:focus-visible { outline: none; }
button { transition: all 0.15s ease; }
button:active:not(:disabled) { transform: scale(0.97); }

/* Responsive */
@media (max-width: 640px) {
  header .flex.items-center.gap-2 { gap: 0.25rem; }
  header button { padding-left: 0.5rem; padding-right: 0.5rem; }
  .smart-status-bar { flex-direction: column; align-items: stretch; }
  .follow-up-btn { font-size: 0.72rem; padding: 0.35rem 0.65rem; }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  .skeleton-avatar, .skeleton-line, button, textarea, .welcome-glow::before,
  .streaming-indicator, .typing-dot {
    animation: none !important;
    transition: none !important;
  }
}
