/* FreeAI - Elite Mobile & Desktop UI Design */
:root {
  --bg-app: #09090b;
  --bg-surface: #121215;
  --bg-surface-hover: #18181b;
  --bg-input: #18181c;
  --bg-user-bubble: #27272a;
  --bg-code-block: #0e0e11;

  --border: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.16);
  --border-focus: rgba(255, 255, 255, 0.28);

  --text-main: #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

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

html, body {
  background-color: var(--bg-app);
  color: var(--text-main);
  font-family: var(--font);
  height: 100%;
  width: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  position: relative;
}

/* Header */
.app-header {
  height: 54px;
  background: rgba(9, 9, 11, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 30;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.header-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-main);
}

.model-pill-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 12px;
  cursor: pointer;
  color: var(--text-main);
  transition: all 0.15s ease;
}

.model-pill-btn:hover {
  border-color: var(--border-hover);
  background: var(--bg-surface-hover);
}

.badge-tag {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 4px;
}

.badge-tag.openai    { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.badge-tag.google    { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.badge-tag.anthropic { background: rgba(168, 85, 247, 0.15); color: #c084fc; }

.model-name-text {
  font-size: 0.85rem;
  font-weight: 600;
}

.chevron {
  color: var(--text-muted);
}

.header-right {
  display: flex;
  align-items: center;
}

.quota-counter {
  font-size: 0.78rem;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 4px 10px;
  font-weight: 600;
}

.quota-denom {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* Chat Thread */
.chat-thread {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scroll-behavior: smooth;
}

.chat-thread::-webkit-scrollbar {
  width: 5px;
}
.chat-thread::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

/* Welcome Hero */
.welcome-hero {
  max-width: 620px;
  width: 100%;
  margin: auto;
  text-align: center;
  padding: 30px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hero-brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, #3b82f6, #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: #fff;
  margin-bottom: 16px;
  box-shadow: 0 8px 24px rgba(59, 130, 246, 0.25);
}

.hero-headline {
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.hero-sub {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.45;
  margin-bottom: 24px;
}

.starter-chips {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  width: 100%;
}

.starter-chip {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text-secondary);
  font-size: 0.82rem;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s;
}

.starter-chip:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-hover);
  color: var(--text-main);
  transform: translateY(-1px);
}

/* Message Rows */
.msg-row {
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.msg-row.user {
  align-items: flex-end;
}

.msg-bubble {
  padding: 10px 16px;
  border-radius: 16px;
  font-size: 0.92rem;
  line-height: 1.55;
  word-break: break-word;
}

.msg-row.user .msg-bubble {
  background: var(--bg-user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
  max-width: 82%;
}

.msg-row.assistant .msg-bubble {
  background: transparent;
  color: var(--text-main);
  padding: 4px 0;
  width: 100%;
}

.msg-user-img {
  max-width: 220px;
  max-height: 180px;
  border-radius: 10px;
  margin-bottom: 8px;
  display: block;
}

/* Thinking accordion */
.think-accordion {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(168, 85, 247, 0.25);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 12px;
  font-size: 0.8rem;
}

.think-accordion summary {
  cursor: pointer;
  color: #c084fc;
  font-weight: 600;
  user-select: none;
}

.think-accordion .think-inner {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.76rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

/* Code block rendering */
.msg-bubble pre {
  background: var(--bg-code-block);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 12px 0;
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

.code-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.copy-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.72rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}

.copy-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.08);
}

.copy-btn.copied {
  color: #34d399;
}

.msg-bubble pre code {
  padding: 12px;
  display: block;
  overflow-x: auto;
  background: transparent;
}

.msg-bubble code {
  font-family: var(--font-mono);
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 0.85em;
}

.msg-footer {
  display: flex;
  gap: 8px;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.msg-footer button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.7rem;
}
.msg-footer button:hover {
  color: var(--text-main);
}

/* Typing Dots */
.typing-dots {
  display: flex;
  gap: 4px;
  padding: 6px 0;
}
.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #3b82f6;
  animation: bounce 1.3s infinite ease-in-out;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

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

/* Rate Alert Toast */
.rate-toast {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  background: #27272a;
  border: 1px solid #3f3f46;
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 40;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
  max-width: 90%;
}

.toast-body {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: #fbbf24;
}

.toast-btn {
  background: rgba(245, 158, 11, 0.2);
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: #fff;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

/* Input Wrapper & Floating Bar */
.input-wrapper {
  padding: 8px 16px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  max-width: 780px;
  width: 100%;
  margin: 0 auto;
  position: relative;
  z-index: 20;
}

.image-attachment-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding: 6px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.preview-img-box {
  position: relative;
  width: 44px;
  height: 44px;
}

#attached-img-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.discard-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #3f3f46;
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.attachment-label {
  font-size: 0.76rem;
  color: #34d399;
}

.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 10px;
  transition: border-color 0.15s ease;
}

.input-bar:focus-within {
  border-color: var(--border-focus);
}

.icon-action-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.15s;
}

.icon-action-btn:hover {
  color: var(--text-main);
}

#message-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-family: var(--font);
  font-size: 0.95rem;
  line-height: 1.45;
  resize: none;
  max-height: 160px;
  min-height: 24px;
  padding: 6px 0;
}

#message-input::placeholder {
  color: var(--text-muted);
}

