/* ============================================================
   بحث المنيو — premium menu-search UI
   Pattern: marketplace/directory · culinary warmth · dark+light
   ============================================================ */

:root {
  /* dark (default) */
  --bg: #0b0e13;
  --bg-soft: #11151d;
  --panel: #131820;
  --panel-2: #1a212c;
  --sidebar: #0d1118;
  --bubble-bot: #161c26;
  --grad-accent: linear-gradient(135deg, #fbbf24 0%, #f97316 100%);
  --grad-accent-soft: linear-gradient(135deg, rgba(251, 191, 36, 0.16), rgba(249, 115, 22, 0.16));
  --text: #f0f3f8;
  --muted: #9aa6b6;
  --faint: #6b7686;
  --accent: #f8a92b;
  --accent-ink: #1c1206;
  --accent-soft: rgba(248, 169, 43, 0.13);
  --border: #232c3a;
  --border-soft: #1b222d;
  --link: #ffc06a;
  --ok: #34d399;
  --danger: #f76d6d;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 8px 30px rgba(249, 115, 22, 0.18);
  --radius: 20px;
  --sidebar-w: 270px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa;
    --bg-soft: #ffffff;
    --panel: #ffffff;
    --panel-2: #f2f5f9;
    --sidebar: #fafbfd;
    --bubble-bot: #ffffff;
    --text: #141b26;
    --muted: #5d6b7e;
    --faint: #93a0b2;
    --accent: #e8800f;
    --accent-ink: #ffffff;
    --accent-soft: rgba(232, 128, 15, 0.1);
    --border: #e4e8ef;
    --border-soft: #eef1f6;
    --link: #c2600a;
    --shadow-sm: 0 2px 8px rgba(20, 27, 38, 0.06);
    --shadow: 0 18px 44px rgba(20, 27, 38, 0.12);
    --shadow-glow: 0 10px 30px rgba(232, 128, 15, 0.16);
  }
}

* { box-sizing: border-box; }
::selection { background: var(--accent-soft); }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Cairo', system-ui, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.app { display: flex; height: 100dvh; overflow: hidden; }

a { color: var(--link); }

/* ============ PIN gate ============ */
.gate {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 20px;
  background:
    radial-gradient(900px 520px at 75% -10%, var(--accent-soft), transparent 62%),
    radial-gradient(700px 400px at 0% 110%, var(--accent-soft), transparent 60%),
    var(--bg);
}
.gate[hidden] { display: none; }
.gate-card {
  width: min(370px, 100%); text-align: center;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 24px; padding: 34px 26px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 9px;
  animation: pop 0.35s cubic-bezier(0.34, 1.3, 0.6, 1) both;
}
.gate-logo {
  width: 64px; height: 64px; margin: 0 auto 8px; color: var(--accent);
  display: grid; place-items: center; border-radius: 18px;
  background: var(--accent-soft); border: 1px solid var(--border);
}
.gate-card h2 { margin: 0; font-size: 20px; font-weight: 800; }
.gate-card p { margin: 0 0 10px; color: var(--muted); font-size: 14px; }
.pin-input {
  font-family: inherit; font-size: 24px; text-align: center; letter-spacing: 10px;
  background: var(--bg-soft); color: var(--text);
  border: 1px solid var(--border); border-radius: 14px; padding: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.pin-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.gate-btn {
  font-family: inherit; font-size: 15px; font-weight: 800; color: var(--accent-ink);
  background: var(--grad-accent); border: none; border-radius: 14px; padding: 13px; cursor: pointer;
  box-shadow: var(--shadow-glow); transition: transform 0.14s, filter 0.14s;
}
.gate-btn:hover { transform: translateY(-2px); filter: brightness(1.05); }
.gate-btn:active { transform: translateY(0); }
.gate-btn:disabled { opacity: 0.5; cursor: default; transform: none; box-shadow: none; }
.gate-err { color: var(--danger); font-size: 13px; min-height: 17px; font-weight: 600; }

/* ============ Sidebar ============ */
.sidebar {
  width: var(--sidebar-w); flex: none;
  background: var(--sidebar); border-inline-end: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 30;
}
.sidebar-head { padding: 18px 14px 12px; }
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 16px; padding: 0 4px;
}
.sidebar-brand .logo {
  width: 36px; height: 36px; flex: none; color: var(--accent);
  display: grid; place-items: center; border-radius: 11px;
  background: var(--accent-soft); border: 1px solid var(--border);
}
.wordmark {
  font-family: 'Lalezar', 'Cairo', sans-serif; font-size: 22px; line-height: 1;
  background: var(--grad-accent); -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; padding-top: 3px;
}
.new-chat {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px;
  font-family: inherit; font-size: 14px; font-weight: 700; color: var(--accent-ink);
  background: var(--grad-accent); border: none; border-radius: 13px; padding: 12px; cursor: pointer;
  box-shadow: var(--shadow-glow); transition: transform 0.14s, filter 0.14s;
}
.new-chat:hover { transform: translateY(-2px); filter: brightness(1.05); }
.new-chat:active { transform: translateY(0); }

