/* ============================================================
   AIVIGA Portal — Futuristic / Sci-Fi
   Dark (default) & Light themes via [data-theme]
   ============================================================ */

:root {
  --font-ui: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", Consolas, "Courier New", monospace;
}

/* ---------- Dark theme (default) ---------- */
[data-theme="dark"] {
  --bg: #05080f;
  --bg-2: #0a1122;
  --panel: rgba(13, 20, 38, .72);
  --panel-solid: #0d1426;
  --line: rgba(64, 190, 255, .18);
  --line-strong: rgba(64, 190, 255, .45);
  --text: #d6e4f5;
  --text-dim: #7c92ad;
  --accent: #22d3ee;
  --accent-2: #8b5cf6;
  --accent-glow: rgba(34, 211, 238, .35);
  --danger: #f87171;
  --ok: #34d399;
  --user-bubble: linear-gradient(135deg, rgba(34, 211, 238, .18), rgba(139, 92, 246, .18));
  --assistant-bubble: rgba(255, 255, 255, .04);
  --shadow: 0 8px 32px rgba(0, 0, 0, .55);
  --input-bg: rgba(10, 18, 34, .8);
  --select-bg: #0b1222;
  --scroll: rgba(64, 190, 255, .3);
}

/* ---------- Light theme ---------- */
[data-theme="light"] {
  --bg: #eef4fb;
  --bg-2: #e2ecf7;
  --panel: rgba(255, 255, 255, .8);
  --panel-solid: #ffffff;
  --line: rgba(13, 60, 110, .14);
  --line-strong: rgba(13, 60, 110, .3);
  --text: #14263d;
  --text-dim: #5a7088;
  --accent: #0891b2;
  --accent-2: #7c3aed;
  --accent-glow: rgba(8, 145, 178, .22);
  --danger: #dc2626;
  --ok: #059669;
  --user-bubble: linear-gradient(135deg, rgba(8, 145, 178, .12), rgba(124, 58, 237, .12));
  --assistant-bubble: rgba(255, 255, 255, .6);
  --shadow: 0 8px 32px rgba(30, 60, 100, .18);
  --input-bg: rgba(255, 255, 255, .9);
  --select-bg: #ffffff;
  --scroll: rgba(13, 60, 110, .3);
}

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

html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  transition: background .35s ease, color .35s ease;
}

/* ---------- Background FX ---------- */
.bg-grid {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 44px 44px;
  opacity: .5;
  mask-image: radial-gradient(ellipse at 50% 40%, #000 0%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse at 50% 40%, #000 0%, transparent 75%);
}
.bg-orb {
  position: fixed; z-index: 0; pointer-events: none;
  width: 60vmax; height: 60vmax; border-radius: 50%;
  top: -20vmax; left: -15vmax;
  background: radial-gradient(circle, var(--accent-glow), transparent 60%);
  filter: blur(60px);
  animation: orbDrift 18s ease-in-out infinite alternate;
}
@keyframes orbDrift {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(8vmax, 6vmax) scale(1.15); }
}

/* ---------- Layout ---------- */
.topbar {
  position: relative; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(12px);
}

.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px; display: grid; place-items: center;
  font-size: 22px; color: var(--accent);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent-glow), transparent);
  box-shadow: 0 18px var(--accent-glow);
  text-shadow: 0 12px var(--accent);
}
.brand-text h1 { font-size: 18px; letter-spacing: 4px; font-weight: 700; }
.brand-text p { font-size: 11px; letter-spacing: 2px; color: var(--text-dim); text-transform: uppercase; }

.topbar-controls { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

.chip-group { display: flex; gap: 10px; flex-wrap: wrap; }

.chip {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--input-bg);
  font-size: 11px; letter-spacing: 1.5px; color: var(--text-dim);
}
.chip span { text-transform: uppercase; }
.chip select {
  background: transparent; border: none; color: var(--text);
  font-family: var(--font-mono); font-size: 12px;
  outline: none; cursor: pointer;
}
.chip select option { background: var(--select-bg); color: var(--text); }

.icon-controls { display: flex; gap: 8px; }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center;
  background: var(--input-bg); color: var(--text-dim);
  border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer; transition: all .2s ease; text-decoration: none;
}
.icon-btn:hover { color: var(--accent); border-color: var(--line-strong); box-shadow: 0 12px var(--accent-glow); }

[data-theme="dark"] .ico-sun { display: none; }
[data-theme="light"] .ico-moon { display: none; }

/* ---------- Chat area ---------- */
.chat-shell {
  position: relative; z-index: 2;
  height: calc(100vh - 130px);
  overflow-y: auto;
  scroll-behavior: smooth;
  padding: 24px 8px 24px;
}
.chat-shell::-webkit-scrollbar { width: 10px; }
.chat-shell::-webkit-scrollbar-thumb { background: var(--scroll); border-radius: 6px; }

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

.msg { display: flex; gap: 12px; animation: msgIn .3s ease; }
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.msg-avatar {
  flex: 0 32px; height: 32px; display: grid; place-items: center;
  border-radius: 8px; font-size: 15px;
}
.msg.user .msg-avatar { background: var(--user-bubble); border: 1px solid var(--line-strong); }
.msg.ai .msg-avatar { background: var(--assistant-bubble); border: 1px solid var(--line); color: var(--accent); }

