@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;500;600;700&family=Rajdhani:wght@400;500;600;700&display=swap');

:root {
  --bg: #0d0d1a;
  --bg-secondary: #1a1a2e;
  --bg-tertiary: #252540;
  --text: #e0e0ff;
  --text-secondary: #a0a0c0;
  --border: #3a3a5c;
  --primary: #ff6ec7;
  --primary-hover: #ff8ed7;
  --secondary: #7b68ee;
  --accent: #00d4ff;
  --user-msg-bg: linear-gradient(135deg, #7b68ee 0%, #ff6ec7 100%);
  --user-msg-text: #ffffff;
  --assistant-msg-bg: #1a1a2e;
  --assistant-msg-text: #e0e0ff;
  --radius: 6px;
  --glow-primary: 0 0 20px rgba(255, 110, 199, 0.4);
  --glow-secondary: 0 0 20px rgba(123, 104, 238, 0.4);
  --glow-accent: 0 0 20px rgba(0, 212, 255, 0.4);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}

body {
  font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  background-image: 
    radial-gradient(ellipse at top left, rgba(123, 104, 238, 0.1) 0%, transparent 50%),
    radial-gradient(ellipse at bottom right, rgba(255, 110, 199, 0.1) 0%, transparent 50%);
  color: var(--text);
  line-height: 1.5;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 900px;
  margin: 0 auto;
  background: transparent;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: linear-gradient(180deg, rgba(13, 13, 26, 0.98) 0%, rgba(13, 13, 26, 0.9) 100%);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

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

.btn-install {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.2s ease;
}

.btn-install:hover {
  background: var(--bg-secondary);
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: var(--glow-accent);
}

/* Language Dropdown */
.lang-dropdown {
  position: relative;
}

.btn-lang {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-lang:hover {
  background: var(--bg-secondary);
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: var(--glow-accent);
}

.btn-lang svg {
  flex-shrink: 0;
}

.lang-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 160px;
  max-height: 320px;
  overflow-y: auto;
  z-index: 200;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.lang-menu.active {
  display: block;
}

.lang-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  color: var(--text);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.lang-option:hover {
  background: var(--bg-tertiary);
}

.lang-option.active {
  color: var(--accent);
}

.lang-option.active::before {
  content: "✓";
  font-weight: bold;
}

[dir="rtl"] .lang-menu {
  right: auto;
  left: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

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

.logo-text {
  font-family: 'Orbitron', sans-serif;
  font-size: 1.125rem;
  font-weight: 700;
  background: linear-gradient(135deg, #7b68ee 0%, #ff6ec7 50%, #00d4ff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

/* Messages Container */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  padding-top: 80px;
  padding-bottom: 180px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Message */
.message {
  display: flex;
  max-width: 80%;
  animation: fadeIn 0.3s ease-out;
}

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

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

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

.message-content {
  padding: 0.875rem 1rem;
  border-radius: var(--radius);
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
  font-size: 0.9375rem;
  line-height: 1.6;
}

.message.user .message-content {
  background: var(--user-msg-bg);
  color: var(--user-msg-text);
  box-shadow: var(--glow-primary);
}

.message.assistant .message-content {
  background: var(--assistant-msg-bg);
  color: var(--assistant-msg-text);
  border: 1px solid var(--border);
  box-shadow: inset 0 0 20px rgba(123, 104, 238, 0.05);
}

/* Code blocks in messages */
.message-content code {
  background: rgba(0, 212, 255, 0.15);
  color: var(--accent);
  padding: 0.125rem 0.375rem;
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.875em;
}

.message-content pre {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  overflow-x: auto;
  margin: 0.5rem 0;
}

.message-content pre code {
  background: transparent;
  padding: 0;
  color: var(--text);
}

/* Message Attachments */
.message-attachments {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.attachment-preview {
  position: relative;
  max-width: 200px;
}

.attachment-preview img {
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.attachment-preview.file {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.attachment-preview.file .file-icon {
  color: var(--accent);
}

.attachment-preview.file .file-info {
  display: flex;
  flex-direction: column;
  font-size: 0.8125rem;
}

.attachment-preview.file .file-name {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.attachment-preview.file .file-size {
  color: var(--text-secondary);
  font-size: 0.75rem;
}

/* Composer */
.composer {
  display: flex;
  flex-direction: column;
  padding: 1rem 1.5rem;
  background: linear-gradient(180deg, transparent 0%, rgba(13, 13, 26, 0.95) 20%);
  backdrop-filter: blur(10px);
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

.composer-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
}

.composer-input {
  flex: 1;
  min-height: 48px;
  max-height: 120px;
  padding: 0.875rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  outline: none;
  background: var(--bg-secondary);
  color: var(--text);
  transition: all 0.2s ease;
}

.composer-input:focus {
  border-color: var(--primary);
  box-shadow: var(--glow-primary);
}

.composer-input::placeholder {
  color: var(--text-secondary);
}

.composer-actions {
  display: flex;
  gap: 0.5rem;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1.125rem;
  transition: all 0.2s ease;
}

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

.btn-attach:hover {
  background: var(--bg-tertiary);
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: var(--glow-accent);
}

.btn-send {
  background: linear-gradient(135deg, #7b68ee 0%, #ff6ec7 100%);
  color: white;
  border: none;
}

.btn-send:hover {
  box-shadow: var(--glow-primary);
  transform: scale(1.02);
}

.btn-send:disabled {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: not-allowed;
  box-shadow: none;
}

/* Footer */
.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 0.75rem;
  margin-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.model-info {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.model-info svg {
  color: var(--accent);
}

/* Language Selector */
.lang-selector {
  position: relative;
}

.lang-btn {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.625rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.lang-btn:hover {
  background: var(--bg-secondary);
  color: var(--accent);
  border-color: var(--accent);
}

.lang-btn svg {
  flex-shrink: 0;
}

.lang-selector .lang-menu {
  display: none;
  position: absolute;
  bottom: 100%;
  right: 0;
  margin-bottom: 0.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 140px;
  z-index: 200;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.lang-selector .lang-menu.active {
  display: block;
}

.lang-selector .lang-option {
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease;
}

.lang-selector .lang-option:hover {
  background: var(--bg-tertiary);
}

.lang-selector .lang-option.active {
  color: var(--accent);
}

.lang-selector .lang-option.active::before {
  content: "✓";
  margin-right: 0.5rem;
}

[dir="rtl"] .lang-selector .lang-menu {
  left: auto;
  right: 50%;
  transform: translateX(50%);
}

/* Language Menu Dropdown (at body level) */
.lang-menu-dropdown {
  display: none;
  position: fixed;
  bottom: 80px;
  right: 1.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 140px;
  z-index: 1000;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.lang-menu-dropdown.active {
  display: block;
}

.lang-menu-dropdown .lang-option {
  padding: 0.625rem 0.875rem;
  font-size: 0.8125rem;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease;
}

.lang-menu-dropdown .lang-option:hover {
  background: var(--bg-tertiary);
}

.lang-menu-dropdown .lang-option.active {
  color: var(--accent);
}

.lang-menu-dropdown .lang-option.active::before {
  content: "✓";
  margin-right: 0.5rem;
}

[dir="rtl"] .lang-menu-dropdown {
  right: auto;
  left: 1.5rem;
}

/* Attachments Preview */
.attachments-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.attachment-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 200px;
}

.attachment-item img {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 4px;
}

.attachment-item.file {
  padding: 0.5rem 0.75rem;
}

.attachment-item.file .file-icon {
  color: var(--accent);
}

.attachment-item.file .file-name {
  font-size: 0.8125rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.attachment-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  background: linear-gradient(135deg, #ff6b6b 0%, #ee5a5a 100%);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.attachment-remove:hover {
  transform: scale(1.1);
  box-shadow: 0 0 10px rgba(255, 107, 107, 0.5);
}

/* Loading Indicator */
.loading {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.875rem 1rem;
  background: var(--assistant-msg-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 80%;
  align-self: flex-start;
}

.loading-dot {
  width: 6px;
  height: 6px;
  background: var(--primary);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
  box-shadow: 0 0 8px var(--primary);
}

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

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

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

/* Toast Notification */
.toast-container {
  position: fixed;
  top: 70px;
  left: 1rem;
  right: 1rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: stretch;
}

.toast {
  padding: 0.875rem 1.25rem;
  background: linear-gradient(135deg, #ff6b6b 0%, #ee5a5a 100%);
  color: white;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(255, 107, 107, 0.4);
  animation: toastIn 0.3s ease-out, toastOut 0.3s ease-in 2.7s forwards;
  text-align: center;
}

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

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

/* Drag and Drop */
.drop-zone {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(13, 13, 26, 0.9);
  border: 2px dashed var(--primary);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1rem;
}

.drop-zone.active {
  display: flex;
}

.drop-zone-text {
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--primary);
  text-shadow: 0 0 20px var(--primary);
}

.drop-zone-icon {
  color: var(--primary);
  animation: pulse 1.5s infinite;
}

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

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

.messages-container::-webkit-scrollbar-track {
  background: transparent;
}

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

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

/* Responsive */
@media (max-width: 768px) {
  #app {
    max-width: 100%;
  }

  .messages-container {
    padding: 1rem;
    padding-bottom: 160px;
  }

  .message {
    max-width: 85%;
  }

  .composer {
    padding: 0.75rem 1rem;
  }

  .composer-input-wrapper {
    gap: 0.5rem;
  }

  .btn {
    width: 44px;
    height: 44px;
  }
}

/* RTL Support */
[dir="rtl"] .header {
  flex-direction: row-reverse;
}

[dir="rtl"] .header-actions {
  flex-direction: row-reverse;
}

[dir="rtl"] .composer-input-wrapper {
  flex-direction: row-reverse;
}

[dir="rtl"] .composer-actions {
  flex-direction: row-reverse;
}

[dir="rtl"] .message.user {
  align-self: flex-start;
}

[dir="rtl"] .message.assistant {
  align-self: flex-end;
}

[dir="rtl"] .message.user .message-content {
  border-bottom-right-radius: 1rem;
  border-bottom-left-radius: 0.25rem;
}

[dir="rtl"] .message.assistant .message-content {
  border-bottom-left-radius: 1rem;
  border-bottom-right-radius: 0.25rem;
}

[dir="rtl"] .attachment-preview.file {
  flex-direction: row-reverse;
}

[dir="rtl"] .model-badge {
  flex-direction: row-reverse;
}

[dir="rtl"] .loading {
  align-self: flex-end;
}

[dir="rtl"] .loading .loading-dot {
  margin-left: 0.25rem;
  margin-right: 0;
}

[dir="rtl"] .toast {
  direction: rtl;
}

@media (max-width: 768px) {
  [dir="rtl"] .btn {
    width: 44px;
    height: 44px;
  }
}
