/* Dark Glassmorphism with Stars - Moon Theme */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #0a0e27;
  color: #e2e8f0;
  min-height: 100vh;
  overflow: auto; /* allow page scrolling on mobile */
  position: relative;
}

/* Starry Night Background */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: 
    radial-gradient(2px 2px at 20% 30%, white, transparent),
    radial-gradient(2px 2px at 60% 70%, white, transparent),
    radial-gradient(1px 1px at 50% 50%, white, transparent),
    radial-gradient(1px 1px at 80% 10%, white, transparent),
    radial-gradient(2px 2px at 90% 60%, white, transparent),
    radial-gradient(1px 1px at 33% 80%, white, transparent),
    radial-gradient(1px 1px at 15% 60%, white, transparent);
  background-size: 200% 200%;
  animation: twinkle 8s ease-in-out infinite;
  opacity: 0.5;
  pointer-events: none;
}

@keyframes twinkle {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 0.8; }
}

/* Moon */
body::after {
  content: '🌙';
  position: fixed;
  top: 40px;
  right: 60px;
  font-size: 60px;
  opacity: 0.3;
  pointer-events: none;
  animation: float 6s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-20px); }
}

.container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 100%;
  position: relative;
  z-index: 1;
}

/* Header - Ultra Compact */
.header {
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(148, 163, 184, 0.1);
  padding: 6px 10px;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
}

.header.expanded {
  padding: 8px 12px;
}

.header-compact {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.app-name {
  font-size: 14px;
  font-weight: 700;
  color: #f1f5f9;
  white-space: nowrap;
}

.expand-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  background: rgba(30, 41, 59, 0.6);
  backdrop-filter: blur(10px);
  color: #cbd5e1;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.expand-btn:hover {
  background: rgba(30, 41, 59, 0.8);
  color: #f1f5f9;
}

.select-box-mini {
  padding: 5px 8px;
  background: rgba(30, 41, 59, 0.6);
  backdrop-filter: blur(10px);
  color: #e2e8f0;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 6px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 110px;
}

.select-box-mini:hover {
  background: rgba(30, 41, 59, 0.8);
  border-color: rgba(148, 163, 184, 0.3);
}

.select-box-mini:focus {
  outline: none;
  background: rgba(30, 41, 59, 0.9);
  border-color: rgba(99, 102, 241, 0.5);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.select-box-mini option {
  background: #1e293b;
  color: #e2e8f0;
}

.header-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 10px;
  text-align: center;
  color: #f1f5f9;
  letter-spacing: -0.5px;
}

.header-controls {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  max-width: 800px;
  margin: 10px auto 0;
}

.select-box {
  padding: 8px 12px;
  background: rgba(30, 41, 59, 0.6);
  backdrop-filter: blur(10px);
  color: #e2e8f0;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
}

.select-box:hover {
  background: rgba(30, 41, 59, 0.8);
  border-color: rgba(148, 163, 184, 0.3);
}

.select-box:focus {
  outline: none;
  background: rgba(30, 41, 59, 0.9);
  border-color: rgba(99, 102, 241, 0.5);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.select-box option {
  background: #1e293b;
  color: #e2e8f0;
}

/* Stats Bar */
.stats-bar {
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(148, 163, 184, 0.1);
  padding: 5px 12px;
  display: flex;
  justify-content: center;
  gap: 10px;
  font-size: 10px;
}

.stats-bar span {
  background: rgba(30, 41, 59, 0.6);
  padding: 3px 10px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  font-weight: 500;
  backdrop-filter: blur(5px);
  color: #cbd5e1;
}

/* Chat Area */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  -webkit-overflow-scrolling: touch;
}

/* Prevent chat content from being hidden behind the input on small screens */
.chat-area {
  padding-bottom: 140px;
}

.chat-area::-webkit-scrollbar {
  width: 6px;
}

.chat-area::-webkit-scrollbar-track {
  background: rgba(30, 41, 59, 0.3);
}

.chat-area::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.3);
  border-radius: 3px;
}

.chat-area::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.5);
}

.welcome {
  text-align: center;
  margin-top: 60px;
  opacity: 0.6;
  font-size: 16px;
  font-weight: 500;
  color: #94a3b8;
}