.send-circle-btn {
  background: var(--text-main);
  color: var(--bg-app);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  margin-bottom: 2px;
  transition: opacity 0.15s, transform 0.1s;
}

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

.send-circle-btn:active:not(:disabled) {
  transform: scale(0.92);
}

/* Bottom Sheet & Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-sheet {
  background: #141417;
  border: 1px solid var(--border-hover);
  border-radius: 16px;
  width: 90%;
  max-width: 480px;
  padding: 16px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
  animation: slideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.sheet-drag-handle {
  display: none;
}

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

.sheet-title {
  font-size: 1rem;
  font-weight: 700;
}

.sheet-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
}

.sheet-model-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sheet-model-item {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.15s ease;
}

.sheet-model-item:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: var(--border-hover);
}

.sheet-model-item.active {
  background: rgba(59, 130, 246, 0.1);
  border-color: #3b82f6;
}

.item-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.item-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.item-name {
  font-size: 0.9rem;
  font-weight: 600;
}

.item-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.item-quota-pill {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.06);
  padding: 3px 8px;
  border-radius: 6px;
  white-space: nowrap;
}

/* Mobile Optimizations */
@media (max-width: 640px) {
  .app-header {
    padding: 0 12px;
  }
  .input-wrapper {
    padding: 6px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
  .starter-chips {
    grid-template-columns: 1fr;
  }
  .modal-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    border-radius: 20px 20px 0 0;
    padding: 16px 16px max(24px, env(safe-area-inset-bottom)) 16px;
    margin: 0;
  }
  .sheet-drag-handle {
    display: block;
    width: 36px;
    height: 4px;
    background: #3f3f46;
    border-radius: 2px;
    margin: 0 auto 12px auto;
  }
  .sheet-model-item {
    padding: 14px;
  }
}

/* Custom System Prompt Sheet Styles */
.prompt-sheet {
  max-width: 600px;
}

.sheet-title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sheet-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.sheet-subtitle code {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 4px;
  border-radius: 4px;
  color: var(--text-secondary);
}

.prompt-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 6px;
}

.prompt-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
}

.prompt-action-pill {
  background: var(--bg-surface-hover);
  border: 1px solid var(--border);
  color: var(--text-main);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.prompt-action-pill:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--border-hover);
}

.prompt-action-pill.secondary {
  color: var(--text-muted);
}

.prompt-action-pill.secondary:hover {
  color: var(--text-main);
}

#system-prompt-textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.84rem;
  line-height: 1.5;
  padding: 12px;
  outline: none;
  resize: vertical;
  min-height: 140px;
  max-height: 380px;
  transition: border-color 0.15s;
}

#system-prompt-textarea:focus {
  border-color: var(--border-focus);
}

.prompt-footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.prompt-status-text {
  font-size: 0.74rem;
  color: #34d399;
}

.save-prompt-btn {
  background: var(--text-main);
  color: var(--bg-app);
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.save-prompt-btn:hover {
  opacity: 0.9;
}
