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

:root {
  --bg: #141210;
  --bg-soft: #1a1715;
  --bg-elevated: #1c1815;
  --bg-bubble: #211c18;
  --text: #f5f0e8;
  --text-dim: #b8ad9d;
  --text-muted: #7a6f60;
  --gold: #e0a94a;
  --gold-bright: #f4c76b;
  --copper: #c4813a;
  --border: rgba(224, 169, 74, 0.12);
  --border-hover: rgba(224, 169, 74, 0.35);
  --font-ar: 'Cairo', system-ui, -apple-system, sans-serif;
  --font-serif: 'Cormorant Garamond', serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius: 14px;
  --trans: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html { height: 100%; }
body { height: 100dvh; height: 100vh; }

body {
  font-family: var(--font-ar);
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  overflow: hidden;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; border: none; background: none; color: inherit; cursor: pointer; }
textarea { font-family: inherit; }

::selection { background: rgba(224, 169, 74, 0.35); color: #fff; }

.bg-aurora { position: fixed; inset: 0; z-index: -3; overflow: hidden; pointer-events: none; }
.aurora { position: absolute; border-radius: 50%; filter: blur(120px); opacity: 0.22; }
.aurora-1 { width: 600px; height: 600px; background: radial-gradient(circle, var(--gold) 0%, transparent 70%); top: -20%; right: -15%; animation: float1 22s ease-in-out infinite; }
.aurora-2 { width: 500px; height: 500px; background: radial-gradient(circle, var(--copper) 0%, transparent 70%); bottom: -20%; left: -15%; animation: float2 26s ease-in-out infinite; }
@keyframes float1 { 0%, 100% { transform: translate(0, 0) scale(1); } 50% { transform: translate(-70px, 70px) scale(1.15); } }
@keyframes float2 { 0%, 100% { transform: translate(0, 0) scale(1); } 50% { transform: translate(90px, -90px) scale(1.2); } }

.bg-grid { position: fixed; inset: 0; z-index: -2; background-image: linear-gradient(rgba(224, 169, 74, 0.03) 1px, transparent 1px), linear-gradient(90deg, rgba(224, 169, 74, 0.03) 1px, transparent 1px); background-size: 80px 80px; pointer-events: none; }

.bg-noise { position: fixed; inset: 0; z-index: -1; pointer-events: none; opacity: 0.05; background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"); }

.bg-vignette { position: fixed; inset: 0; z-index: -1; pointer-events: none; background: radial-gradient(ellipse at center, transparent 40%, rgba(10, 8, 6, 0.6) 100%); }

.chat-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; background: rgba(20, 18, 16, 0.75); backdrop-filter: blur(24px) saturate(150%); -webkit-backdrop-filter: blur(24px) saturate(150%); border-bottom: 1px solid var(--border); position: relative; z-index: 10; }

.back-btn, .icon-btn { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; color: var(--text-dim); border: 1px solid var(--border); background: rgba(224, 169, 74, 0.02); transition: all var(--trans); }
.back-btn:hover, .icon-btn:hover { color: var(--gold); border-color: var(--gold); background: rgba(224, 169, 74, 0.08); }

.chat-brand { display: flex; align-items: center; gap: 8px; position: relative; }
.brand-glow { font-family: var(--font-serif); font-size: 22px; font-weight: 600; font-style: italic; letter-spacing: 0.02em; color: var(--gold); text-shadow: 0 0 24px rgba(224, 169, 74, 0.4); }
.brand-ai { font-family: var(--font-mono); font-size: 13px; font-weight: 700; padding: 3px 8px; border-radius: 6px; background: linear-gradient(135deg, var(--gold), var(--copper)); color: var(--bg); letter-spacing: 0.05em; }
.brand-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--gold-bright); box-shadow: 0 0 10px var(--gold-bright); animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.4; transform: scale(1.4); } }

