/* Dahlia UI — Blended: original aesthetic + new features */
:root {
  --purple: #9333ea;
  --purple-light: #c084fc;
  --purple-glow: rgba(147, 51, 234, 0.4);
  --purple-dim: rgba(147, 51, 234, 0.15);
  --bg: #010101;
  --bg-header: linear-gradient(90deg, #010101, #151515);
  --bg-input: #0a0a0a;
  --bg-surface: rgba(255, 255, 255, 0.02);
  --border: rgba(255, 255, 255, 0.06);
  --border-purple: rgba(147, 51, 234, 0.2);
  --text: #e0e0e0;
  --text-dim: #999;
  --text-faint: #666;
  --radius: 16px;
  --sidebar-width: 280px;
}

[data-theme="light"] {
  --bg: #f5f5f7;
  --bg-header: linear-gradient(90deg, #f5f5f7, #eeeef0);
  --bg-input: #ffffff;
  --bg-surface: rgba(0, 0, 0, 0.03);
  --border: rgba(0, 0, 0, 0.08);
  --border-purple: rgba(147, 51, 234, 0.15);
  --text: #1a1a1a;
  --text-dim: #888;
  --text-faint: #bbb;
}

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

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Background video */
#bgvid {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  object-fit: cover; opacity: 0.15; z-index: 0; pointer-events: none;
}
[data-theme="light"] #bgvid { opacity: 0.06; }

/* === HEADER (original style) === */
header {
  position: relative; z-index: 2;
  padding: 16px 24px;
  background: var(--bg-header);
  border-bottom: 2px solid var(--purple);
  display: flex;
  align-items: center;
  gap: 14px;
}

header img.logo {
  width: 48px; height: 48px;
  object-fit: contain;
  filter: drop-shadow(0 0 10px var(--purple-glow));
}

.title-group { display: flex; flex-direction: column; }

header h1 {
  font-size: 22px; font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.provider-tag {
  font-size: 10px;
  color: var(--text-dim);
  background: var(--bg-surface);
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #333; transition: all 0.3s; }
.status-dot.on { background: var(--purple); box-shadow: 0 0 8px var(--purple-glow); }

.status-label { font-size: 12px; color: var(--text-dim); }
.status-label.on { color: var(--purple-light); }

/* Header action buttons */
.header-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  padding: 6px 8px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1;
}
.header-btn:hover { border-color: var(--border-purple); color: var(--purple-light); }

/* === MESSAGES === */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative; z-index: 1;
  scrollbar-width: thin;
  scrollbar-color: #222 transparent;
}
#messages::-webkit-scrollbar { width: 6px; }
#messages::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }

/* Message rows with avatars */
.msg-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: fi 0.2s ease-out;
}
.msg-row.user { justify-content: flex-end; }
.msg-row.bot { justify-content: flex-start; }

.msg-avatar {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  margin-top: 2px;
}
.msg-avatar img {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid rgba(147, 51, 234, 0.5);
  box-shadow: 0 0 20px var(--purple-glow), 0 0 40px rgba(147, 51, 234, 0.2);
  transition: transform 0.2s ease;
}
.msg-row.bot:hover .msg-avatar img {
  transform: scale(1.05);
  box-shadow: 0 0 25px var(--purple-glow), 0 0 50px rgba(147, 51, 234, 0.3);
}
.user-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #c084fc, #7c3aed);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid rgba(147, 51, 234, 0.5);
  box-shadow: 0 0 15px rgba(147, 51, 234, 0.3);
}

.msg {
  max-width: 78%;
  padding: 14px 18px;
  border-radius: var(--radius);
  line-height: 1.6;
  font-size: 14px;
  word-wrap: break-word;
}
.msg-row .msg { max-width: none; flex: 0 1 78%; }
@keyframes fi { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(147,51,234,0.25), rgba(147,51,234,0.1));
  color: #e8d5f5;
  border: 1px solid var(--border-purple);
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}

.msg.bot {
  align-self: flex-start;
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  border-left: 3px solid rgba(147, 51, 234, 0.5);
}

