:root {
  --bg: #fafafa;
  --bg-elevated: #ffffff;
  --text: #0a0a0a;
  --text-secondary: #525252;
  --text-muted: #8a8a8a;
  --border: #e8e8e8;
  --border-strong: #d4d4d4;
  --accent: #0a0a0a;
  --accent-hover: #262626;
  --surface: #f4f4f5;
  --surface-hover: #ececec;
  --danger: #ef4444;
  --success: #10b981;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.06);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.08);
  --radius-lg: 24px;
  --radius-full: 9999px;
  --font-en: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-ar: 'Cairo', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html, body {
  height: 100%;
}

body {
  font-family: var(--font-en);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s ease, color 0.3s ease;
}

[dir="rtl"] body,
[dir="rtl"] * {
  font-family: var(--font-ar);
}

/* ========== Icons ========== */
.app-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  font-style: normal;
  line-height: 1;
  flex-shrink: 0;
}
.app-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* ========== Header ========== */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(12px);
  background: color-mix(in srgb, var(--bg-elevated) 85%, transparent);
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}
.brand-logo img.custom-logo {
  height: 48px;
  width: auto;
  object-fit: contain;
}
.brand-text {
  font-weight: 800;
  font-size: 19px;
  letter-spacing: -0.6px;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-new-chat {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 5px 11px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all var(--transition);
}
.btn-new-chat:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}
.btn-new-chat .app-icon {
  width: 14px;
  height: 14px;
}

.btn-signup {
  background: var(--accent);
  color: var(--bg);
  border: none;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-signup:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.menu-icon {
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 8px;
  border-radius: 8px;
  transition: background var(--transition);
}
.menu-icon:hover {
  background: var(--surface);
}
.menu-icon span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}

/* ========== Main ========== */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px 40px;
  position: relative;
}

main.has-messages {
  justify-content: flex-start;
  padding-top: 12px;
}

/* Hero */
.hero {
  text-align: center;
  margin-bottom: 32px;
  transition: all 0.35s ease;
}
main.has-messages .hero {
  display: none;
}

.hero-title {
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 700;
  letter-spacing: -1.2px;
  line-height: 1.2;
  color: var(--text);
  min-height: 1.3em;
  margin-bottom: 10px;
}

.hero-subtitle {
  font-size: 15px;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: -0.2px;
}

.typing-cursor {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: var(--text);
  margin-inline-start: 3px;
  vertical-align: text-bottom;
  animation: blink 1s step-end infinite;
}
@keyframes blink {
  50% { opacity: 0; }
}

/* Chat Box */
#chat-box {
  width: 100%;
  display: none;
  flex-direction: column;
  gap: 18px;
  margin-bottom: 20px;
  flex: 1;
  max-height: calc(100vh - 300px);
  overflow-y: auto;
  padding: 8px 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
main.has-messages #chat-box {
  display: flex;
}

.msg {
  padding: 14px 18px;
  border-radius: 18px;
  line-height: 1.65;
  font-size: 15px;
  max-width: 88%;
  white-space: pre-wrap;
  word-break: break-word;
  animation: msgIn 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  position: relative;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--bg);
  border-bottom-right-radius: 5px;
}
[dir="rtl"] .user {
  border-bottom-right-radius: 18px;
  border-bottom-left-radius: 5px;
}

.bot {
  align-self: flex-start;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
  box-shadow: var(--shadow-sm);
}
[dir="rtl"] .bot {
  border-bottom-left-radius: 18px;
  border-bottom-right-radius: 5px;
}

.who {
  font-size: 11px;
  font-weight: 700;
  opacity: 0.55;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  letter-spacing: 0.2px;
}

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 2px;
}
.typing-indicator span {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.35s infinite ease-in-out both;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.3s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.15s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

.msg-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.copy-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 11px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all var(--transition);
}
.copy-btn:hover {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  margin-inline-end: 6px;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 12px;
  background: rgba(255,255,255,0.15);
  direction: ltr;
}
.bot .file-chip {
  background: var(--surface);
}