.model-bar { display: flex; align-items: center; gap: 10px; padding: 10px 20px; background: rgba(20, 18, 16, 0.5); border-bottom: 1px solid var(--border); overflow-x: auto; }
.model-label { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.model-select { font-family: var(--font-ar); font-size: 13px; color: var(--text); background: rgba(224, 169, 74, 0.04); border: 1px solid var(--border); border-radius: 10px; padding: 8px 14px; cursor: pointer; outline: none; transition: all var(--trans); min-width: 220px; }
.model-select:hover, .model-select:focus { border-color: var(--gold); background: rgba(224, 169, 74, 0.08); }
.model-select option { background: var(--bg-elevated); color: var(--text); }

.chat-container { position: absolute; top: 118px; bottom: 118px; right: 0; left: 0; overflow-y: auto; overflow-x: hidden; scroll-behavior: smooth; }
.chat-container::-webkit-scrollbar { width: 8px; }
.chat-container::-webkit-scrollbar-track { background: transparent; }
.chat-container::-webkit-scrollbar-thumb { background: rgba(224, 169, 74, 0.2); border-radius: 4px; }

.messages { max-width: 860px; margin: 0 auto; padding: 32px 20px; display: flex; flex-direction: column; gap: 24px; }

.welcome { text-align: center; padding: 40px 20px; animation: fadeIn 0.6s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.welcome-logo { display: inline-flex; align-items: center; justify-content: center; width: 80px; height: 80px; border-radius: 22px; background: linear-gradient(135deg, var(--gold), var(--copper)); box-shadow: 0 20px 60px rgba(224, 169, 74, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.2); margin-bottom: 28px; animation: logoFloat 4s ease-in-out infinite; }
@keyframes logoFloat { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.logo-mark { font-family: var(--font-mono); font-size: 32px; font-weight: 800; color: var(--bg); letter-spacing: -0.02em; }
.welcome-title { font-family: var(--font-serif); font-size: clamp(28px, 5vw, 40px); font-weight: 500; font-style: italic; margin-bottom: 10px; background: linear-gradient(135deg, var(--gold-bright), var(--gold), var(--copper)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.welcome-sub { font-size: 15px; color: var(--text-dim); margin-bottom: 40px; }
.suggestions { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; max-width: 640px; margin: 0 auto; }
.suggestion { display: flex; align-items: center; gap: 10px; padding: 14px 18px; background: rgba(224, 169, 74, 0.03); border: 1px solid var(--border); border-radius: 12px; color: var(--text-dim); font-size: 13px; font-weight: 500; text-align: right; transition: all var(--trans); }
.suggestion svg { flex-shrink: 0; color: var(--gold); }
.suggestion:hover { background: rgba(224, 169, 74, 0.08); border-color: var(--gold); color: var(--text); transform: translateY(-2px); }

.message { display: flex; gap: 14px; animation: messageIn 0.4s ease; max-width: 100%; }
@keyframes messageIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
.message.user { flex-direction: row-reverse; }
.msg-avatar { width: 36px; height: 36px; flex-shrink: 0; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-family: var(--font-mono); font-size: 13px; font-weight: 700; }
.message.user .msg-avatar { background: rgba(224, 169, 74, 0.15); color: var(--gold); border: 1px solid rgba(224, 169, 74, 0.3); }
.message.assistant .msg-avatar { background: linear-gradient(135deg, var(--gold), var(--copper)); color: var(--bg); }
.msg-body { flex: 1; min-width: 0; max-width: calc(100% - 60px); }
.message.user .msg-body { display: flex; flex-direction: column; align-items: flex-start; }
.msg-name { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; letter-spacing: 0.02em; }
.message.user .msg-name { color: var(--gold); }
.msg-content { padding: 14px 18px; border-radius: 16px; font-size: 15px; line-height: 1.75; word-wrap: break-word; overflow-wrap: break-word; }
.message.user .msg-content { background: linear-gradient(135deg, rgba(224, 169, 74, 0.15), rgba(196, 129, 58, 0.08)); border: 1px solid rgba(224, 169, 74, 0.25); color: var(--text); border-top-right-radius: 4px; }
.message.assistant .msg-content { background: rgba(28, 24, 21, 0.7); border: 1px solid var(--border); color: var(--text); border-top-left-radius: 4px; }
.msg-content p { margin-bottom: 10px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content strong { color: var(--gold); font-weight: 700; }
.msg-content em { color: var(--gold-bright); font-style: italic; }
.msg-content code:not(pre code) { font-family: var(--font-mono); font-size: 13px; padding: 2px 6px; border-radius: 4px; background: rgba(224, 169, 74, 0.12); color: var(--gold-bright); direction: ltr; unicode-bidi: embed; }
.msg-content a { color: var(--gold); text-decoration: underline; text-decoration-color: rgba(224, 169, 74, 0.4); text-underline-offset: 3px; }
.msg-content a:hover { color: var(--gold-bright); }
.msg-content ul, .msg-content ol { padding-right: 22px; margin: 10px 0; }
.msg-content li { margin-bottom: 6px; }
.msg-content blockquote { border-right: 3px solid var(--gold); padding-right: 14px; margin: 10px 0; color: var(--text-dim); font-style: italic; }

.code-block { margin: 14px 0; border-radius: 12px; overflow: hidden; border: 1px solid var(--border); background: #0d0b09; direction: ltr; text-align: left; }
.code-header { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; background: rgba(224, 169, 74, 0.06); border-bottom: 1px solid var(--border); }
.code-lang { font-family: var(--font-mono); font-size: 11px; font-weight: 600; color: var(--gold); text-transform: uppercase; letter-spacing: 0.1em; }
.code-copy { display: flex; align-items: center; gap: 6px; font-family: var(--font-ar); font-size: 11px; font-weight: 600; color: var(--text-muted); padding: 5px 10px; border-radius: 6px; transition: all var(--trans); }
.code-copy:hover { color: var(--gold); background: rgba(224, 169, 74, 0.1); }
.code-copy.copied { color: #10b981; }
.code-copy svg { width: 13px; height: 13px; }
.code-block pre { margin: 0; padding: 16px 18px; overflow-x: auto; font-family: var(--font-mono); font-size: 13px; line-height: 1.65; direction: ltr; text-align: left; }
.code-block pre::-webkit-scrollbar { height: 6px; }
.code-block pre::-webkit-scrollbar-thumb { background: rgba(224, 169, 74, 0.2); border-radius: 3px; }
.code-block code { font-family: var(--font-mono); background: transparent !important; padding: 0 !important; color: #e8dcc7; }
.hljs { background: transparent !important; color: #e8dcc7; }
.hljs-keyword { color: #e0a94a; }
.hljs-string { color: #b8d4a0; }
.hljs-number { color: #e89a5a; }
.hljs-comment { color: #6b5d4a; font-style: italic; }
.hljs-function { color: #f4c76b; }
.hljs-variable { color: #d4c4b0; }
.hljs-built_in { color: #c4813a; }

.typing-indicator { display: flex; gap: 5px; padding: 14px 18px; background: rgba(28, 24, 21, 0.7); border: 1px solid var(--border); border-radius: 16px; border-top-left-radius: 4px; width: fit-content; }
.typing-indicator span { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); animation: typing 1.4s ease-in-out infinite; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%, 60%, 100% { opacity: 0.3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-6px); } }

.input-area { position: absolute; bottom: 0; right: 0; left: 0; padding: 16px 20px 12px; background: linear-gradient(180deg, transparent, rgba(20, 18, 16, 0.95) 30%); z-index: 5; }
.input-wrapper { max-width: 860px; margin: 0 auto; display: flex; align-items: flex-end; gap: 10px; background: rgba(28, 24, 21, 0.85); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border: 1px solid var(--border); border-radius: 20px; padding: 8px 8px 8px 18px; transition: all var(--trans); box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3); }
.input-wrapper:focus-within { border-color: var(--gold); box-shadow: 0 8px 32px rgba(224, 169, 74, 0.15); }
#input { flex: 1; resize: none; border: none; outline: none; background: transparent; color: var(--text); font-size: 16px; line-height: 1.6; padding: 8px 0; max-height: 160px; font-family: var(--font-ar); }
#input::placeholder { color: var(--text-muted); }
#input::-webkit-scrollbar { width: 4px; }
#input::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.send-btn { width: 44px; height: 44px; flex-shrink: 0; border-radius: 14px; background: linear-gradient(135deg, var(--gold), var(--copper)); color: var(--bg); display: flex; align-items: center; justify-content: center; transition: all var(--trans); box-shadow: 0 4px 16px rgba(224, 169, 74, 0.3); }
.send-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(224, 169, 74, 0.5); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.send-btn.loading svg { animation: spin 1s linear infinite; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.footer-note { text-align: center; font-size: 11px; color: var(--text-muted); margin-top: 8px; max-width: 860px; margin-right: auto; margin-left: auto; }

@media (max-width: 768px) {
  .chat-header { padding: 12px 16px; }
  .model-bar { padding: 8px 16px; }
  .model-select { min-width: 180px; font-size: 12px; }
  
  .messages { padding: 20px 14px; gap: 18px; }
  .welcome { padding: 20px 10px; }
  .welcome-logo { width: 68px; height: 68px; }
  .logo-mark { font-size: 26px; }
  .suggestions { grid-template-columns: 1fr; }
  .msg-avatar { width: 32px; height: 32px; font-size: 11px; }
  .msg-body { max-width: calc(100% - 50px); }
  .msg-content { padding: 12px 14px; font-size: 14px; }
  .input-area { padding: 12px 14px 8px; }
  .code-block pre { padding: 12px 14px; font-size: 12px; }
}

/* ============ IMAGE UPLOAD ============ */
.image-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 14px;
  background: rgba(224, 169, 74, 0.08);
  border: 1px solid var(--border);
  color: var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--trans);
}

.image-btn:hover {
  background: rgba(224, 169, 74, 0.15);
  border-color: var(--gold);
  transform: translateY(-2px);
}

.image-btn.has-image {
  background: rgba(224, 169, 74, 0.25);
  border-color: var(--gold);
}

.image-preview {
  max-width: 860px;
  margin: 0 auto 10px;
  display: none;
  gap: 10px;
  flex-wrap: wrap;
}

.image-preview.active {
  display: flex;
}

.preview-item {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--gold);
  animation: fadeIn 0.3s ease;
}

.preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.8);
  color: var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  border: 1px solid var(--gold);
  transition: all 0.2s ease;
}

.preview-remove:hover {
  background: var(--gold);
  color: var(--bg);
}

.msg-image {
  max-width: 300px;
  max-height: 300px;
  border-radius: 12px;
  margin-bottom: 8px;
  display: block;
  border: 1px solid rgba(224, 169, 74, 0.3);
  cursor: pointer;
  transition: transform var(--trans);
}

.msg-image:hover {
  transform: scale(1.02);
}

@media (max-width: 768px) {
  .image-btn {
    width: 40px;
    height: 40px;
  }
  .preview-item {
    width: 64px;
    height: 64px;
  }
  .msg-image {
    max-width: 220px;
    max-height: 220px;
  }
}

/* ============ MOBILE KEYBOARD FIX (OVERRIDE) ============ */
html {
  height: 100% !important;
}

body {
  display: flex !important;
  flex-direction: column !important;
  height: 100dvh !important;
  min-height: 100dvh !important;
  overflow: hidden !important;
}

.chat-header,
.model-bar {
  flex-shrink: 0 !important;
}

.chat-container {
  position: relative !important;
  top: auto !important;
  bottom: auto !important;
  right: auto !important;
  left: auto !important;
  flex: 1 1 0 !important;
  min-height: 0 !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  -webkit-overflow-scrolling: touch !important;
}

.input-area {
  position: relative !important;
  bottom: auto !important;
  right: auto !important;
  left: auto !important;
  flex-shrink: 0 !important;
}

#input {
  font-size: 16px !important;
}