.chat-list { flex: 1; overflow-y: auto; padding: 8px 10px; display: flex; flex-direction: column; gap: 3px; }
.chat-list::-webkit-scrollbar { width: 7px; }
.chat-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 20px; }

.chat-item {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 11px; border-radius: 12px; cursor: pointer;
  color: var(--muted); font-size: 13.5px; font-weight: 600;
  border: 1px solid transparent; transition: background 0.14s, color 0.14s, border-color 0.14s;
}
.chat-item:hover { background: var(--panel-2); color: var(--text); }
.chat-item.active { background: var(--accent-soft); color: var(--text); border-color: var(--border); }
.chat-item.active .ci-icon { color: var(--accent); }
.chat-item .ci-icon { flex: none; color: var(--faint); }
.chat-item .ci-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .ci-del {
  flex: none; opacity: 0; border: none; background: none; color: var(--faint);
  cursor: pointer; padding: 3px 5px; border-radius: 7px; font-size: 14px; line-height: 1;
  transition: opacity 0.14s, color 0.14s, background 0.14s;
}
.chat-item:hover .ci-del { opacity: 0.8; }
.chat-item .ci-del:hover { color: var(--danger); background: var(--bg-soft); opacity: 1; }
.chat-empty { color: var(--faint); font-size: 13px; text-align: center; padding: 26px 10px; }

.sidebar-foot { padding: 12px 18px; border-top: 1px solid var(--border); }
.foot-status { font-size: 11.5px; color: var(--faint); }

.overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55);
  opacity: 0; pointer-events: none; transition: opacity 0.22s; z-index: 25;
  backdrop-filter: blur(2px);
}
.app.drawer-open .overlay { opacity: 1; pointer-events: auto; }

/* ============ Main column ============ */
.main {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
  background:
    radial-gradient(1100px 560px at 85% -12%, var(--accent-soft), transparent 58%),
    radial-gradient(800px 500px at -5% 108%, var(--accent-soft), transparent 60%),
    var(--bg);
}

.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 18px;
  background: color-mix(in srgb, var(--panel) 80%, transparent);
  backdrop-filter: blur(14px); border-bottom: 1px solid var(--border);
}
.icon-btn {
  display: none; border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  width: 40px; height: 40px; border-radius: 12px; cursor: pointer; place-items: center;
  transition: background 0.14s;
}
.icon-btn:hover { background: var(--accent-soft); }
.brand { flex: 1; min-width: 0; }
.brand-text h1 {
  font-size: 16.5px; font-weight: 800; margin: 0; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -0.2px;
}
.brand-text p { font-size: 12.5px; margin: 2px 0 0; color: var(--muted); }

.status {
  display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 20px; padding: 6px 12px; white-space: nowrap; font-weight: 600;
}
.status .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent);
  animation: pulse 2.4s ease-in-out infinite;
}

/* ============ Chat area ============ */
.chat {
  flex: 1; overflow-y: auto; padding: 24px 18px 10px;
  display: flex; flex-direction: column; gap: 14px; scroll-behavior: smooth;
}
.chat::-webkit-scrollbar { width: 9px; }
.chat::-webkit-scrollbar-thumb { background: var(--border); border-radius: 20px; }
.chat::-webkit-scrollbar-thumb:hover { background: var(--faint); }

/* Welcome / discovery hub */
.welcome { margin: auto 0; text-align: center; padding: 26px 12px; animation: rise 0.5s ease both; }
.welcome-mark {
  width: 72px; height: 72px; margin: 0 auto 16px; color: var(--accent);
  display: grid; place-items: center; border-radius: 22px;
  background: var(--accent-soft); border: 1px solid var(--border);
  box-shadow: var(--shadow-glow);
}
.welcome h2 { font-size: 23px; font-weight: 800; margin: 0 0 8px; letter-spacing: -0.3px; }
.welcome p { color: var(--muted); font-size: 14.5px; margin: 0 auto 22px; max-width: 460px; line-height: 1.7; }
.suggestions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.chip {
  font-family: inherit; font-size: 14px; font-weight: 600; color: var(--text);
  background: var(--panel); border: 1px solid var(--border); border-radius: 999px;
  padding: 9px 16px; cursor: pointer; box-shadow: var(--shadow-sm);
  display: inline-flex; align-items: center; gap: 6px;
  transition: transform 0.14s, border-color 0.14s, background 0.14s;
}
.chip:hover { transform: translateY(-2px); border-color: var(--accent); background: var(--accent-soft); }
.chip:active { transform: translateY(0); }
.chip-emoji { font-size: 15px; }

