/* River Point Technology — Vault Expert Chat */

:root {
  /* RPT Brand Colors */
  --rpt-blue: #324251;       /* Primary dark blue */
  --rpt-orange: #F47E20;     /* Key brand orange */
  --accent-blue-1: #1D3558;  /* Dark navy */
  --accent-blue-2: #1D416B;  /* Navy */
  --bright-blue: #3970D3;    /* Links/interactive (use sparingly) */
  --light-blue: #8AB1F7;     /* Light blue backgrounds */
  --faded-orange: #FDE5D2;   /* Faded orange tint */
  --light-grey: #E7E6E6;     /* Light grey */
  --dark-grey: #929396;      /* Secondary text */

  --bg: #E7E6E6;
  --surface: #FEFEFE;
  --surface-muted: #FDE5D2;
  --border: rgba(50, 66, 81, 0.2);
  --border-subtle: rgba(50, 66, 81, 0.1);
  --text: #324251;
  --text-muted: #929396;
  --text-light: #b0b3b8;
  --accent: #3970D3;
  --accent-hover: #1D416B;
  --accent-light: #8AB1F7;
  --brand-dark: #324251;
  --brand-orange: #F47E20;
  --error: #E10F0F;
  --error-bg: rgba(225, 15, 15, 0.08);
  --success: #019C48;
  --warning: #F47E20;
  --user-msg-bg: #FDE5D2;
  --user-msg-border: rgba(244, 126, 32, 0.35);
  --assistant-msg-bg: #FEFEFE;
  --code-bg: #1D3558;
  --code-text: #FEFEFE;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 4px;
  --font: "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --sidebar-width: 240px;
  --header-height: auto;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
}

/* ── Layout ─────────────────────────────────────────── */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

/* ── Header ──────────────────────────────────────────── */

.header {
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.875rem 1.25rem 0.75rem;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.sidebar-toggle:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.sidebar-toggle:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#Logo--Header {
  display: block;
  flex-shrink: 0;
  line-height: 0;
  text-decoration: none;
}

#Logo--Header svg {
  width: 44px;
  height: 44px;
  display: block;
  flex-shrink: 0;
}

#Logo--Header .art--right { fill: var(--brand-dark); }
#Logo--Header .art--left  { fill: var(--brand-orange); }
#Logo--Header .lettermark { fill: var(--text); }

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.brand-name {
  font-size: 1rem;
  font-weight: 650;
  color: var(--text);
  letter-spacing: 0.01em;
  line-height: 1.2;
}

.brand-tagline {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.2;
}

.subtitle {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ── Health Indicator ────────────────────────────────── */

.health-indicator {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.health-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-light);
  flex-shrink: 0;
  transition: background 0.3s;
}

.health-dot--checking {
  background: var(--warning);
  animation: pulse 1.5s ease-in-out infinite;
}

.health-dot--connected {
  background: var(--success);
}

.health-dot--error {
  background: var(--error);
}

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

/* ── Workspace (sidebar + main) ──────────────────────── */

.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

/* ── Sidebar ─────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--surface-muted);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.22s ease, opacity 0.22s ease;
}

.sidebar.is-collapsed {
  width: 0;
  opacity: 0;
  pointer-events: none;
}

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

.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--font);
  color: var(--accent);
  background: var(--accent-light);
  border: 1px solid rgba(57, 112, 211, 0.3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.new-chat-btn:hover {
  background: rgba(57, 112, 211, 0.25);
  color: var(--accent-hover);
}

.new-chat-btn:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-list::-webkit-scrollbar { width: 4px; }
.chat-list::-webkit-scrollbar-track { background: transparent; }
.chat-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.chat-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: background 0.12s;
}

.chat-item:hover {
  background: var(--border-subtle);
}

.chat-item.active {
  background: var(--accent-light);
}

.chat-item-btn {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.6rem;
  font-size: 0.82rem;
  font-family: var(--font);
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item.active .chat-item-btn {
  color: var(--accent);
  font-weight: 500;
}

.chat-delete-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  margin-right: 4px;
  font-size: 1rem;
  line-height: 1;
  color: var(--text-light);
  background: none;
  border: none;
  border-radius: var(--radius-xs);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s, color 0.12s, background 0.12s;
}

.chat-item:hover .chat-delete-btn,
.chat-item.active .chat-delete-btn {
  opacity: 1;
}

.chat-delete-btn:hover {
  color: var(--error);
  background: var(--error-bg);
}

.chat-delete-btn:focus {
  opacity: 1;
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ── Main chat area ──────────────────────────────────── */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.5rem;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Empty state ─────────────────────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  height: 100%;
  min-height: 200px;
  color: var(--text-light);
  text-align: center;
  padding: 2rem;
}

