/* ═══════════════════════════════════════════════════════
   ELAINA AI — UPGRADED STYLE
   ═══════════════════════════════════════════════════════ */

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

/* ── THEME VARIABLES ─────────────────────────────────── */
:root {
  --pink:    #ff4fd8;
  --purple:  #7d4dff;
  --grad:    linear-gradient(135deg, var(--pink), var(--purple));

  /* Transitions */
  --tr-fast: 150ms cubic-bezier(.4,0,.2,1);
  --tr-mid:  250ms cubic-bezier(.4,0,.2,1);
  --tr-slow: 400ms cubic-bezier(.4,0,.2,1);
}

/* DARK THEME (default) */
[data-theme="dark"] {
  --bg:           #0d0b14;
  --bg2:          #12101e;
  --sidebar-bg:   rgba(13,11,20,.88);
  --topbar-bg:    rgba(13,11,20,.75);
  --input-bg:     rgba(255,255,255,.06);
  --glass:        rgba(255,255,255,.06);
  --border:       rgba(255,255,255,.10);
  --text:         #f0eaff;
  --text2:        #c8bcdf;
  --muted:        #7a6e90;
  --bot-bubble:   rgba(255,255,255,.07);
  --bot-border:   rgba(255,255,255,.10);
  --shadow:       0 8px 32px rgba(0,0,0,.4);
  --shadow-sm:    0 2px 8px rgba(0,0,0,.3);
  --scroll-thumb: rgba(255,79,216,.30);
}

/* LIGHT THEME */
[data-theme="light"] {
  --bg:           #f4f0ff;
  --bg2:          #ece6fa;
  --sidebar-bg:   rgba(244,240,255,.95);
  --topbar-bg:    rgba(244,240,255,.85);
  --input-bg:     rgba(255,255,255,.85);
  --glass:        rgba(255,255,255,.7);
  --border:       rgba(125,77,255,.15);
  --text:         #1a1030;
  --text2:        #3d2e60;
  --muted:        #8a7aaa;
  --bot-bubble:   rgba(255,255,255,.92);
  --bot-border:   rgba(125,77,255,.15);
  --shadow:       0 8px 32px rgba(125,77,255,.12);
  --shadow-sm:    0 2px 8px rgba(125,77,255,.08);
  --scroll-thumb: rgba(255,79,216,.40);
}

/* ── BASE ────────────────────────────────────────────── */
body {
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Nunito', 'Noto Sans JP', sans-serif;
  transition: background var(--tr-slow), color var(--tr-slow);
}

/* Background texture */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(ellipse 80% 50% at 20% 10%, rgba(255,79,216,.07) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 90%, rgba(125,77,255,.08) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
  transition: opacity var(--tr-slow);
}

[data-theme="light"] body::before {
  background-image:
    radial-gradient(ellipse 80% 50% at 20% 10%, rgba(255,79,216,.10) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 90%, rgba(125,77,255,.10) 0%, transparent 60%);
}

.app {
  position: relative;
  width: 100%;
  height: 100dvh;
  display: flex;
  z-index: 1;
}

/* ── SIDEBAR ─────────────────────────────────────────── */
.sidebar {
  width: 268px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border-right: 1px solid var(--border);
  overflow: hidden;
  transition: background var(--tr-slow), border-color var(--tr-slow),
              transform var(--tr-mid), width var(--tr-mid);
}

.sidebar-header {
  padding: 24px 18px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-ring {
  position: relative;
  width: 52px;
  height: 52px;
  flex-shrink: 0;
}

.logo-ring::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  background: var(--grad);
  z-index: 0;
  animation: spinRing 8s linear infinite;
}

@keyframes spinRing {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.logo-ring img,
.logo-ring .logo-fallback {
  position: absolute;
  inset: 2px;
  width: calc(100% - 4px);
  height: calc(100% - 4px);
  border-radius: 50%;
  z-index: 1;
  background: var(--bg2);
  overflow: hidden;
}

.logo-ring .logo-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--pink);
}