.msg-bubble {
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--assistant-bubble);
  max-width: 85%;
  line-height: 1.6;
  font-size: 14px;
  overflow-wrap: break-word;
}
.msg.user .msg-bubble {
  background: var(--user-bubble);
  border-color: var(--line-strong);
  margin-left: auto;
}
.msg.meta { justify-content: center; }
.msg.meta .msg-bubble {
  background: transparent; border-style: dashed;
  color: var(--text-dim); font-size: 12px; letter-spacing: 1px;
  text-transform: uppercase; padding: 6px 14px; max-width: 100%;
}

/* markdown-ish content */
.msg-bubble pre {
  background: rgba(0, 0, 0, .35); border: 1px solid var(--line);
  border-radius: 8px; padding: 12px; overflow-x: auto;
  font-family: var(--font-mono); font-size: 12.5px; margin: 8px 0;
}
[data-theme="light"] .msg-bubble pre { background: rgba(13, 30, 55, .06); }
.msg-bubble code { font-family: var(--font-mono); font-size: 12.5px; background: rgba(0,0,0,.25); padding: 1px 5px; border-radius: 4px; }
[data-theme="light"] .msg-bubble code { background: rgba(13, 30, 55, .08); }
.msg-bubble pre code { background: none; padding: 0; }
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 { margin: 10px 0 6px; }
.msg-bubble ul, .msg-bubble ol { padding-left: 22px; margin: 6px 0; }
.msg-bubble a { color: var(--accent); }
.msg-bubble table { border-collapse: collapse; margin: 8px 0; }
.msg-bubble th, .msg-bubble td { border: 1px solid var(--line); padding: 6px 10px; }

.typing { display: inline-flex; gap: 5px; align-items: center; padding: 6px 0; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---------- Welcome ---------- */
.welcome {
  position: absolute; inset: 0; z-index: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; text-align: center; pointer-events: none;
}
.welcome.hidden { display: none; }
.welcome-core { position: relative; width: 110px; height: 110px; display: grid; place-items: center; }
.core-ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 1px solid var(--line-strong);
  animation: spin 8s linear infinite;
}
.core-ring::after {
  content: ""; position: absolute; top: -4px; left: 50%;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 12px var(--accent);
}
@keyframes spin { to { transform: rotate(360deg); } }
.core {
  font-size: 40px; color: var(--accent);
  text-shadow: 0 24px var(--accent);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }
.welcome h2 { font-size: 22px; letter-spacing: 3px; font-weight: 600; }
.welcome-hint { color: var(--text-dim); font-size: 13px; letter-spacing: 1px; }

/* ---------- Composer ---------- */
.composer-wrap {
  position: relative; z-index: 5;
  border-top: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(12px);
  padding: 10px 22px 14px;
}
.status-line {
  display: flex; align-items: center; gap: 8px;
  max-width: 860px; margin: 0 auto 8px;
  font-family: var(--font-mono); font-size: 10px;
  letter-spacing: 2px; color: var(--text-dim);
}
.status-line .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-dim); transition: background .3s;
}
.status-line.active .dot { background: var(--ok); box-shadow: 0 8px var(--ok); }
.status-line.busy .dot { background: var(--accent); box-shadow: 0 8px var(--accent); animation: pulse 1s infinite; }
.status-line.error .dot { background: var(--danger); box-shadow: 0 8px var(--danger); }

.composer {
  display: flex; align-items: flex-end; gap: 10px;
  max-width: 860px; margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--input-bg);
  padding: 10px 12px;
  transition: border-color .2s, box-shadow .2s;
}
.composer:focus-within { border-color: var(--line-strong); box-shadow: 0 18px var(--accent-glow); }

.composer textarea {
  flex: 1; resize: none; border: none; outline: none;
  background: transparent; color: var(--text);
  font-family: var(--font-ui); font-size: 14.5px; line-height: 1.5;
  max-height: 160px; padding: 4px 2px;
}
.composer textarea::placeholder { color: var(--text-dim); }

.composer-actions { display: flex; gap: 6px; }
.action-btn {
  width: 40px; height: 40px; display: grid; place-items: center;
  background: transparent; color: var(--text-dim);
  border: 1px solid var(--line); border-radius: 12px;
  cursor: pointer; transition: all .2s;
}
.action-btn:hover { color: var(--accent); border-color: var(--line-strong); }
.action-btn.on { color: var(--accent); border-color: var(--accent); box-shadow: 0 10px var(--accent-glow); }
.action-btn.recording {
  color: #fff; background: var(--danger); border-color: var(--danger);
  animation: pulse 1s infinite;
}
.send-btn {
  width: 44px; height: 40px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border: none; border-radius: 12px;
  cursor: pointer; transition: transform .15s, box-shadow .2s;
  box-shadow: 0 4px 16px var(--accent-glow);
}
.send-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 22px var(--accent-glow); }
.send-btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .topbar { padding: 10px 14px; }
  .brand-text p { display: none; }
  .chip span { display: none; }
  .chip { padding: 5px 10px; }
  .msg-bubble { max-width: 92%; }
  .welcome h2 { font-size: 17px; }
}