/* Composer */
.composer-card {
  width: 100%;
  background: var(--bg-elevated);
  border: 1.5px solid var(--border);
  border-radius: 28px;
  padding: 14px 18px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
.composer-card:focus-within {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-lg);
}
.composer-card.drag-over {
  border-color: var(--accent);
  border-style: dashed;
  background: color-mix(in srgb, var(--surface) 60%, var(--bg-elevated));
}

.selected-files {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.selected-files:empty { display: none; }

.selected-file-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 5px 11px;
  border-radius: var(--radius-full);
  font-size: 12.5px;
  direction: ltr;
}
.selected-file-item button {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--danger);
  font-weight: bold;
  font-size: 15px;
  margin-inline-start: 2px;
  line-height: 1;
}

textarea#userInput {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  font-size: 15.5px;
  line-height: 1.5;
  color: var(--text);
  background: transparent;
  min-height: 26px;
  max-height: 160px;
  font-family: inherit;
}
textarea#userInput::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

.composer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 2px;
}
.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition);
}
.icon-btn:hover {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}
.icon-btn.recording {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
  animation: pulseRec 1.2s infinite;
}
@keyframes pulseRec {
  50% { transform: scale(1.07); }
}

.model-selector-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: all var(--transition);
}
.model-selector-pill:hover {
  background: var(--surface);
  border-color: var(--border-strong);
}

.btn-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--surface);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: not-allowed;
  transition: all 0.2s ease;
}
.btn-send.active {
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
}
.btn-send.active:hover {
  transform: scale(1.05);
  background: var(--accent-hover);
}

/* Models Nav */
.models-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  padding: 4px;
  border-radius: var(--radius-full);
  margin-top: 18px;
  border: 1px solid var(--border);
}
.model-tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 16px;
  border-radius: var(--radius-full);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  border: none;
  background: transparent;
}
.model-tab:hover {
  color: var(--text-secondary);
}
.model-tab.active {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.status-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 16px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.dl-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 9px 16px;
  background: var(--success);
  color: #fff;
  border-radius: var(--radius-full);
  text-decoration: none;
  font-weight: 700;
  font-size: 13px;
  transition: opacity 0.2s, transform 0.15s;
}
.dl-btn:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

/* Responsive */
@media (max-width: 640px) {
  header { padding: 12px 16px; }
  .hero-title { font-size: 26px; }
  main { padding: 16px 14px 28px; }
  .models-nav { flex-wrap: wrap; justify-content: center; }
  .btn-new-chat span.label { display: none; }
  .brand-text { font-size: 18px; }
}