.msg.bot h2,.msg.bot h3,.msg.bot h4,.msg.bot h5 {
  color: var(--purple-light);
  margin: 16px 0 8px;
  font-weight: 600;
  line-height: 1.3;
}
.msg.bot h2:first-child,.msg.bot h3:first-child,.msg.bot h4:first-child,.msg.bot h5:first-child { margin-top: 0; }
.msg.bot h2 { font-size: 18px; }
.msg.bot h3 { font-size: 16px; }
.msg.bot h4 { font-size: 15px; }
.msg.bot h5 { font-size: 14px; }
.msg.bot strong { color: var(--purple-light); font-weight: 600; }
.msg.bot em { font-style: italic; color: var(--text); }
.msg.bot code {
  background: var(--purple-dim);
  padding: 3px 7px;
  border-radius: 4px;
  font-size: 13px;
  font-family: 'SF Mono','Fira Code','Consolas',monospace;
  color: var(--purple-light);
  border: 1px solid rgba(147, 51, 234, 0.2);
}
.msg.bot pre {
  background: rgba(0,0,0,0.5);
  padding: 14px 16px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 12px 0;
  border: 1px solid var(--border-purple);
}
.msg.bot pre code {
  background: none;
  padding: 0;
  border: none;
  color: var(--text);
}
.msg.bot ul,.msg.bot ol {
  padding-left: 24px;
  margin: 10px 0;
  line-height: 1.6;
}
.msg.bot li {
  margin: 6px 0;
  line-height: 1.5;
}
.msg.bot li::marker { color: var(--purple-light); }
.msg.bot table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.msg.bot th {
  background: var(--purple-dim);
  color: var(--purple-light);
  text-align: left;
  padding: 10px 14px;
  border: 1px solid var(--border-purple);
  font-weight: 600;
}
.msg.bot td {
  padding: 10px 14px;
  border: 1px solid var(--border);
}
.msg.bot tr:nth-child(even) td { background: var(--bg-surface); }
.msg.bot hr {
  border: none;
  border-top: 2px solid var(--border-purple);
  margin: 18px 0;
  opacity: 0.6;
}
.msg.bot a {
  color: var(--purple-light);
  text-decoration: underline;
  text-decoration-color: rgba(147,51,234,0.4);
  transition: color 0.2s ease;
}
.msg.bot a:hover {
  color: #d8b4fe;
  text-decoration-color: rgba(147,51,234,0.6);
}

.msg.sys { align-self: center; background: transparent; color: var(--text-dim); font-size: 12px; font-style: italic; }

/* Streaming cursor */
.msg.bot.streaming::after {
  content: '';
  display: inline-block;
  width: 2px; height: 16px;
  background: var(--purple-light);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* Thinking dots */
.think { align-self: flex-start; display: flex; gap: 6px; padding: 12px 18px; }
.think span { width: 8px; height: 8px; background: var(--purple-glow); border-radius: 50%; animation: pulse 1.4s ease-in-out infinite; }
.think span:nth-child(2) { animation-delay: .2s; }
.think span:nth-child(3) { animation-delay: .4s; }
@keyframes pulse { 0%,80%,100% { opacity: .3; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }

/* Tool execution cards */
.tool-card {
  align-self: flex-start;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--purple);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: fi 0.2s ease-out;
}
.tool-card .tool-icon { font-size: 14px; }
.tool-card .tool-name { font-weight: 600; color: var(--purple-light); }
.tool-card.done { border-left-color: #22c55e; }
.tool-card.error { border-left-color: #ef4444; }

/* === INPUT AREA (original style) === */
#input-area {
  position: relative; z-index: 1;
  padding: 16px 24px;
  background: linear-gradient(90deg, var(--bg-input), #111);
  border-top: 1px solid rgba(147, 51, 234, 0.15);
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

#inp {
  flex: 1;
  padding: 14px 18px;
  background: var(--bg-surface);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  color: var(--text);
  font-size: 14px;
  font-family: 'Inter', sans-serif;
  outline: none;
  resize: none;
  min-height: 48px;
  max-height: 140px;
  transition: border-color 0.2s;
}
#inp:focus { border-color: rgba(147,51,234,0.5); box-shadow: 0 0 0 2px rgba(147,51,234,0.1); }
#inp::placeholder { color: var(--text-faint); }

.input-btn {
  padding: 14px 16px;
  background: var(--bg-surface);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1;
}
.input-btn:hover { border-color: rgba(147,51,234,0.5); color: var(--purple-light); }
.input-btn:disabled { opacity: 0.3; cursor: not-allowed; }

#send-btn {
  padding: 14px 28px;
  background: linear-gradient(135deg, hsl(270,70%,45%) 0%, hsl(270,70%,38%) 100%);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.02em;
}
#send-btn:hover { background: linear-gradient(135deg, hsl(270,70%,52%) 0%, hsl(270,70%,45%) 100%); transform: translateY(-1px); }
#send-btn:active { transform: translateY(0); }
#send-btn:disabled { opacity: 0.3; cursor: not-allowed; transform: none; }

/* === SIDEBAR (hidden by default, slides in from left) === */
#sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: #0a0a0b;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  box-shadow: 4px 0 24px rgba(0,0,0,0.5);
}
#sidebar.open { transform: translateX(0); }

#sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}
#sidebar-overlay.open { display: block; }

#sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
#sidebar-header img { width: 28px; height: 28px; filter: drop-shadow(0 0 4px var(--purple-glow)); }
#sidebar-header h2 { font-size: 15px; font-weight: 600; color: var(--text); }
#sidebar-close { margin-left: auto; background: none; border: none; color: var(--text-dim); font-size: 18px; cursor: pointer; }

.sidebar-new-btn {
  margin: 12px 16px 8px;
  padding: 10px;
  background: linear-gradient(135deg, var(--purple), hsl(270,70%,38%));
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.sidebar-new-btn:hover { filter: brightness(1.15); }

#sidebar-search {
  margin: 0 16px 8px;
  padding: 8px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}
#sidebar-search::placeholder { color: var(--text-faint); }

#conv-list { flex: 1; overflow-y: auto; padding: 4px 8px; }

.conv-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-dim);
  transition: all 0.15s;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-item:hover { background: var(--bg-surface); color: var(--text); }