/* Messages — user RIGHT, bot LEFT (RTL) */
.msg { display: flex; animation: rise 0.34s cubic-bezier(0.22, 1, 0.36, 1) both; }
.msg.user { justify-content: flex-start; }
.msg.bot { justify-content: flex-end; }

.bubble {
  max-width: min(80%, 640px); padding: 13px 16px; border-radius: var(--radius);
  line-height: 1.78; font-size: 15px; word-wrap: break-word; overflow-wrap: anywhere;
}
.msg.bot .bubble {
  background: var(--bubble-bot); border: 1px solid var(--border);
  border-bottom-left-radius: 6px; box-shadow: var(--shadow-sm);
}
.msg.user .bubble {
  background: var(--grad-accent); color: var(--accent-ink); font-weight: 600;
  border-bottom-right-radius: 6px; box-shadow: var(--shadow-glow);
}

.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble strong { font-weight: 800; }
.bubble em { color: var(--accent); font-style: normal; font-weight: 700; }
.bubble ul { margin: 7px 0; padding-inline-start: 18px; list-style: none; }
.bubble li { margin: 5px 0; padding-inline-start: 14px; position: relative; }
.bubble li::before {
  content: ''; position: absolute; inset-inline-start: 0; top: 0.62em;
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
}
.bubble a {
  color: var(--link); text-decoration: none; font-weight: 700;
  border-bottom: 1.5px solid color-mix(in srgb, var(--link) 40%, transparent);
  transition: border-color 0.14s;
}
.bubble a:hover { border-bottom-color: var(--link); }
.bubble h3.res {
  font-size: 15px; font-weight: 800; margin: 15px 0 7px;
  padding-inline-start: 11px; border-inline-start: 3px solid var(--accent);
}
.bubble h3.res:first-child { margin-top: 2px; }

/* Tool status chip */
.tool-chip {
  align-self: flex-end; display: inline-flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--muted); font-weight: 600;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 13px; animation: rise 0.25s ease both;
}
.tool-chip .spin {
  width: 12px; height: 12px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite;
}

.typing { display: inline-flex; gap: 5px; padding: 5px 2px; }
.typing span {
  width: 8px; height: 8px; border-radius: 50%; background: var(--muted);
  animation: blink 1.2s infinite both;
}
.typing span:nth-child(2) { animation-delay: 0.18s; }
.typing span:nth-child(3) { animation-delay: 0.36s; }

/* ============ Composer ============ */
.composer {
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--panel) 86%, transparent);
  backdrop-filter: blur(14px); border-top: 1px solid var(--border);
}
.composer-inner {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 18px; padding: 7px 7px 7px 14px;
  transition: border-color 0.16s, box-shadow 0.16s;
}
.composer-inner:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.composer textarea {
  flex: 1; resize: none; background: transparent; color: var(--text);
  border: none; padding: 8px 0; font: inherit; font-size: 15px; max-height: 150px; line-height: 1.6;
}
.composer textarea:focus { outline: none; }
.composer textarea::placeholder { color: var(--faint); }
.send-btn {
  flex: none; width: 42px; height: 42px; border: none; border-radius: 13px;
  background: var(--grad-accent); color: var(--accent-ink); display: grid; place-items: center;
  cursor: pointer; box-shadow: var(--shadow-glow); transition: transform 0.14s, filter 0.14s;
}
.send-btn svg { transform: scaleX(-1); }
.send-btn:hover { transform: translateY(-1px) scale(1.03); filter: brightness(1.05); }
.send-btn:active { transform: scale(0.96); }
.send-btn:disabled { opacity: 0.45; cursor: default; transform: none; box-shadow: none; }
.hint { text-align: center; color: var(--faint); font-size: 11.5px; margin: 9px 0 0; }

/* ============ Focus (a11y) ============ */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:focus-visible, .chat-item:focus-visible { outline-offset: 3px; border-radius: 12px; }

/* ============ Animations ============ */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(0.94) translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); } 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--ok) 6%, transparent); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

/* ============ Responsive: sidebar -> drawer ============ */
@media (max-width: 820px) {
  .icon-btn { display: grid; }
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0;
    transform: translateX(var(--sidebar-w)); transition: transform 0.26s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow);
  }
  .app.drawer-open .sidebar { transform: translateX(0); }
  .bubble { max-width: 86%; }
  .welcome h2 { font-size: 20px; }
}
