/* ============================================================
   Casper — Futuristic Glassmorphism UI
   Desktop · Tablet · Phone · RTL
   ============================================================ */

:root {
  --bg-0: #05060c;
  --bg-1: #0a0b14;
  --violet: #7c5cff;
  --indigo: #5b6bff;
  --cyan: #34e7e4;
  --pink: #b15cff;
  --glow: #7c5cff;

  --text: #eef0ff;
  --muted: #9aa0c0;
  --faint: #6b7196;

  --glass: rgba(255, 255, 255, 0.045);
  --glass-2: rgba(255, 255, 255, 0.07);
  --stroke: rgba(255, 255, 255, 0.10);
  --stroke-2: rgba(255, 255, 255, 0.16);

  --radius: 18px;
  --radius-sm: 12px;
  --blur: 22px;
  --shadow: 0 18px 50px -12px rgba(0, 0, 0, 0.55);
  --ease: cubic-bezier(.22, 1, .36, 1);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Tajawal', system-ui, sans-serif;
  color: var(--text);
  background: var(--bg-0);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; cursor: pointer; color: inherit; }
::selection { background: rgba(124, 92, 255, .35); }

/* ---------------------------------------------------------------- */
/*  Animated aurora background                                       */
/* ---------------------------------------------------------------- */
.aurora { position: fixed; inset: 0; z-index: -2; overflow: hidden; background:
    radial-gradient(120% 120% at 80% -10%, #10122a 0%, var(--bg-0) 55%),
    radial-gradient(100% 100% at 0% 110%, #0b1422 0%, var(--bg-0) 60%); }
.aurora .blob { position: absolute; border-radius: 50%; filter: blur(70px); opacity: .55;
  mix-blend-mode: screen; will-change: transform; }
.blob.b1 { width: 46vw; height: 46vw; left: -8vw; top: -10vh;
  background: radial-gradient(circle, var(--violet), transparent 65%); animation: drift1 22s var(--ease) infinite; }
.blob.b2 { width: 40vw; height: 40vw; right: -6vw; top: 8vh;
  background: radial-gradient(circle, var(--cyan), transparent 65%); animation: drift2 26s var(--ease) infinite; }
.blob.b3 { width: 38vw; height: 38vw; left: 25vw; bottom: -16vh;
  background: radial-gradient(circle, var(--pink), transparent 65%); animation: drift3 30s var(--ease) infinite; }
.grid-overlay { position: absolute; inset: 0; opacity: .25;
  background-image: linear-gradient(rgba(255,255,255,.04) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(255,255,255,.04) 1px, transparent 1px);
  background-size: 46px 46px; mask-image: radial-gradient(120% 80% at 50% 0%, #000 30%, transparent 80%); }

@keyframes drift1 { 0%,100% { transform: translate(0,0) scale(1) } 50% { transform: translate(6vw,5vh) scale(1.12) } }
@keyframes drift2 { 0%,100% { transform: translate(0,0) scale(1) } 50% { transform: translate(-5vw,6vh) scale(1.08) } }
@keyframes drift3 { 0%,100% { transform: translate(0,0) scale(1) } 50% { transform: translate(4vw,-5vh) scale(1.15) } }

/* ---------------------------------------------------------------- */
/*  Glass primitive                                                  */
/* ---------------------------------------------------------------- */
.glass {
  background: linear-gradient(160deg, var(--glass-2), var(--glass));
  backdrop-filter: blur(var(--blur)) saturate(150%);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(150%);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.08);
}

/* ---------------------------------------------------------------- */
/*  App shell / layout                                               */
/* ---------------------------------------------------------------- */
.app-shell { display: flex; height: 100dvh; padding: 14px; gap: 14px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 14px; }

.backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(3,4,10,.55);
  backdrop-filter: blur(2px); opacity: 0; pointer-events: none; transition: opacity .3s var(--ease); }
body.nav-open .backdrop { opacity: 1; }

/* ---------------------------------------------------------------- */
/*  Sidebar                                                          */
/* ---------------------------------------------------------------- */
.sidebar { width: 290px; flex-shrink: 0; border-radius: var(--radius);
  display: flex; flex-direction: column; padding: 16px; }
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 4px 16px;
  border-bottom: 1px solid var(--stroke); }
.brand-mark { width: 44px; height: 44px; filter: drop-shadow(0 4px 14px rgba(124,92,255,.5)); animation: floaty 6s ease-in-out infinite; }
.brand-mark svg { width: 100%; height: 100%; }
.brand-name { font-weight: 800; font-size: 17px; letter-spacing: .3px; }
.brand-sub { font-size: 11px; color: var(--muted); margin-top: 1px; }
@keyframes floaty { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-4px) } }