.empty-state svg {
  opacity: 0.4;
}

.empty-state p {
  margin: 0;
  font-size: 0.9rem;
}

/* ── Messages ────────────────────────────────────────── */

.message {
  margin-bottom: 1.125rem;
  max-width: 100%;
}

.message-meta {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 0.3rem;
  color: var(--text-muted);
}

.message.user .message-meta {
  color: var(--accent);
  text-align: right;
}

.message-bubble {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  box-shadow: var(--shadow-sm);
  word-break: break-word;
  overflow-x: auto;
}

.message.user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.message.user .message-bubble {
  background: var(--user-msg-bg);
  border-color: var(--user-msg-border);
  border-radius: var(--radius) var(--radius-xs) var(--radius) var(--radius);
  max-width: 80%;
}

.message.assistant .message-bubble {
  background: var(--assistant-msg-bg);
  border-color: var(--border-subtle);
  border-radius: var(--radius-xs) var(--radius) var(--radius) var(--radius);
}

/* ── Message content (markdown) ──────────────────────── */

.message-bubble .content {
  white-space: normal;
}

.message-bubble .content pre,
.message-bubble .content code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.84rem;
}

.message-bubble .content pre {
  white-space: pre-wrap;
  background: var(--code-bg);
  color: var(--code-text);
  padding: 0.875rem 1rem;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 0.6rem 0;
  line-height: 1.5;
}

.message-bubble .content code {
  padding: 0.15em 0.45em;
  border-radius: var(--radius-xs);
  background: rgba(50, 66, 81, 0.1);
  color: var(--brand-dark);
  font-size: 0.875em;
}

.message.user .message-bubble .content code {
  background: rgba(244, 126, 32, 0.15);
  color: var(--rpt-blue);
}

.message-bubble .content pre code {
  padding: 0;
  background: transparent;
  color: inherit;
  font-size: inherit;
}

.message-bubble .content p { margin: 0 0 0.5rem 0; }
.message-bubble .content p:last-child { margin-bottom: 0; }

.message-bubble .content h1,
.message-bubble .content h2,
.message-bubble .content h3,
.message-bubble .content h4,
.message-bubble .content h5,
.message-bubble .content h6 {
  margin: 0.85rem 0 0.4rem 0;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
}
.message-bubble .content h1:first-child,
.message-bubble .content h2:first-child,
.message-bubble .content h3:first-child,
.message-bubble .content h4:first-child { margin-top: 0; }
.message-bubble .content h1 { font-size: 1.25rem; }
.message-bubble .content h2 { font-size: 1.1rem; }
.message-bubble .content h3 { font-size: 1rem; }
.message-bubble .content h4,
.message-bubble .content h5,
.message-bubble .content h6 { font-size: 0.9rem; }

.message-bubble .content ul,
.message-bubble .content ol {
  margin: 0.4rem 0;
  padding-left: 1.5rem;
}
.message-bubble .content li { margin-bottom: 0.2rem; }
.message-bubble .content ul { list-style-type: disc; }
.message-bubble .content ol { list-style-type: decimal; }

.message-bubble .content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.75rem 0;
}

.message-bubble .content blockquote {
  margin: 0.5rem 0;
  padding: 0.35rem 0 0.35rem 0.875rem;
  border-left: 3px solid var(--border);
  color: var(--text-muted);
  font-style: italic;
}

.message-bubble .content a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.message-bubble .content a:hover { color: var(--accent-hover); }

.message-bubble .content table {
  border-collapse: collapse;
  margin: 0.6rem 0;
  width: 100%;
  font-size: 0.875rem;
}
.message-bubble .content thead { background: rgba(57, 112, 211, 0.07); }
.message-bubble .content th,
.message-bubble .content td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.7rem;
  text-align: left;
  vertical-align: top;
}
.message-bubble .content th { font-weight: 600; white-space: nowrap; }
.message-bubble .content tbody tr:nth-child(even) { background: rgba(57, 112, 211, 0.03); }
.message-bubble .content tbody tr:hover { background: rgba(57, 112, 211, 0.06); }

