/* ===== Shooq — Meta-AI-inspired theme ===== */
:root {
  --grad: linear-gradient(135deg, #0866FF 0%, #A033FF 50%, #FF4FA3 100%);
  --grad-ring: conic-gradient(from 0deg, #0866FF, #00C6FF, #A033FF, #FF4FA3, #FF8A3D, #0866FF);
  --radius: 22px;
  --font: "Tajawal", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}
[data-theme="dark"] {
  --bg: #0b0b10;
  --bg-2: #141419;
  --surface: #1c1c24;
  --surface-2: #26262f;
  --border: #2c2c36;
  --text: #f2f2f7;
  --muted: #9a9aab;
  --user-bubble: #0866FF;
  --user-text: #fff;
  --bot-bubble: transparent;
  --code-bg: #101016;
}
[data-theme="light"] {
  --bg: #ffffff;
  --bg-2: #f5f6fa;
  --surface: #f0f2f5;
  --surface-2: #e4e6eb;
  --border: #e1e3ea;
  --text: #0b0b10;
  --muted: #65676b;
  --user-bubble: #0866FF;
  --user-text: #fff;
  --bot-bubble: transparent;
  --code-bg: #f3f4f8;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  transition: background .25s, color .25s;
}
html[lang="en"] body { font-family: "Inter", "Tajawal", system-ui, sans-serif; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
a { color: #4d9bff; }

.app { display: flex; flex-direction: column; height: 100dvh; max-width: 860px; margin: 0 auto; }

/* ===== Top bar ===== */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(14px);
}
.topbar-title { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.title-name { font-weight: 800; font-size: 17px; }
.title-status { font-size: 12px; color: var(--muted); }
.title-status.typing { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; color: var(--text);
  transition: background .15s, transform .1s;
}
.icon-btn:hover { background: var(--surface); }
.icon-btn:active { transform: scale(.92); }
.icon-btn.soft { color: var(--muted); }
.icon-btn.recording { color: #fff; background: #e0245e; animation: pulse 1.2s infinite; }

.pill-btn {
  padding: 7px 12px; border-radius: 999px; background: var(--surface);
  font-weight: 700; font-size: 13px; white-space: nowrap;
}
.pill-btn:hover { background: var(--surface-2); }

.ring-mini {
  width: 38px; height: 38px; border-radius: 50%; padding: 2px;
  background: var(--grad-ring); display: grid; place-items: center; flex: none;
}
.ring-mini img { width: 100%; height: 100%; border-radius: 50%; border: 2px solid var(--bg); }

/* ===== Chat area ===== */
.chat { flex: 1; overflow-y: auto; padding: 8px 16px 20px; scroll-behavior: smooth; }
.chat::-webkit-scrollbar { width: 6px; }
.chat::-webkit-scrollbar-thumb { background: var(--surface-2); border-radius: 6px; }

.welcome { text-align: center; padding: 6vh 0 10px; animation: fadeUp .5s ease; }
.welcome.hidden { display: none; }
.orb { position: relative; width: 132px; height: 132px; margin: 0 auto 22px; }
.orb-ring {
  position: absolute; inset: -6px; border-radius: 50%;
  background: var(--grad-ring); animation: spin 6s linear infinite;
  filter: blur(.3px);
}
.orb-ring::after { content: ""; position: absolute; inset: 5px; border-radius: 50%; background: var(--bg); }
.orb-ring.big { inset: -10px; }
.orb-img { position: relative; width: 100%; height: 100%; border-radius: 50%; z-index: 1; box-shadow: 0 10px 40px rgba(160, 51, 255, .35); }
.welcome-title {
  font-size: clamp(26px, 5vw, 36px); margin: 0 0 8px; font-weight: 800;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.welcome-sub { color: var(--muted); margin: 0 auto 26px; max-width: 460px; line-height: 1.7; }

.suggestions { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; text-align: start; }
.sugg {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  padding: 14px; display: flex; flex-direction: column; gap: 6px; text-align: start;
  transition: transform .15s, background .15s, border-color .15s;
}
.sugg:hover { transform: translateY(-2px); border-color: #A033FF; }
.sugg .emo { font-size: 22px; }
.sugg b { font-size: 14px; }
.sugg span { font-size: 12.5px; color: var(--muted); line-height: 1.5; }

/* ===== Messages ===== */
.messages { display: flex; flex-direction: column; gap: 18px; padding-top: 8px; }
.msg { display: flex; gap: 10px; align-items: flex-start; animation: fadeUp .25s ease; }
.msg.user { justify-content: flex-end; }
.msg .avatar { width: 30px; height: 30px; border-radius: 50%; flex: none; padding: 1.5px; background: var(--grad-ring); }
.msg .avatar img { width: 100%; height: 100%; border-radius: 50%; display: block; }
.bubble { max-width: 82%; line-height: 1.8; font-size: 15.5px; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user .bubble {
  background: var(--user-bubble); color: var(--user-text);
  padding: 10px 16px; border-radius: 22px; white-space: pre-wrap;
}
.msg.user .bubble img { max-width: 220px; border-radius: 14px; display: block; margin-bottom: 6px; }
.msg.bot .bubble { background: var(--bot-bubble); padding: 2px 0; flex: 1; max-width: 100%; }
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { margin: 14px 0 8px; line-height: 1.4; }
.bubble h1 { font-size: 20px; } .bubble h2 { font-size: 18px; } .bubble h3, .bubble h4 { font-size: 16px; }
.bubble ul, .bubble ol { margin: 6px 0 10px; padding-inline-start: 22px; }
.bubble li { margin: 4px 0; }
.bubble strong { font-weight: 800; }
.bubble blockquote { margin: 8px 0; padding: 6px 14px; border-inline-start: 4px solid #A033FF; background: var(--surface); border-radius: 10px; }
.bubble code { background: var(--code-bg); padding: 2px 6px; border-radius: 6px; font-size: 13.5px; direction: ltr; unicode-bidi: embed; }
.bubble pre { background: var(--code-bg); padding: 12px; border-radius: 12px; overflow-x: auto; direction: ltr; text-align: left; }
.bubble pre code { padding: 0; background: none; }
.bubble hr { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }
.bubble table { border-collapse: collapse; margin: 8px 0; font-size: 14px; display: block; overflow-x: auto; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 6px 10px; }
.bubble th { background: var(--surface); }

.msg-actions { display: flex; gap: 2px; margin-top: 6px; opacity: .75; }
.msg-actions button { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); }
.msg-actions button:hover { background: var(--surface); color: var(--text); }
.msg-actions button.active { color: #A033FF; }
.msg-actions svg { width: 17px; height: 17px; }

.err { color: #ff6b81; background: rgba(255, 80, 110, .1); padding: 10px 14px; border-radius: 14px; }

/* typing dots (Meta style shimmer) */
.typing-dots { display: inline-flex; gap: 5px; padding: 10px 0; }
.typing-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--grad); animation: bounce 1.2s infinite; }
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }

/* ===== Composer ===== */
.composer-wrap { padding: 8px 14px; padding-bottom: max(10px, env(safe-area-inset-bottom)); background: var(--bg); }
.composer {
  display: flex; align-items: flex-end; gap: 4px;
  background: var(--surface); border-radius: 28px; padding: 6px;
  border: 1.5px solid transparent;
  transition: border-color .2s, box-shadow .2s;
}
.composer:focus-within {
  border-color: transparent;
  background: linear-gradient(var(--surface), var(--surface)) padding-box, var(--grad) border-box;
  box-shadow: 0 6px 28px rgba(160, 51, 255, .18);
}
.composer textarea {
  flex: 1; resize: none; border: 0; outline: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 16px; line-height: 1.5; padding: 9px 6px; max-height: 160px;
}
.composer textarea::placeholder { color: var(--muted); }
.send-btn {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: var(--grad); color: #fff; flex: none; transition: transform .1s, opacity .2s;
}
.send-btn:disabled { opacity: .35; cursor: default; }
.send-btn:active { transform: scale(.9); }
.send-btn.stop svg { display: none; }
.send-btn.stop::after { content: ""; width: 12px; height: 12px; border-radius: 3px; background: #fff; }

.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.disclaimer { font-size: 11.5px; color: var(--muted); }
.voice-mode-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 700;
  background: var(--surface); border: 1px solid var(--border);
}
.voice-mode-btn:hover { border-color: #A033FF; }
.wave { display: inline-flex; gap: 2px; align-items: center; height: 14px; }
.wave i { width: 3px; border-radius: 2px; background: var(--grad); animation: wave 1s infinite ease-in-out; }
.wave i:nth-child(1) { height: 6px; } .wave i:nth-child(2) { height: 12px; animation-delay: .1s; }
.wave i:nth-child(3) { height: 9px; animation-delay: .2s; } .wave i:nth-child(4) { height: 5px; animation-delay: .3s; }

.attach-preview { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.attach-preview img { height: 64px; border-radius: 12px; }
.attach-preview button { background: var(--surface-2); border-radius: 50%; width: 26px; height: 26px; display: grid; place-items: center; }
.attach-preview svg { width: 14px; height: 14px; }

/* ===== Drawer ===== */
.drawer {
  position: fixed; top: 0; bottom: 0; inset-inline-start: 0; width: min(320px, 86vw);
  background: var(--bg-2); z-index: 30; display: flex; flex-direction: column; padding: 14px;
  transform: translateX(100%); visibility: hidden;
  transition: transform .28s ease, visibility 0s linear .28s;
  border-inline-end: 1px solid var(--border);
}
.drawer.open { visibility: visible; transition: transform .28s ease; }
html[dir="ltr"] .drawer { transform: translateX(-100%); }
.drawer.open { transform: translateX(0) !important; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 25; opacity: 0; pointer-events: none; transition: opacity .25s; }
.scrim.show { opacity: 1; pointer-events: auto; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; }
.brand-avatar { width: 34px; height: 34px; border-radius: 50%; }
.new-chat-btn {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  padding: 12px; border-radius: 16px; background: var(--grad); color: #fff; font-weight: 700;
}
.drawer-label { font-size: 12px; color: var(--muted); margin: 18px 4px 8px; font-weight: 700; }
.history-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.history-list li {
  display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-radius: 12px;
  cursor: pointer; font-size: 14px;
}
.history-list li:hover, .history-list li.active { background: var(--surface); }
.history-list li .t { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-list li button { opacity: 0; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; color: var(--muted); }
.history-list li:hover button { opacity: 1; }
.history-list li button svg { width: 15px; height: 15px; }
.history-empty { color: var(--muted); font-size: 13px; padding: 10px; }
.drawer-foot { border-top: 1px solid var(--border); padding-top: 10px; }
.drawer-link { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 12px; width: 100%; }
.drawer-link:hover { background: var(--surface); }

/* ===== Modal ===== */
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 16px; animation: fade .2s; }
.modal[hidden] { display: none; }
.modal-card {
  width: min(480px, 100%); max-height: 92dvh; overflow-y: auto;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 24px; padding: 20px;
  animation: fadeUp .25s ease;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal-head h2 { margin: 0; font-size: 20px; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; font-weight: 700; font-size: 14px; }
.field small { font-weight: 400; color: var(--muted); }
.field[hidden] { display: none; }
.field input, .field select {
  width: 100%; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500; outline: none;
}
.field input:focus, .field select:focus { border-color: #A033FF; }
.key-row { display: flex; gap: 8px; align-items: center; }
#apiKeyInput, .ltr-input { direction: ltr; text-align: left; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 16px 0; font-weight: 700; font-size: 14px; cursor: pointer; }
.switch-row input { display: none; }
.switch { width: 46px; height: 28px; border-radius: 999px; background: var(--surface-2); position: relative; transition: background .2s; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch-row input:checked + .switch { background: #0866FF; }
.switch-row input:checked + .switch::after { transform: translateX(-18px); }
html[dir="ltr"] .switch-row input:checked + .switch::after { transform: translateX(18px); }
.modal-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 20px; }
.primary-btn { padding: 11px 26px; border-radius: 14px; background: var(--grad); color: #fff; font-weight: 800; }
.danger-btn { padding: 11px 16px; border-radius: 14px; color: #ff6b81; background: rgba(255,80,110,.1); font-weight: 700; font-size: 13px; }

.conn-btn { align-self: flex-start; margin-top: 4px; }
.conn-result { font-weight: 500; font-size: 13px; line-height: 1.7; padding: 10px 12px; border-radius: 12px; background: var(--surface); white-space: pre-wrap; word-break: break-word; }
.conn-result.ok { color: #2ecc71; background: rgba(46, 204, 113, .1); }
.conn-result.bad { color: #ff6b81; background: rgba(255, 80, 110, .1); }
.avatar-row { display: flex; gap: 14px; align-items: center; }
.avatar-preview { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; flex: none; padding: 3px; background: var(--grad-ring); }
.avatar-ctrls { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 0; }
.primary-btn.small { padding: 9px 14px; font-size: 13px; flex: 1; }
.primary-btn:disabled { opacity: .6; cursor: wait; }
.avatar-preview.loading { animation: spin 1.2s linear infinite; }
img.shooq-av { object-fit: cover; }

/* ===== Voice overlay ===== */
.voice-overlay {
  position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 26px;
  background: radial-gradient(circle at 50% 40%, #1d1340 0%, #0b0b10 70%); color: #fff; padding: 24px; text-align: center;
}
.voice-overlay[hidden] { display: none; }
.vo-orb { position: relative; width: 190px; height: 190px; transition: transform .3s; }
.vo-orb img { position: relative; z-index: 1; width: 100%; height: 100%; border-radius: 50%; }
.vo-orb .orb-ring::after { background: #120d26; }
.vo-orb.listening { animation: breathe 1.6s infinite ease-in-out; }
.vo-orb.speaking .orb-ring { animation-duration: 1.4s; inset: -16px; filter: blur(2px); }
.vo-orb.thinking .orb-ring { animation-duration: 2.5s; opacity: .7; }
.vo-state { font-size: 22px; font-weight: 800; }
.vo-text { max-width: 560px; color: #c9c9d9; line-height: 1.8; min-height: 60px; max-height: 30vh; overflow-y: auto; }
.vo-close { width: 64px; height: 64px; border-radius: 50%; background: #e0245e; display: grid; place-items: center; color: #fff; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 110px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--surface-2); color: var(--text); padding: 10px 18px; border-radius: 999px; font-size: 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,.3); animation: fadeUp .2s;
}

/* ===== Animations ===== */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-6px); opacity: 1; } }
@keyframes wave { 0%, 100% { transform: scaleY(.5); } 50% { transform: scaleY(1.2); } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(224,36,94,.6); } 100% { box-shadow: 0 0 0 14px rgba(224,36,94,0); } }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }

@media (max-width: 560px) {
  .suggestions { grid-template-columns: 1fr 1fr; }
  .sugg span { display: none; }
  .bubble { font-size: 15px; }
  .disclaimer { width: 100%; text-align: center; }
  .composer-row { justify-content: center; }
}
