/* QuantumShade UX — Nexus interface optimized */

/* Root colors */
:root {
  --bg: #0e1116;
  --panel: #141a22;
  --accent: #2f6fed;
  --accent2: #9bb6ff;
  --muted: #96a0ae;
  --user: #8fb2ff;
  --assistant: #cbd6e2;
  --ok: #3abf8f;
  --warn: #e0b064;
  --err: #e36a6a;
}

/* Theme Variants */
body[data-theme="plasma"] {
  --accent: #5066f1;
  --accent2: #93a6ff;
  --assistant: #c9d1e1;
}
body[data-theme="crimson"] {
  --accent: #c0392b;
  --accent2: #e08b7a;
  --assistant: #d9c3be;
}

/* Base */
body.quantum {
  margin: 0;
  min-height: 100vh;
  font-family: "IBM Plex Sans", "Source Sans 3", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(1200px 700px at 10% -20%, rgba(47, 111, 237, 0.18), transparent 60%),
              radial-gradient(900px 600px at 110% 10%, rgba(155, 182, 255, 0.12), transparent 60%),
              linear-gradient(180deg, #0b0f14 0%, #0e1116 100%);
  color: #e6eef6;
}
* {
  box-sizing: border-box;
}

/* Startup overlay */
.startup-overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(900px 600px at 10% -20%, rgba(47, 111, 237, 0.2), transparent 60%),
              linear-gradient(180deg, #0b0f14 0%, #0e1116 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.startup-overlay.hidden {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}
.startup-card {
  width: 360px;
  padding: 24px 28px;
  border-radius: 16px;
  background: rgba(20, 26, 34, 0.9);
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 20px 50px rgba(0,0,0,0.6);
  text-align: center;
}
.startup-title {
  font-size: 20px;
  font-weight: 700;
  color: #d6e4ff;
  letter-spacing: 0.4px;
}
.startup-sub {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
}
.startup-bar {
  margin-top: 16px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
}
.startup-bar span {
  display: block;
  height: 100%;
  width: 40%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  animation: loading-sweep 1.2s ease-in-out infinite;
}
@keyframes loading-sweep {
  0% { transform: translateX(-100%); }
  50% { transform: translateX(80%); }
  100% { transform: translateX(220%); }
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(90deg, var(--panel), #0b121c);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}
.topbar .left, .topbar .right {
  display: flex;
  gap: 10px;
  align-items: center;
}
.title {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.4px;
}
.badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: rgba(47, 111, 237, 0.16);
  color: #d6e4ff;
  border: 1px solid rgba(47, 111, 237, 0.35);
}

/* Buttons */
button { cursor: pointer; }
.ghost {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #cfe8ff;
  padding: 8px 12px;
  border-radius: 12px;
}
.ghost:hover { border-color: rgba(255, 255, 255, 0.18); }

.outline {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 8px 12px;
  border-radius: 12px;
}
.outline:hover { background: rgba(0, 230, 255, 0.08); }

/* Creative Mode Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
}
.switch input { display: none; }
.slider {
  position: absolute;
  inset: 0;
  background: #2a3340;
  border-radius: 999px;
  transition: all 0.25s ease;
}
.slider:before {
  content: "";
  position: absolute;
  height: 20px;
  width: 20px;
  left: 4px;
  top: 4px;
  background: white;
  border-radius: 50%;
  transition: all 0.25s ease;
}
.switch input:checked + .slider { background: linear-gradient(90deg, var(--accent), var(--accent2)); }
.switch input:checked + .slider:before { transform: translateX(22px); }
.switch-label { font-size: 12px; color: var(--muted); margin-left: 6px; }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: minmax(250px, 18vw) minmax(0, 1fr);
  gap: 12px;
  width: 100%;
  height: calc(100vh - 62px);
  margin: 0;
  padding: 12px 14px 14px;
}
.panel {
  background: linear-gradient(180deg, #121821, #101722);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 16px;
  overflow: hidden;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0,0,0,0.4);
}
.panel.hidden { display: none; }
.panel-header, .panel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.panel-footer { border-top: 1px solid rgba(255,255,255,0.06); border-bottom: none; margin-top: auto; }

/* Signals */
.signals-list {
  padding: 12px 16px 6px 16px;
  display: grid;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.signal-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
}
.signal-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.signal-value {
  font-size: 12px;
  font-weight: 700;
  color: #d6e4ff;
}
.signal-value.ok {
  color: var(--ok);
}

/* Graph */
.graph { flex: 1; min-height: 320px; }

/* Chat App */
.app {
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0,0,0,0.6);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}
.app-main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(260px, 22vw) minmax(0, 1fr);
}
.chat-main {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.history-sidebar {
  border-right: 1px solid rgba(255,255,255,0.08);
  background: linear-gradient(180deg, rgba(9, 16, 28, 0.95), rgba(11, 19, 33, 0.88));
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.history-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px;
  font-size: 13px;
  font-weight: 700;
  color: #d6e4ff;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.history-actions {
  display: flex;
  gap: 6px;
}
.history-sidebar-header .ghost {
  padding: 5px 9px;
  font-size: 12px;
}
.history-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-list {
  scrollbar-width: thin;
  scrollbar-color: rgba(90, 126, 187, 0.65) rgba(9, 18, 34, 0.75);
}
.history-list::-webkit-scrollbar {
  width: 10px;
}
.history-list::-webkit-scrollbar-track {
  background: rgba(9, 18, 34, 0.75);
  border-radius: 999px;
}
.history-list::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(90, 126, 187, 0.9), rgba(55, 87, 147, 0.9));
  border-radius: 999px;
  border: 2px solid rgba(9, 18, 34, 0.75);
}
.history-item {
  width: 100%;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.03);
  border-radius: 10px;
  padding: 6px;
  color: #d6e4ff;
}
.history-item:hover {
  border-color: rgba(47,111,237,0.5);
  background: rgba(47,111,237,0.12);
}
.history-item.active {
  border-color: rgba(47,111,237,0.65);
  background: rgba(47,111,237,0.18);
}
.history-item-title {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}
.history-item-preview {
  font-size: 12px;
  line-height: 1.35;
  color: #e7f1ff;
  overflow-wrap: anywhere;
}
.history-open {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: inherit;
  padding: 4px 4px 6px 4px;
}
.history-item-controls {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  padding-top: 4px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.history-ctl {
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
  color: #d6e4ff;
  border-radius: 8px;
  padding: 2px 8px;
  font-size: 11px;
}
.history-ctl:hover {
  border-color: rgba(47,111,237,0.45);
  background: rgba(47,111,237,0.14);
}
.history-edit {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 4px 6px 4px;
}
.history-edit-input {
  width: 100%;
  padding: 7px 8px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.16);
  background: rgba(12, 19, 30, 0.9);
  color: #e6eef6;
  outline: none;
}
.history-edit-input:focus {
  border-color: rgba(47,111,237,0.55);
  box-shadow: 0 0 0 2px rgba(47,111,237,0.18);
}
.history-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}
.history-ctl.save {
  border-color: rgba(47,111,237,0.55);
}
.history-empty {
  border: 1px dashed rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.03);
  border-radius: 10px;
  padding: 10px;
  color: var(--muted);
  font-size: 12px;
}
.support-header {
  padding: 18px 22px 10px 22px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background: linear-gradient(180deg, rgba(20,26,34,0.95), rgba(20,26,34,0.7));
}
.support-head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.support-title {
  font-size: 16px;
  font-weight: 700;
  color: #d6e4ff;
}
.support-sub {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}
.chat-area {
  flex: 1;
  min-height: 0;
  padding: 24px 26px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.chat-area {
  scrollbar-width: thin;
  scrollbar-color: rgba(90, 126, 187, 0.7) rgba(10, 19, 36, 0.75);
}
.chat-area::-webkit-scrollbar {
  width: 11px;
}
.chat-area::-webkit-scrollbar-track {
  background: rgba(10, 19, 36, 0.75);
  border-radius: 999px;
}
.chat-area::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(110, 150, 220, 0.9), rgba(66, 102, 173, 0.9));
  border-radius: 999px;
  border: 2px solid rgba(10, 19, 36, 0.75);
}
.msg {
  max-width: min(860px, 78%);
  padding: 14px 16px;
  border-radius: 14px;
  line-height: 1.6;
  font-size: 14px;
  border: 1px solid transparent;
  backdrop-filter: blur(3px);
  animation: rise 0.25s ease both;
}
@keyframes rise { from { opacity:0; transform:translateY(6px);} to {opacity:1; transform:translateY(0);} }
.msg.user {
  align-self: flex-end;
  background: rgba(47,111,237,0.12);
  border-color: rgba(47,111,237,0.18);
  box-shadow: 0 3px 10px rgba(47,111,237,0.18);
}
.msg.assistant {
  align-self: flex-start;
  background: rgba(203,214,226,0.08);
  border-color: rgba(203,214,226,0.16);
  box-shadow: 0 3px 10px rgba(12,18,28,0.35);
}
.msg.system {
  align-self: center;
  max-width: 70%;
  background: rgba(255,255,255,0.03);
  border-color: rgba(255,255,255,0.08);
  color: var(--muted);
  font-size: 13px;
}
.msg .meta { font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.msg .content { white-space: pre-wrap; word-wrap: break-word; }

/* Sentiment glows */
.msg.happy { box-shadow: 0 0 18px rgba(60,240,165,0.3); border-color: rgba(60,240,165,0.4); }
.msg.sad   { box-shadow: 0 0 18px rgba(255,92,122,0.25); border-color: rgba(255,92,122,0.4); }
.msg.neutral { opacity: 0.97; }

/* Typing indicator */
.typing {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: rgba(255,255,255,0.03);
  border: 1px dashed rgba(255,255,255,0.08);
  border-radius: 12px;
  width: max-content;
}
.dots { display: inline-flex; gap: 6px; }
.dots span {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--accent);
  animation: blink 1.3s infinite both;
}
.dots span:nth-child(2) { animation-delay: .18s; }
.dots span:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%,80%,100% { opacity:0.25; transform: translateY(0);} 40% { opacity:1; transform: translateY(-2px);} }