.message {
  margin-bottom: 8px;
  display: block;
  clear: both;
  animation: slideIn 0.3s ease;
}

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

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

.message-bubble {
  display: inline-block;
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 12px;
  text-align: left;
  word-wrap: break-word;
  line-height: 1.4;
  font-size: 13px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease;
}

.message-bubble:hover {
  transform: translateY(-2px);
}

.message.user .message-bubble {
  background: rgba(99, 102, 241, 0.2);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: #e2e8f0;
}

.message.ai .message-bubble {
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.2);
  color: #e2e8f0;
  max-width: 95%;
}

/* Text Formatting */
.message-bubble h1,
.message-bubble h2,
.message-bubble h3 {
  display: block;
  margin: 10px 0 6px 0;
  font-weight: 700;
  color: #f1f5f9;
}

.message-bubble h1 {
  font-size: 18px;
  border-bottom: 2px solid rgba(148, 163, 184, 0.3);
  padding-bottom: 5px;
}

.message-bubble h2 {
  font-size: 16px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
  padding-bottom: 4px;
}

.message-bubble h3 {
  font-size: 15px;
}

.message-bubble p {
  display: block;
  margin: 6px 0;
}

.message-bubble ul,
.message-bubble ol {
  display: block;
  margin: 8px 0;
  padding-left: 20px;
}

.message-bubble ul {
  list-style-type: disc;
}

.message-bubble ol {
  list-style-type: decimal;
}

.message-bubble li {
  display: list-item;
  margin: 4px 0;
  line-height: 1.5;
}

.message-bubble ul.checklist {
  list-style-type: none;
  padding-left: 5px;
}

.message-bubble ul.checklist li {
  margin-bottom: 10px;
}

.message-bubble strong {
  font-weight: 700;
  color: #f1f5f9;
}

.message-bubble em {
  font-style: italic;
}

.message-bubble code {
  background: rgba(15, 23, 42, 0.8);
  padding: 3px 8px;
  border-radius: 6px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  color: #a5b4fc;
}

.message-bubble hr {
  border: none;
  border-top: 1px solid rgba(148, 163, 184, 0.3);
  margin: 12px 0;
}

.message-bubble pre {
  background: rgba(15, 23, 42, 0.9);
  padding: 14px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 12px 0;
  border: 1px solid rgba(148, 163, 184, 0.2);
}

.message-bubble pre code {
  background: transparent;
  padding: 0;
  border: none;
}

/* Table Styling */
.table-wrapper {
  overflow-x: auto;
  margin: 12px 0;
  -webkit-overflow-scrolling: touch;
  border-radius: 10px;
}

.message-bubble table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 10px;
  overflow: hidden;
}

.message-bubble table th,
.message-bubble table td {
  border: 1px solid rgba(148, 163, 184, 0.2);
  padding: 10px 12px;
  text-align: left;
}

.message-bubble table th {
  background: rgba(30, 41, 59, 0.8);
  font-weight: 600;
  color: #f1f5f9;
}

.message-bubble table tr:nth-child(even) {
  background: rgba(30, 41, 59, 0.3);
}

/* Action Buttons */
.action-btns {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
  flex-wrap: wrap;
}

.action-btn {
  padding: 8px 14px;
  background: rgba(30, 41, 59, 0.6);
  color: #cbd5e1;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.3s ease;
  backdrop-filter: blur(5px);
}

.action-btn:hover {
  background: rgba(30, 41, 59, 0.8);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  color: #f1f5f9;
}

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

.action-btn.speaking {
  background: rgba(239, 68, 68, 0.3);
  border-color: rgba(239, 68, 68, 0.5);
  color: #fca5a5;
}

/* Loading Animation */
.loading-dots {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.loading-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(148, 163, 184, 0.8);
  animation: bounce 1.4s infinite ease-in-out;
}

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

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

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

/* Input Area - Ultra Compact */
.input-area {
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(148, 163, 184, 0.1);
  padding: 8px 10px;
  box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.3);
}

.input-buttons {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  background: rgba(30, 41, 59, 0.6);
  backdrop-filter: blur(10px);
  color: #cbd5e1;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.icon-btn:hover {
  background: rgba(30, 41, 59, 0.8);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  color: #f1f5f9;
}

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

.icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.image-preview {
  margin-bottom: 16px;
  padding: 12px;
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 12px;
  position: relative;
  backdrop-filter: blur(10px);
}

.image-preview img {
  max-width: 200px;
  max-height: 150px;
  border-radius: 10px;
  border: 2px solid rgba(148, 163, 184, 0.3);
}

.clear-img {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(239, 68, 68, 0.9);
  color: white;
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  font-weight: bold;
  transition: all 0.3s ease;
  backdrop-filter: blur(5px);
}

.clear-img:hover {
  background: rgba(239, 68, 68, 1);
  transform: scale(1.1);
}

.input-wrapper {
  display: flex;
  gap: 6px;
  align-items: flex-end;
}

#userInput {
  flex: 1;
  padding: 8px 12px;
  background: rgba(30, 41, 59, 0.6);
  backdrop-filter: blur(10px);
  color: #e2e8f0;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 6px;
  font-size: 13px;
  resize: none;
  font-family: inherit;
  transition: all 0.3s ease;
  min-height: 34px;
  max-height: 90px;
}

#userInput:focus {
  outline: none;
  background: rgba(30, 41, 59, 0.8);
  border-color: rgba(99, 102, 241, 0.5);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

#userInput::placeholder {
  color: rgba(148, 163, 184, 0.6);
}

.send-btn {
  padding: 8px 16px;
  background: rgba(99, 102, 241, 0.2);
  backdrop-filter: blur(10px);
  color: #e0e7ff;
  border: 1px solid rgba(99, 102, 241, 0.4);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
  height: 34px;
}

.send-btn:hover {
  background: rgba(99, 102, 241, 0.3);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.3);
  color: #fff;
}

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

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

/* Fullscreen Mode */
body.fullscreen .header {
  padding: 6px 10px;
}

body.fullscreen .app-name {
  font-size: 14px;
}

body.fullscreen .expand-btn,
body.fullscreen .select-box-mini {
  height: 28px;
  font-size: 11px;
}

body.fullscreen .input-area {
  padding: 8px 10px;
}

body.fullscreen .icon-btn {
  width: 32px;
  height: 32px;
  font-size: 14px;
}

body.fullscreen #userInput {
  min-height: 34px;
  padding: 8px 12px;
  font-size: 13px;
}

body.fullscreen .send-btn {
  height: 34px;
  padding: 8px 16px;
  font-size: 12px;
}

body.fullscreen .message-bubble {
  padding: 10px 14px;
  font-size: 13px;
}

/* Desktop Styles */
@media (min-width: 768px) {
  .container {
    max-width: 1100px;
    margin: 30px auto;
    height: calc(100vh - 60px);
    border-radius: 24px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(148, 163, 184, 0.2);
  }

  .header-title {
    font-size: 28px;
  }

  .header-controls {
    max-width: 900px;
  }

  .chat-area {
    padding: 32px;
  }

  .message-bubble {
    max-width: 70%;
  }

  .input-area {
    padding: 24px;
  }
}

/* Mobile optimizations */
@media (max-width: 480px) {
  .header {
    padding: 16px;
  }

  .header-title {
    font-size: 20px;
    margin-bottom: 12px;
  }

  .header-controls {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .select-box {
    font-size: 13px;
    padding: 10px 14px;
  }

  .stats-bar {
    font-size: 11px;
    padding: 10px 16px;
    gap: 12px;
  }

  .stats-bar span {
    padding: 6px 12px;
    font-size: 11px;
  }

  .chat-area {
    padding: 16px;
  }

  .message-bubble {
    font-size: 14px;
    padding: 14px 16px;
  }

  .input-area {
    padding: 16px;
    position: fixed; /* keep input fixed at bottom on mobile */
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    backdrop-filter: blur(12px);
  }

  .input-buttons {
    gap: 8px;
    margin-bottom: 12px;
  }

  .icon-btn {
    width: 44px;
    height: 44px;
    font-size: 18px;
  }

  .input-wrapper {
    flex-direction: column;
    gap: 12px;
  }

  #userInput {
    width: 100%;
  }

  .send-btn {
    width: 100%;
    height: 48px;
  }
}