/* ── Sources ─────────────────────────────────────────── */

.sources {
  margin-top: 0.75rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.sources-toggle {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  width: 100%;
  padding: 0.2rem 0;
  margin: 0;
  font-size: inherit;
  font-weight: 600;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  border-radius: var(--radius-xs);
  font-family: var(--font);
}

.sources-toggle:hover { color: var(--text); }

.sources-toggle:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sources-chevron {
  display: inline-block;
  font-size: 0.6rem;
  transition: transform 0.2s ease;
  transform: rotate(-90deg);
}

.sources-chevron::before { content: "▼"; }

.sources.is-expanded .sources-chevron { transform: rotate(0); }

.sources-list {
  display: none;
  margin-top: 0.4rem;
}

.sources.is-expanded .sources-list { display: block; }

.sources-title { flex: 1; }

.source-item {
  padding: 0.2rem 0;
  border-bottom: 1px solid var(--border-subtle);
  line-height: 1.4;
}

.source-item:last-child { border-bottom: none; }

.source-item .type {
  display: inline-block;
  padding: 0.1em 0.45em;
  border-radius: var(--radius-xs);
  background: var(--border-subtle);
  border: 1px solid var(--border);
  margin-right: 0.35rem;
  font-size: 0.72rem;
  font-weight: 500;
}

/* ── Loading ─────────────────────────────────────────── */

.loading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1.5rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.loading-dots::after {
  content: "";
  animation: dots 1.2s steps(4, end) infinite;
}

@keyframes dots {
  0%, 20% { content: "."; }
  40%      { content: ".."; }
  60%, 100% { content: "..."; }
}

/* ── Error ───────────────────────────────────────────── */

.error {
  padding: 0.65rem 1rem;
  background: var(--error-bg);
  border: 1px solid rgba(225, 15, 15, 0.3);
  border-radius: var(--radius-sm);
  color: var(--error);
  margin: 0 1.5rem 0.5rem;
  font-size: 0.875rem;
}

/* ── Input row ───────────────────────────────────────── */

.input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.input-row input {
  flex: 1;
  padding: 0.65rem 1rem;
  font-size: 0.9375rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 24px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input-row input:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(57, 112, 211, 0.15);
}

.input-row input::placeholder { color: var(--text-light); }

.input-row button[type="submit"] {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  color: #fff;
  background: var(--brand-dark);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.input-row button[type="submit"]:hover {
  background: var(--accent);
  transform: scale(1.05);
}

.input-row button[type="submit"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.input-row button[type="submit"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Utility ─────────────────────────────────────────── */

.hidden { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ── Mobile sidebar overlay ─────────────────────────── */

.sidebar-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 199;
}

.sidebar-overlay.is-visible {
  display: block;
}

/* ── Responsive ──────────────────────────────────────── */

@media (max-width: 700px) {
  .app { height: 100svh; }

  .sidebar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 200;
    box-shadow: var(--shadow-md);
  }

  .sidebar.is-collapsed {
    width: 0;
    box-shadow: none;
  }

  .messages { padding: 1rem; }
  .input-row { padding: 0.625rem 0.875rem; }
  .message.user .message-bubble { max-width: 90%; }

  .brand-name { font-size: 0.875rem; }
  .subtitle { display: none; }
}

@media (min-width: 701px) {
  /* Sidebar always visible on desktop; toggle just collapses it */
  .sidebar { position: relative; }
}

/* ── Dark mode (system preference) ──────────────────── */

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111d2b;
    --surface: #1D3558;
    --surface-muted: #243d58;
    --border: rgba(255, 255, 255, 0.1);
    --border-subtle: rgba(255, 255, 255, 0.06);
    --text: #FEFEFE;
    --text-muted: #b4b8c0;
    --text-light: #929396;
    --accent: #8AB1F7;
    --accent-hover: #FDE5D2;
    --accent-light: rgba(138, 177, 247, 0.15);
    --brand-dark: #3970D3;
    --user-msg-bg: rgba(244, 126, 32, 0.18);
    --user-msg-border: rgba(244, 126, 32, 0.4);
    --assistant-msg-bg: rgba(29, 65, 107, 0.5);
    --error-bg: rgba(225, 15, 15, 0.15);
    --code-bg: #0d1724;
    --code-text: #FEFEFE;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
  }
}