.conv-item.active { background: var(--purple-dim); color: var(--purple-light); }

#sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: center;
}

.theme-btn {
  padding: 6px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
}
.theme-btn:hover { color: var(--purple-light); }

/* === ACTIVITY PANEL (slides in from right) === */
#activity-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 300px;
  max-width: 85%;
  background: #0a0a0b;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  box-shadow: -4px 0 24px rgba(0,0,0,0.5);
}
#activity-panel.open { transform: translateX(0); }

#activity-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 600;
}
#activity-close { background: none; border: none; color: var(--text-dim); font-size: 18px; cursor: pointer; }

#activity-list { flex: 1; overflow-y: auto; padding: 12px; }

.activity-item {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  font-size: 12px;
}
.activity-item .label { font-weight: 600; color: var(--purple-light); margin-bottom: 4px; }
.activity-item .detail { color: var(--text-dim); }

/* === AGENT STREAM PANEL === */
.agent-stream-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  margin: 8px 0;
  max-width: 480px;
}

.agent-step {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 13px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  transition: opacity 0.3s, color 0.3s;
}

.agent-step:last-child { border-bottom: none; }

.agent-step .step-icon {
  flex-shrink: 0;
  font-size: 14px;
  width: 20px;
  text-align: center;
}

.agent-step.running { color: var(--purple-light); }
.agent-step.done { color: var(--text-dim); opacity: 0.8; }
.agent-step.error { color: #ef4444; }

.agent-step.running .step-icon {
  animation: pulse-icon 1.2s ease-in-out infinite;
}

@keyframes pulse-icon {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Settings select */
#model-select option { background: #1c1c20; color: #e0e0e0; }
[data-theme="light"] #model-select { background: #fff; color: #1a1a1a; }
[data-theme="light"] #model-select option { background: #fff; color: #1a1a1a; }

/* File preview modal scrollbar */
#file-preview-modal > div { scrollbar-width: thin; scrollbar-color: #333 transparent; }

/* === MOBILE === */
@media (max-width: 640px) {
  .msg { max-width: 90%; }
  #input-area { padding: 12px 16px; }
  header { padding: 12px 16px; }
  #messages { padding: 16px; }
  .provider-tag { display: none; }
}

/* === LOGIN SCREEN === */
#login-screen {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 500;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}
#login-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.login-container {
  text-align: center;
  padding: 48px;
  max-width: 360px;
  width: 90%;
}

.login-logo {
  width: 96px;
  height: 96px;
  object-fit: contain;
  filter: drop-shadow(0 0 30px var(--purple-glow)) drop-shadow(0 0 60px rgba(147, 51, 234, 0.2));
  margin-bottom: 24px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.login-title {
  font-size: 36px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.03em;
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  margin-bottom: 40px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#login-password {
  padding: 14px 18px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 14px;
  font-family: 'Inter', sans-serif;
  outline: none;
  text-align: center;
  transition: border-color 0.2s;
}
#login-password:focus {
  border-color: rgba(147, 51, 234, 0.5);
  box-shadow: 0 0 0 2px rgba(147, 51, 234, 0.1);
}
#login-password::placeholder { color: var(--text-faint); }

#login-btn {
  padding: 14px;
  background: linear-gradient(135deg, hsl(270,70%,45%) 0%, hsl(270,70%,38%) 100%);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.02em;
}
#login-btn:hover {
  background: linear-gradient(135deg, hsl(270,70%,52%) 0%, hsl(270,70%,45%) 100%);
  transform: translateY(-1px);
}
#login-btn:active { transform: translateY(0); }
#login-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.login-error {
  color: #ef4444;
  font-size: 13px;
  min-height: 20px;
  margin-top: 8px;
}


/* Logout button in sidebar */
.logout-btn {
  margin-left: auto;
  padding: 6px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 11px;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1;
}
.logout-btn:hover {
  color: var(--purple-light);
}