.logo-ring img { display: block; }
.logo-ring img + .logo-fallback { display: none; }
.logo-ring img[style*="none"] + .logo-fallback { display: flex; }

.logo-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.logo-name {
  font-family: 'Cinzel', serif;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 4px;
  background: var(--grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-sub {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: .5px;
}

/* New Chat Button */
.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 14px 16px 0;
  padding: 11px 16px;
  border: none;
  border-radius: 12px;
  background: var(--grad);
  color: white;
  font-family: 'Nunito', sans-serif;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity var(--tr-fast), transform var(--tr-fast), box-shadow var(--tr-fast);
  box-shadow: 0 4px 16px rgba(255,79,216,.25);
}

.new-chat-btn:hover {
  opacity: .9;
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(255,79,216,.35);
}

.new-chat-btn:active { transform: translateY(0); }

/* Section label */
.section-label {
  margin: 16px 18px 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--muted);
  text-transform: uppercase;
  flex-shrink: 0;
}

/* Chat List */
.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: transparent;
  color: var(--text2);
  font-size: 13px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--tr-fast);
  animation: slideIn .18s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0); }
}

.chat-item .chat-icon { flex-shrink: 0; font-size: 14px; opacity: .7; }
.chat-item .chat-title { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.chat-item .del-btn {
  opacity: 0;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 6px;
  flex-shrink: 0;
  transition: all var(--tr-fast);
  font-size: 13px;
}

.chat-item:hover { background: var(--glass); border-color: var(--border); color: var(--text); }
.chat-item:hover .del-btn { opacity: 1; }
.chat-item .del-btn:hover { background: rgba(255,100,100,.15); color: #ff6b6b; }
.chat-item.active {
  background: rgba(125,77,255,.14);
  border-color: rgba(125,77,255,.25);
  color: var(--text);
}

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.footer-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: none;
  color: var(--muted);
  font-family: 'Nunito', sans-serif;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--tr-fast);
}

.footer-btn:hover {
  color: var(--pink);
  border-color: rgba(255,79,216,.35);
  background: rgba(255,79,216,.05);
}

/* Sidebar toggle (mobile) */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 201;
  background: var(--sidebar-bg);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px;
  border-radius: 10px;
  cursor: pointer;
  transition: all var(--tr-fast);
  box-shadow: var(--shadow-sm);
}

.sidebar-toggle:hover { border-color: var(--pink); color: var(--pink); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px);
  z-index: 99;
  animation: fadeIn .2s ease;
}

.sidebar-overlay.active { display: block; }

/* ── CHAT AREA ───────────────────────────────────────── */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  height: 58px;
  flex-shrink: 0;
  background: var(--topbar-bg);
  backdrop-filter: blur(16px) saturate(1.3);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  border-bottom: 1px solid var(--border);
  transition: background var(--tr-slow), border-color var(--tr-slow);
  z-index: 10;
}

.topbar-left { display: flex; flex-direction: column; gap: 1px; }

.status-wrap { display: flex; align-items: center; gap: 7px; }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 2px rgba(74,222,128,.2);
  animation: pulse 2.5s ease infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(74,222,128,.2); }
  50%       { box-shadow: 0 0 0 5px rgba(74,222,128,.08); }
}

.topbar-name {
  font-weight: 700;
  font-size: 14.5px;
  color: var(--text);
}