.side-label { font-size: 11px; color: var(--faint); font-weight: 600; padding: 16px 6px 8px; letter-spacing: .5px; }
.chat-list { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 0 2px; display: flex; flex-direction: column; gap: 6px; }
.chat-item { display: flex; align-items: center; gap: 8px; padding: 11px 12px; border-radius: var(--radius-sm);
  border: 1px solid transparent; cursor: pointer; transition: all .2s var(--ease); font-size: 14px; }
.chat-item:hover { background: var(--glass); border-color: var(--stroke); transform: translateX(-2px); }
.chat-item.active { background: linear-gradient(120deg, rgba(124,92,255,.20), rgba(52,231,228,.10));
  border-color: rgba(124,92,255,.4); box-shadow: 0 0 24px -8px rgba(124,92,255,.6); }
.chat-item .ci-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .ci-del { opacity: 0; color: var(--faint); background: none; border: none; padding: 2px; border-radius: 6px; transition: .15s; }
.chat-item:hover .ci-del { opacity: 1; }
.chat-item .ci-del:hover { color: #ff6b8a; background: rgba(255,107,138,.12); }
.chat-empty { text-align: center; color: var(--faint); font-size: 12px; padding: 26px 0; }
.side-settings { margin-top: 12px; }

/* ---------------------------------------------------------------- */
/*  Buttons                                                          */
/* ---------------------------------------------------------------- */
.btn-primary, .btn-ghost { display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 12px 14px; border-radius: 14px; font-size: 14px; font-weight: 600;
  border: 1px solid var(--stroke); transition: all .2s var(--ease); }
.btn-primary { color: #fff;
  background: var(--indigo); border: none; box-shadow: 0 10px 28px -10px rgba(91,107,255,.8); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 14px 34px -10px rgba(124,92,255,.95); }
.btn-primary:active { transform: translateY(0) scale(.98); }
.btn-ghost { background: var(--glass); color: var(--text); }
.btn-ghost:hover { background: var(--glass-2); border-color: var(--stroke-2); transform: translateY(-1px); }
@keyframes sheen { 0% { background-position: 0% 50% } 100% { background-position: 180% 50% } }

.icon-btn { display: grid; place-items: center; width: 42px; height: 42px; flex-shrink: 0;
  border-radius: 13px; background: var(--glass); border: 1px solid var(--stroke);
  color: var(--text); transition: all .2s var(--ease); }
.icon-btn:hover { background: var(--glass-2); border-color: var(--stroke-2); transform: translateY(-2px); color: #fff; }
.icon-btn:active { transform: scale(.92); }
.icon-btn.is-active { border-color: rgba(124,92,255,.7); color: #fff;
  background: linear-gradient(120deg, rgba(124,92,255,.30), rgba(52,231,228,.18));
  box-shadow: 0 0 22px -4px rgba(124,92,255,.85); }
.icon-btn.send { color: #fff; border: none;
  background: var(--indigo);
  box-shadow: 0 10px 26px -8px rgba(91,107,255,.85); }
.icon-btn.send:hover { transform: translateY(-2px) scale(1.04); }

.ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.ico-sm { width: 16px; height: 16px; }

/* ---------------------------------------------------------------- */
/*  Top bar                                                          */
/* ---------------------------------------------------------------- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: var(--radius); }
.nav-toggle { display: none; }
.topbar-title { flex: 1; font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-wrap { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 12px;
  background: var(--glass); border: 1px solid var(--stroke); color: var(--muted); }
.voice-select { background: transparent; border: none; color: var(--text); font-size: 13px; outline: none; max-width: 150px; }
.voice-select option { background: var(--bg-1); color: var(--text); }
.status-pill { font-size: 11px; padding: 6px 12px; border-radius: 999px; white-space: nowrap;
  background: var(--glass); border: 1px solid var(--stroke); color: var(--muted); transition: .25s; }
.status-pill.ok { color: #6ff0c0; border-color: rgba(111,240,192,.35); background: rgba(111,240,192,.08); }
.status-pill.warn { color: #ffd27a; border-color: rgba(255,210,122,.35); background: rgba(255,210,122,.08); }
.status-pill.busy { color: #c4b4ff; border-color: rgba(124,92,255,.4); background: rgba(124,92,255,.1);
  animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .55 } }

/* ---------------------------------------------------------------- */
/*  Messages                                                         */
/* ---------------------------------------------------------------- */
.messages { flex: 1; overflow-y: auto; padding: 8px 6px 4px; display: flex; flex-direction: column; gap: 18px; }
.msg { display: flex; gap: 12px; max-width: min(48rem, 100%); }
.msg-user { flex-direction: row-reverse; align-self: flex-start; }
.bubble { border-radius: 16px; padding: 12px 16px; line-height: 1.75; white-space: pre-wrap; word-break: break-word;
  animation: fadeUp .4s var(--ease) both; }
.msg-user .bubble { background: linear-gradient(135deg, rgba(124,92,255,.22), rgba(177,92,255,.14));
  border: 1px solid rgba(124,92,255,.34); box-shadow: 0 8px 26px -14px rgba(124,92,255,.7); }
.msg-assistant .bubble { background: var(--glass); border: 1px solid var(--stroke);
  backdrop-filter: blur(10px); box-shadow: var(--shadow); }
.bubble.opacity-0 { animation: none; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px) } to { opacity: 1; transform: translateY(0) } }