/* Voice recording and preview */
.voice-preview { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
.voice-preview[hidden] { display: none !important; }
.voice-preview-head { display:flex; align-items:center; justify-content:space-between; gap:10px; margin-bottom:8px; font-size:12px; color:var(--text-secondary); }
.voice-preview audio { display:block; width:100%; max-width:100%; height:38px; }
.voice-discard { border:0; background:transparent; color:var(--danger); cursor:pointer; font:inherit; font-weight:700; }
.voice-recording-status { color:var(--danger); font-size:12px; font-weight:700; }

/* Structured assistant response typography */
.msg-content { line-height: 1.8; overflow-wrap: anywhere; }
.msg-content > :first-child { margin-top: 0; }
.msg-content > :last-child { margin-bottom: 0; }
.msg-content p { margin: 0 0 12px; }
.msg-content h2, .msg-content h3, .msg-content h4, .msg-content h5 { margin: 18px 0 8px; line-height: 1.45; font-weight: 750; }
.msg-content ul, .msg-content ol { margin: 8px 0 14px; padding-inline-start: 24px; }
.msg-content li { margin: 4px 0; padding-inline-start: 3px; }
.msg-content strong { font-weight: 750; }
.msg-content code { padding: 2px 5px; border-radius: 5px; background: rgba(127,127,127,.13); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .92em; }
.msg-content pre { margin: 12px 0; padding: 14px; overflow-x: auto; border-radius: 10px; background: #111827; color: #f3f4f6; direction: ltr; text-align: left; }
.msg-content pre code { padding: 0; background: transparent; color: inherit; white-space: pre; }
.msg-content a { text-decoration: underline; text-underline-offset: 3px; }
.app-icon img { width: 100%; height: 100%; object-fit: contain; display: block; }
.app-icon.icon-placeholder-missing { opacity: .35; }

/* Refined authentication modal */
.auth-overlay{position:fixed;inset:0;z-index:9999;display:grid;place-items:center;padding:20px;background:rgba(8,12,20,.64);backdrop-filter:blur(9px);animation:authFade .18s ease}
.auth-panel{position:relative;width:min(440px,100%);padding:34px 30px 28px;background:var(--bg-elevated,#fff);color:var(--text,#111);border:1px solid var(--border,#e8e8e8);border-radius:26px;box-shadow:0 30px 90px rgba(0,0,0,.24);animation:authRise .24s ease}
.auth-close{position:absolute;top:14px;inset-inline-end:14px;border:0;background:var(--surface,#f4f4f5);color:var(--text-secondary,#555);width:34px;height:34px;border-radius:50%;font-size:23px;line-height:1;cursor:pointer;display:grid;place-items:center;transition:.18s}
.auth-close:hover{background:var(--surface-hover,#ececec);color:var(--text,#111)}
.auth-brand{display:flex;align-items:center;gap:10px;justify-content:center;font-weight:800;font-size:19px;margin-bottom:24px}
.auth-mark{width:34px;height:34px;border-radius:11px;background:linear-gradient(135deg,#111827,#374151);color:#fff;display:grid;place-items:center;font-weight:900}
.auth-panel h2{text-align:center;font-size:23px;letter-spacing:-.5px;margin:0 0 8px}
.auth-subtitle{text-align:center;color:var(--text-muted,#777);font-size:13px;line-height:1.7;margin-bottom:23px}
.auth-google,.auth-submit{width:100%;height:48px;border-radius:13px;display:flex;align-items:center;justify-content:center;gap:12px;font-weight:700;font-size:14px;cursor:pointer;transition:.18s}
.auth-google{border:1px solid var(--border-strong,#d5d5d5);background:var(--bg-elevated,#fff);color:var(--text,#111)}
.auth-google:hover{background:var(--surface,#f5f5f5);transform:translateY(-1px)}
.google-mark{font-family:Arial,sans-serif;font-size:19px;font-weight:800;background:conic-gradient(from -45deg,#4285f4 0 25%,#34a853 25% 50%,#fbbc05 50% 75%,#ea4335 75%);background-clip:text;-webkit-background-clip:text;color:transparent}
.auth-divider{display:flex;align-items:center;gap:12px;color:var(--text-muted,#888);font-size:12px;margin:22px 0}
.auth-divider:before,.auth-divider:after{content:"";height:1px;background:var(--border,#e5e5e5);flex:1}
.auth-panel form label{display:block;font-size:12px;font-weight:700;margin:12px 0 7px;color:var(--text-secondary,#555)}
.auth-panel form input{width:100%;height:46px;border:1px solid var(--border-strong,#d4d4d4);border-radius:12px;background:var(--bg-elevated,#fff);color:var(--text,#111);padding:0 13px;outline:none;transition:.18s}
.auth-panel form input:focus{border-color:#64748b;box-shadow:0 0 0 3px rgba(100,116,139,.13)}
.auth-submit{margin-top:14px;background:var(--accent,#111);color:var(--bg,#fff);border:0}
.auth-submit:hover{filter:brightness(1.15);transform:translateY(-1px)}
.auth-error{min-height:18px;color:#dc2626;font-size:12px;margin:8px 0 0;line-height:1.5}
.auth-forgot,.auth-switch{display:block;margin:13px auto 0;border:0;background:transparent;color:var(--text-secondary,#555);font-size:12px;cursor:pointer;padding:6px}
.auth-forgot:hover,.auth-switch:hover{text-decoration:underline;color:var(--text,#111)}
.auth-switch{color:var(--text,#111);font-weight:700;margin-top:10px}
@keyframes authFade{from{opacity:0}to{opacity:1}}
@keyframes authRise{from{opacity:0;transform:translateY(12px) scale(.985)}to{opacity:1;transform:translateY(0) scale(1)}}
@media(max-width:480px){.auth-panel{padding:30px 22px 24px;border-radius:22px}.auth-panel h2{font-size:21px}}