.topbar-status {
  font-size: 11px;
  color: #4ade80;
  letter-spacing: .3px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-brand {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 1px;
}

.theme-quick-btn {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 16px;
  cursor: pointer;
  transition: all var(--tr-fast);
  line-height: 1;
}

.theme-quick-btn:hover {
  border-color: var(--pink);
  transform: scale(1.1) rotate(15deg);
}

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

/* Message bubble */
.msg {
  display: flex;
  max-width: 68%;
  animation: msgPop .22s cubic-bezier(.34,1.56,.64,1);
}

@keyframes msgPop {
  from { opacity: 0; transform: scale(.94) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.bot  { align-self: flex-start; }

.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  margin-top: 4px;
}

.msg.bot .msg-avatar {
  background: var(--grad);
  color: white;
  margin-right: 8px;
}

.msg.user .msg-avatar {
  background: var(--glass);
  border: 1px solid var(--border);
  margin-left: 8px;
  color: var(--muted);
}

.msg-content {
  padding: 11px 15px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.7;
  word-break: break-word;
  position: relative;
}

.msg.user .msg-content {
  background: var(--grad);
  color: white;
  border-bottom-right-radius: 5px;
  box-shadow: 0 4px 14px rgba(255,79,216,.25);
}

.msg.bot .msg-content {
  background: var(--bot-bubble);
  border: 1px solid var(--bot-border);
  color: var(--text);
  border-bottom-left-radius: 5px;
  backdrop-filter: blur(8px);
  transition: background var(--tr-slow), border-color var(--tr-slow);
}

.ai-image{
  width: 100%;
  max-width: 420px;
  border-radius: 18px;
  display: block;
  object-fit: cover;
  margin-top: 4px;
  box-shadow: 0 0 20px rgba(255,79,216,.25);
}

.msg.bot .msg-content{
  max-width: 460px;
}

/* Timestamp */
.msg-time {
  font-size: 10px;
  color: var(--muted);
  margin-top: 4px;
  padding: 0 4px;
  text-align: right;
}

.msg.bot .msg-time { text-align: left; }

/* Typing indicator */
.typing-wrap {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 6px 28px 14px;
  animation: fadeIn .2s ease;
}

.typing-wrap.active { display: flex; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.typing-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bot-bubble);
  border: 1px solid var(--bot-border);
  padding: 9px 14px;
  border-radius: 18px;
  border-bottom-left-radius: 5px;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--pink);
  animation: bounce 1.1s ease-in-out infinite;
}

.dot:nth-child(2) { animation-delay: .16s; }
.dot:nth-child(3) { animation-delay: .32s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: .4; }
  40%            { transform: translateY(-6px); opacity: 1; }
}

.typing-label {
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}

/* Input area */
.input-area {
  padding: 14px 24px 16px;
  background: var(--topbar-bg);
  backdrop-filter: blur(16px) saturate(1.3);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  border-top: 1px solid var(--border);
  transition: background var(--tr-slow), border-color var(--tr-slow);
}

.input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--input-bg);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  padding: 4px 4px 4px 16px;
  transition: all var(--tr-fast);
}

.input-wrap:focus-within {
  border-color: rgba(255,79,216,.5);
  box-shadow: 0 0 0 3px rgba(255,79,216,.08);
  background: var(--input-bg);
}

.input-wrap input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: 'Nunito', 'Noto Sans JP', sans-serif;
  font-size: 14px;
  padding: 8px 0;
}

.input-wrap input::placeholder { color: var(--muted); }

.send-btn {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border: none;
  border-radius: 12px;
  background: var(--grad);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--tr-fast);
  box-shadow: 0 3px 10px rgba(255,79,216,.3);
}

.send-btn:hover { opacity: .9; transform: scale(1.05); box-shadow: 0 4px 14px rgba(255,79,216,.4); }
.send-btn:active { transform: scale(.97); }
.send-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.input-hint {
  margin-top: 7px;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  opacity: .7;
}

/* ── WELCOME SCREEN ──────────────────────────────────── */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 100%;
  color: var(--muted);
  text-align: center;
  padding: 20px;
}

.welcome-screen .w-icon {
  font-size: 48px;
  margin-bottom: 6px;
  animation: floatWave 3s ease-in-out infinite;
}

@keyframes floatWave {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  33%       { transform: translateY(-6px) rotate(-3deg); }
  66%       { transform: translateY(-3px) rotate(3deg); }
}

