:root {
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-soft: #eff4ff;
  --accent: #0ea5e9;
  --ink: #0f172a;
  --ink-soft: #475569;
  --surface: #ffffff;
  --canvas: #f1f5f9;
  --border: #e2e8f0;
  --border-soft: #eef2f6;
  --assistant-bubble: #ffffff;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
  --radius-lg: 18px;
  --radius-md: 12px;
  --font:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --left-width: 540px;
  --chat-height: 56vh;
}

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

html {
  height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--canvas);
}

/* ------------------------------------------------------------------ */
/* Left column (chat on top, file explorer below)                       */
/* ------------------------------------------------------------------ */
.left-column {
  width: var(--left-width);
  min-width: 280px;
  max-width: 70vw;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

/* ------------------------------------------------------------------ */
/* Chat widget                                                          */
/* ------------------------------------------------------------------ */
.chat-container {
  flex: 0 0 auto;
  height: var(--chat-height);
  max-height: 85vh;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

/* --- header --- */
.chat-header {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border-soft);
  background: linear-gradient(180deg, #ffffff 0%, #fafbfd 100%);
  flex: 0 0 auto;
}

.chat-avatar {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: #fff;
  letter-spacing: 0.02em;
  background: linear-gradient(135deg, var(--brand) 0%, var(--accent) 100%);
  box-shadow: 0 3px 8px rgba(37, 99, 235, 0.28);
}

.chat-header-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-title {
  font-weight: 650;
  font-size: 0.98rem;
  color: var(--ink);
}

.chat-subtitle {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.76rem;
  color: var(--ink-soft);
  margin-top: 1px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.18);
  animation: pulse 2.4s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.18);
  }
  50% {
    box-shadow: 0 0 0 5px rgba(34, 197, 94, 0.05);
  }
}

/* --- messages --- */
.chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background:
    radial-gradient(1200px 400px at 50% -10%, rgba(37, 99, 235, 0.04), transparent),
    #f8fafc;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
  width: 8px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: content-box;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
  background-clip: content-box;
}

.message {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  animation: rise 0.28s ease both;
}

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

.message.user {
  flex-direction: row-reverse;
}

/* --- avatars --- */
.avatar {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-weight: 700;
  color: #fff;
  user-select: none;
}

.assistant-avatar {
  background: linear-gradient(135deg, #0f766e 0%, #0ea5e9 100%);
  box-shadow: var(--shadow-sm);
}

.user .avatar {
  display: none;
}

/* --- bubbles --- */
.bubble {
  max-width: 82%;
  padding: 0.62rem 0.9rem;
  border-radius: var(--radius-lg);
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
  font-size: 0.93rem;
  position: relative;
}

.message.assistant .bubble {
  background: var(--assistant-bubble);
  color: var(--ink);
  border: 1px solid var(--border-soft);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-sm);
}

.message.user .bubble {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: 0 3px 10px rgba(37, 99, 235, 0.28);
}

/* --- bubble typography (assistant markdown) --- */
.bubble h2,
.bubble h3,
.bubble h4 {
  margin: 0.5rem 0 0.3rem;
  font-weight: 650;
  line-height: 1.35;
}

.bubble h2 {
  font-size: 1.06rem;
}

.bubble h3 {
  font-size: 1rem;
}

.bubble h4 {
  font-size: 0.95rem;
}

.bubble p {
  margin: 0.25rem 0;
}

.bubble ul,
.bubble ol {
  margin: 0.3rem 0 0.3rem 1.2rem;
}

.bubble li {
  margin: 0.15rem 0;
}

.bubble a {
  color: var(--brand);
  text-decoration: none;
  border-bottom: 1px solid rgba(37, 99, 235, 0.3);
}

.bubble a:hover {
  border-bottom-color: var(--brand);
}

.bubble code {
  background: rgba(15, 23, 42, 0.06);
  padding: 0.1rem 0.35rem;
  border-radius: 5px;
  font-family: var(--mono);
  font-size: 0.84em;
}

.message.user .bubble code {
  background: rgba(255, 255, 255, 0.22);
}

.bubble pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  overflow-x: auto;
  margin: 0.5rem 0;
}

.bubble pre code {
  background: transparent;
  padding: 0;
  color: inherit;
  font-size: 0.82rem;
  line-height: 1.5;
}

.bubble blockquote {
  border-left: 3px solid var(--border);
  padding-left: 0.7rem;
  color: var(--ink-soft);
  margin: 0.4rem 0;
}

/* --- streaming cursor --- */
.stream-cursor {
  display: inline-block;
  width: 7px;
  height: 1.05em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: currentColor;
  border-radius: 1px;
  animation: blink 0.9s step-end infinite;
}

@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