/* Input row */
.chat-form {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  padding: 14px 16px;
  background: linear-gradient(90deg,#071021,#071021);
  border-top: 1px solid rgba(255,255,255,0.06);
}
.chat-form input {
  flex: 1;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.06);
  background: #0c131e;
  color: #e6eef6;
  outline: none;
}
.chat-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,230,255,0.14); }
.chat-form button {
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(133, 168, 235, 0.28);
  background: linear-gradient(180deg, rgba(20, 36, 64, 0.9), rgba(13, 25, 46, 0.9));
  color: #dceaff;
  font-weight: 700;
  letter-spacing: .1px;
  transition: border-color 0.2s ease, transform 0.15s ease, background 0.2s ease;
}
.chat-form .icon-btn {
  min-width: 44px;
  width: 44px;
  height: 42px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}
.chat-form button:hover {
  border-color: rgba(133, 168, 235, 0.5);
  background: linear-gradient(180deg, rgba(27, 46, 79, 0.95), rgba(16, 31, 56, 0.95));
}
.chat-form button:active {
  transform: translateY(1px);
}
.attachment-tray {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 16px 4px 16px;
}
.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.04);
  color: #d6e4ff;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  max-width: 360px;
  overflow: hidden;
}
.attachment-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attachment-chip button {
  border: none;
  background: transparent;
  color: #d6e4ff;
  cursor: pointer;
  font-size: 12px;
  padding: 0;
}