.welcome-screen h3 {
  font-family: 'Cinzel', serif;
  font-size: 18px;
  letter-spacing: 3px;
  background: var(--grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-screen p { font-size: 13px; line-height: 1.7; max-width: 280px; }

/* ── MODAL ───────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 9999;
  padding: 20px;
}

.modal-overlay.active { display: flex; }

.modal {
  width: min(460px, 100%);
  border-radius: 22px;
  background: var(--bg2);
  border: 1px solid var(--border);
  box-shadow: 0 24px 64px rgba(0,0,0,.5);
  animation: popIn .22s cubic-bezier(.34,1.56,.64,1);
  overflow: hidden;
  transition: background var(--tr-slow), border-color var(--tr-slow);
}

@keyframes popIn {
  from { transform: scale(.92); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-family: 'Cinzel', serif;
  font-size: 16px;
  letter-spacing: 3px;
  background: var(--grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal-close {
  background: var(--glass);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--tr-fast);
}

.modal-close:hover { color: #ff6b6b; border-color: rgba(255,100,100,.3); background: rgba(255,100,100,.1); }

.settings-body {
  padding: 8px 24px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 60vh;
  overflow-y: auto;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.setting-row:last-child { border-bottom: none; }

.setting-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.setting-label {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
}

.setting-desc {
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.4;
}

.setting-input {
  width: 140px;
  flex-shrink: 0;
  padding: 9px 12px;
  background: var(--input-bg);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: 'Nunito', sans-serif;
  font-size: 13px;
  outline: none;
  transition: all var(--tr-fast);
}

.setting-input:focus { border-color: var(--pink); box-shadow: 0 0 0 2px rgba(255,79,216,.1); }

/* Pill group */
.pill-group {
  display: flex;
  gap: 5px;
  flex-shrink: 0;
}

.pill {
  padding: 7px 12px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--glass);
  color: var(--muted);
  font-family: 'Nunito', sans-serif;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--tr-fast);
  white-space: nowrap;
}

.pill:hover { border-color: var(--pink); color: var(--pink); background: rgba(255,79,216,.07); }
.pill.active {
  background: var(--grad);
  border-color: transparent;
  color: white;
  box-shadow: 0 3px 10px rgba(255,79,216,.3);
}

/* Modal footer */
.modal-footer {
  display: flex;
  gap: 8px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
}

.btn-save {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 12px;
  background: var(--grad);
  color: white;
  font-family: 'Nunito', sans-serif;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--tr-fast);
  box-shadow: 0 4px 14px rgba(255,79,216,.25);
}

.btn-save:hover { opacity: .9; transform: translateY(-1px); }

.btn-cancel {
  padding: 12px 20px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: none;
  color: var(--muted);
  font-family: 'Nunito', sans-serif;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--tr-fast);
}

.btn-cancel:hover { border-color: var(--pink); color: var(--pink); }

/* ── SCROLLBAR ───────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,79,216,.55); }

/* ── MOBILE ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    height: 100dvh;
    z-index: 100;
    width: 280px;
    transition: left var(--tr-mid), background var(--tr-slow);
  }

  .sidebar.open { left: 0; }
  .sidebar-toggle { display: flex; }
  .topbar { padding-left: 52px; }
  .messages { padding: 16px 16px 12px; }
  .input-area { padding: 10px 14px 14px; }
  .msg { max-width: 86%; }

  .setting-row { flex-direction: column; align-items: flex-start; gap: 10px; }
  .setting-input { width: 100%; }
  .pill-group { flex-wrap: wrap; }
}

/* ── SMOOTH COLOR TRANSITIONS ────────────────────────── */
.topbar, .sidebar-footer, .input-area, .modal,
.chat-item, .footer-btn, .setting-input, .pill {
  transition-property: background, border-color, color, box-shadow;
  transition-duration: 350ms;
  transition-timing-function: cubic-bezier(.4,0,.2,1);
}

.ai-image{
  width:100%;
  max-width:350px;
  border-radius:16px;
  display:block;
}