.bubble p { margin: 0 0 .6rem; } .bubble p:last-child { margin-bottom: 0; }
.bubble strong { color: #fff; }
.bubble code { background: rgba(255,255,255,.08); padding: .12rem .4rem; border-radius: .4rem; font-size: .85em; direction: ltr; display: inline-block; }
.bubble pre { background: rgba(5,6,12,.7); border: 1px solid var(--stroke); border-radius: 12px;
  padding: .8rem 1rem; padding-top: 2.5rem; overflow-x: auto; direction: ltr; text-align: left; margin: .6rem 0; position: relative; }
.code-bar { position: absolute; top: 0; inset-inline: 0; display: flex; align-items: center; justify-content: space-between;
  padding: .35rem .7rem; background: rgba(255,255,255,.04); border-bottom: 1px solid var(--stroke);
  border-radius: 12px 12px 0 0; direction: rtl; }
.code-lang { font-size: .68rem; color: var(--faint); direction: ltr; text-transform: lowercase; letter-spacing: .5px; }
.code-copy { font-size: .68rem; color: var(--muted); background: var(--glass-2); border: 1px solid var(--stroke);
  border-radius: 7px; padding: .12rem .6rem; transition: .15s; }
.code-copy:hover { color: #fff; border-color: var(--glow); }

.msg-col { min-width: 0; }
.msg-meta { font-size: 10px; color: var(--faint); margin-top: 5px; padding: 0 4px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; }
.avatar .ico { width: 18px; height: 18px; }
.avatar-assistant { color: #fff; background: linear-gradient(135deg, var(--violet), var(--cyan));
  box-shadow: 0 6px 18px -6px rgba(124,92,255,.7); }
.avatar-user { color: var(--muted); background: var(--glass-2); border: 1px solid var(--stroke); }

.typing span { display: inline-block; width: 7px; height: 7px; margin: 0 2px; background: var(--glow);
  border-radius: 99px; animation: blink 1.4s infinite both; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100% { opacity: .25; transform: scale(.8) } 40% { opacity: 1; transform: scale(1) } }

/* ---------------------------------------------------------------- */
/*  Orb stage (voice mode)                                           */
/* ---------------------------------------------------------------- */
.orb-stage { position: relative; height: 300px; border-radius: var(--radius); overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(60% 80% at 50% 50%, rgba(124,92,255,.12), transparent 70%);
  border: 1px solid var(--stroke); animation: fadeUp .4s var(--ease) both; }
.orb-stage.hidden { display: none; }
.orb-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.orb-caption { position: relative; z-index: 2; text-align: center; }
.orb-caption > div { font-size: 18px; font-weight: 600; }
.orb-hint { font-size: 12px; color: var(--muted); }

/* ---------------------------------------------------------------- */
/*  Composer                                                         */
/* ---------------------------------------------------------------- */
.composer-bar { display: flex; flex-direction: column; gap: 8px; }
.file-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.file-chips:empty { display: none; }
.file-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 6px 10px;
  border-radius: 10px; background: var(--glass-2); border: 1px solid var(--stroke); max-width: 14rem; }
.file-chip .fc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip button { background: none; border: none; color: var(--faint); } .file-chip button:hover { color: #ff6b8a; }

.composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px; border-radius: var(--radius); }
.composer textarea { flex: 1; resize: none; max-height: 168px; min-height: 26px; background: transparent;
  border: none; outline: none; color: var(--text); font-size: 15px; line-height: 1.6; padding: 8px 6px; }
.composer textarea::placeholder { color: var(--faint); }
.composer-note { text-align: center; font-size: 10.5px; color: var(--faint); padding: 0 8px; }

/* ---------------------------------------------------------------- */
/*  Settings modal                                                   */
/* ---------------------------------------------------------------- */
.modal-overlay { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px;
  background: rgba(3,4,10,.6); backdrop-filter: blur(6px); animation: fadeIn .25s var(--ease); }
.modal-overlay.hidden { display: none; }
.modal { width: 100%; max-width: 540px; border-radius: 22px; overflow: hidden; animation: popIn .35s var(--ease); }
@keyframes popIn { from { opacity: 0; transform: translateY(16px) scale(.97) } to { opacity: 1; transform: none } }
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--stroke); }
.modal-head h2 { margin: 0; font-size: 18px; font-weight: 800; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 18px; max-height: 70vh; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--stroke); }
.modal-foot .btn-primary, .modal-foot .btn-ghost { width: auto; padding: 10px 22px; }