.input-note {
  flex: 0 0 auto;
  padding: 0 14px 12px 14px;
  font-size: 11px;
  color: var(--muted);
}

.quick-prompts {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 0 16px 14px 16px;
  flex-wrap: wrap;
}
.prompt-chip {
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
  color: #d6e4ff;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
}
.prompt-chip:hover {
  border-color: rgba(47,111,237,0.45);
  background: rgba(47,111,237,0.12);
}

.icon-btn {
  min-width: 44px;
  width: 44px;
  height: 42px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.send-btn {
  min-width: 44px;
  background: linear-gradient(90deg,var(--accent),var(--accent2));
  color: #071021;
  border-color: transparent;
}

/* Defensive: if an older template still includes URL button, hide it. */
#btnUrl {
  display: none !important;
}

.mic-btn {
  background: linear-gradient(180deg, rgba(20, 36, 64, 0.9), rgba(13, 25, 46, 0.9));
  color: #d6e4ff;
  border: 1px solid rgba(133, 168, 235, 0.28);
  font-weight: 600;
}
.mic-btn.active {
  background: linear-gradient(180deg, rgba(37, 75, 137, 0.95), rgba(29, 61, 113, 0.95));
  border-color: rgba(95, 141, 231, 0.7);
  color: #e6f0ff;
}

/* Drawer (Profile/Interface) */
.drawer {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: none;
  align-items: center;
  justify-content: flex-end;
  z-index: 30;
}
.drawer.open { display: flex; }
.drawer-content {
  width: 380px;
  height: 100%;
  background: #0a1018;
  border-left: 1px solid rgba(255,255,255,0.08);
  box-shadow: -12px 0 40px rgba(0,0,0,0.45);
  display: flex;
  flex-direction: column;
}
.drawer-header, .drawer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.drawer-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 14px; }
.field input, .field select {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
  background: #0c131e;
  color: #e6eef6;
}

/* Responsive */
@media (max-width: 960px){
  .layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: calc(100vh - 62px);
    padding: 10px;
  }
  .panel { order: 2; height: 42vh; }
  .app { order: 1; height: 72vh; }
  .app-main { grid-template-columns: 1fr; }
  .history-sidebar {
    border-right: none;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    max-height: 210px;
  }
  .chat-area { padding: 16px; }
  .msg { max-width: 92%; }
  .support-head-row { flex-direction: column; align-items: stretch; }
  #btnToggleHistory { align-self: flex-end; }
}

body.history-collapsed .app-main {
  grid-template-columns: minmax(0, 1fr);
}
body.history-collapsed .history-sidebar {
  display: none;
}