/* --- typing indicator (three bouncing dots) --- */
.typing .bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0.85rem 1rem;
}

.dot {
  width: 7px;
  height: 7px;
  background: #94a3b8;
  border-radius: 50%;
  animation: typingBlink 1.2s infinite ease-in-out;
}

.dot:nth-child(2) {
  animation-delay: 0.18s;
}

.dot:nth-child(3) {
  animation-delay: 0.36s;
}

@keyframes typingBlink {
  0%,
  60%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* --- input --- */
.chat-input {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.7rem 0.8rem;
  border-top: 1px solid var(--border-soft);
  background: #ffffff;
  flex: 0 0 auto;
}

.chat-input textarea {
  flex: 1;
  resize: none;
  max-height: 132px;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 22px;
  font-family: var(--font);
  font-size: 0.93rem;
  line-height: 1.4;
  outline: none;
  background: #f8fafc;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    background 0.15s ease;
}

.chat-input textarea:focus {
  border-color: var(--brand);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.chat-input textarea:disabled {
  opacity: 0.6;
}

.chat-input button {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 10px rgba(37, 99, 235, 0.32);
  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease,
    opacity 0.12s ease;
}

.chat-input button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 5px 14px rgba(37, 99, 235, 0.38);
}

.chat-input button:active:not(:disabled) {
  transform: translateY(0);
}

.chat-input button:disabled {
  background: #cbd5e1;
  box-shadow: none;
  cursor: not-allowed;
}

/* ------------------------------------------------------------------ */
/* File explorer (below chat)                                           */
/* ------------------------------------------------------------------ */
.file-explorer {
  flex: 1 1 auto;
  padding: 0.9rem 1rem;
  background: #f8fafc;
  overflow-y: auto;
  min-height: 0;
}

.file-explorer h3 {
  margin-bottom: 0.5rem;
  font-size: 0.82rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
}

.file-explorer ul {
  list-style: none;
}

.file-explorer li {
  margin: 0.2rem 0;
}

.file-explorer a {
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  font-size: 0.87rem;
  display: block;
  padding: 0.3rem 0.5rem;
  border-radius: 8px;
  transition: background 0.12s ease;
}

.file-explorer a:hover {
  background: var(--brand-soft);
  color: var(--brand);
}

/* ------------------------------------------------------------------ */
/* Right-side file viewer                                               */
/* ------------------------------------------------------------------ */
.file-viewer {
  flex: 1 1 auto;
  padding: 1.2rem 1.4rem;
  background: #ffffff;
  overflow-y: auto;
  min-width: 0;
}

.file-viewer h2 {
  margin-bottom: 0.5rem;
  font-size: 1.05rem;
  font-weight: 650;
}

.file-viewer p {
  color: var(--ink-soft);
  font-size: 0.9rem;
}

#divFileContents {
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 0.83rem;
  line-height: 1.55;
  color: #1e293b;
  margin-top: 0.75rem;
}

/* ------------------------------------------------------------------ */
/* Split-pane resizers (draggable dividers)                            */
/* ------------------------------------------------------------------ */
.resizer {
  flex: 0 0 auto;
  background: transparent;
  position: relative;
  z-index: 10;
  touch-action: none;
  transition: background 0.15s ease;
}

.resizer-v {
  width: 6px;
  cursor: col-resize;
}

.resizer-h {
  height: 6px;
  cursor: row-resize;
}

.resizer:hover,
.resizer.active {
  background: rgba(37, 99, 235, 0.14);
}

/* centered grip line that appears on hover / drag */
.resizer::after {
  content: "";
  position: absolute;
  background: var(--brand);
  opacity: 0;
  transition: opacity 0.15s ease;
}

.resizer-v::after {
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
}

.resizer-h::after {
  left: 0;
  right: 0;
  top: 50%;
  height: 2px;
  transform: translateY(-50%);
}

.resizer:hover::after,
.resizer.active::after {
  opacity: 0.9;
}

/* lock text selection + cursor while dragging */
body.resizing {
  user-select: none;
  -webkit-user-select: none;
}

body.resizing-v,
body.resizing-v * {
  cursor: col-resize !important;
}

body.resizing-h,
body.resizing-h * {
  cursor: row-resize !important;
}

/* ------------------------------------------------------------------ */
/* Responsive: stack columns on narrow screens                          */
/* ------------------------------------------------------------------ */
@media (max-width: 860px) {
  body {
    flex-direction: column;
  }

  .left-column {
    width: 100%;
    min-width: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .chat-container {
    height: 60vh;
    max-height: 560px;
    min-height: 320px;
  }

  .file-viewer {
    min-height: 60vh;
  }

  .resizer-v,
  .resizer-h {
    display: none;
  }
}