.field label { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; margin-bottom: 5px; }
.field .badge { font-size: 10px; font-weight: 500; color: var(--cyan); background: rgba(52,231,228,.1);
  border: 1px solid rgba(52,231,228,.3); padding: 1px 8px; border-radius: 999px; }
.field .hint { font-size: 11.5px; color: var(--faint); margin: 0 0 7px; line-height: 1.5; }
.field input, .field textarea, .select-block { width: 100%; background: rgba(5,6,12,.5); border: 1px solid var(--stroke);
  border-radius: 12px; padding: 11px 13px; color: var(--text); font-size: 13.5px; outline: none; transition: .2s; font-family: inherit; }
.field textarea { resize: vertical; }
.field input:focus, .field textarea:focus, .select-block:focus { border-color: rgba(124,92,255,.6); box-shadow: 0 0 0 3px rgba(124,92,255,.18); }
.switch-row { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 500; }
.switch-row input { width: 18px; height: 18px; accent-color: var(--violet); flex-shrink: 0; }
.switch-row b { color: var(--cyan); }
.note-glass { display: flex; gap: 10px; align-items: flex-start; font-size: 11.5px; color: var(--muted); line-height: 1.6;
  background: rgba(124,92,255,.08); border: 1px solid rgba(124,92,255,.2); border-radius: 12px; padding: 12px 14px; }
.note-glass .ico { color: var(--violet); flex-shrink: 0; }

/* ---------------------------------------------------------------- */
/*  Toast + boot warning                                             */
/* ---------------------------------------------------------------- */
#toast { position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%); z-index: 70;
  padding: 12px 18px; border-radius: 14px; font-size: 13.5px; transition: opacity .3s var(--ease);
  background: var(--glass-2); border: 1px solid var(--stroke-2); backdrop-filter: blur(16px); box-shadow: var(--shadow); }
.boot-warn { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 80;
  background: rgba(255,210,122,.12); border: 1px solid rgba(255,210,122,.4); color: #ffd27a;
  padding: 10px 16px; border-radius: 12px; font-size: 12.5px; max-width: 92vw; text-align: center; backdrop-filter: blur(10px); }
.boot-warn code { background: rgba(0,0,0,.3); padding: 1px 6px; border-radius: 5px; direction: ltr; display: inline-block; }

/* ---------------------------------------------------------------- */
/*  Scrollbars                                                       */
/* ---------------------------------------------------------------- */
.scroll-thin::-webkit-scrollbar { width: 8px; height: 8px; }
.scroll-thin::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 99px; }
.scroll-thin::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.2); }
.scroll-thin { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.12) transparent; }

/* ---------------------------------------------------------------- */
/*  Responsive — tablet & phone                                      */
/* ---------------------------------------------------------------- */
@media (max-width: 1024px) {
  .app-shell { padding: 10px; gap: 10px; }
  .nav-toggle { display: grid; }
  .sidebar { position: fixed; z-index: 50; top: 0; bottom: 0; inset-inline-start: 0; width: min(86vw, 320px);
    border-radius: 22px 0 0 22px; transform: translateX(105%); transition: transform .35s var(--ease); margin: 10px 0; }
  body.nav-open .sidebar { transform: translateX(0); }
  .backdrop { pointer-events: none; }
  body.nav-open .backdrop { pointer-events: auto; }
}
@media (min-width: 1025px) { .backdrop { display: none; } }

@media (max-width: 640px) {
  .app-shell { padding: 0; gap: 8px; }
  .main { gap: 8px; }
  .topbar { border-radius: 0 0 var(--radius) var(--radius); padding: 10px 12px; }
  .voice-select { max-width: 92px; }
  .status-pill { display: none; }
  .messages { padding: 6px 10px; }
  .msg { max-width: 100%; }
  .orb-stage { height: 240px; border-radius: var(--radius); }
  .composer-bar { padding: 0 8px 8px; }
  .composer { border-radius: 18px; }
  .composer textarea { font-size: 16px; } /* avoids iOS zoom on focus */
  .icon-btn { width: 40px; height: 40px; }
  #toast { bottom: 110px; }
}

@media (prefers-reduced-motion: reduce) {
  .blob, .brand-mark, .btn-primary, .icon-btn.send, .status-pill.busy { animation: none !important; }
  * { transition-duration: .01ms !important; }
}
