/*
 * DYLAN — BVH IT Support Assistant · "Liquid Glass" (Omni suite standard)
 *
 * Values taken from:
 *   e:\Omni-ITM\docs\SUITE-DESIGN-AND-INFRASTRUCTURE.md  (Part 1, 1.1–1.6)
 *   e:\Omni-ITM\apps\frontend\src\styles\liquid-glass.css + theme.css
 *
 * THEMING — every colour, blur and radius is a :root custom property.
 * Resolution order (later / more specific wins):
 *   1. :root                                -> light defaults
 *   2. @media (prefers-color-scheme: dark)  -> follow the OS
 *   3. :root[data-theme="light|dark"]       -> explicit choice beats the OS
 */

/* ═══ 1. TOKENS ══════════════════════════════════════════ */

:root {
  /* Ground / ambient wash */
  --ground: #f4f6fb;
  --blob-1: rgba(129, 140, 248, 0.16);
  --blob-2: rgba(240, 171, 252, 0.13);
  --blob-3: rgba(56, 189, 248, 0.10);

  /* Glass surfaces */
  --glass-fill: rgba(255, 255, 255, 0.55);
  --glass-fill-strong: rgba(255, 255, 255, 0.72);
  --glass-fill-soft: rgba(255, 255, 255, 0.42);
  --glass-fill-60: rgba(255, 255, 255, 0.60);
  --glass-fill-65: rgba(255, 255, 255, 0.65);
  --glass-border: rgba(255, 255, 255, 0.70);
  --glass-border-soft: rgba(255, 255, 255, 0.55);
  --glass-border-bright: rgba(255, 255, 255, 0.85);
  --specular: rgba(255, 255, 255, 0.90);
  --specular-soft: rgba(255, 255, 255, 0.45);

  /* Shadow base — used as rgba(var(--shadow-rgb), a) */
  --shadow-rgb: 15, 23, 42;

  /* Text */
  --ink: #0f172a;
  --text: #1e293b;
  --text-2: #334155;
  --text-3: #475569;
  --muted: #64748b;
  --faint: #94a3b8;

  /* Hairlines */
  --hairline: rgba(15, 23, 42, 0.06);
  --hairline-strong: rgba(15, 23, 42, 0.10);

  /* Accent (indigo) */
  --accent-2: #6366f1;
  --accent-soft: rgba(99, 102, 241, 0.12);
  --accent-border: rgba(99, 102, 241, 0.40);

  /* Brand / hero gradient + link blue (constant across themes) */
  --hero-a: #667eea;
  --hero-b: #764ba2;
  --info: #3b82f6;
  --info-strong: #2563eb;

  /* Chip fills / inks */
  --chip-blue-bg: rgba(219, 234, 254, 0.80);   --chip-blue-fg: #1d4ed8;
  --chip-green-bg: rgba(220, 252, 231, 0.80);  --chip-green-fg: #15803d;
  --chip-amber-bg: rgba(254, 243, 199, 0.80);  --chip-amber-fg: #b45309;
  --chip-red-bg: rgba(254, 226, 226, 0.80);    --chip-red-fg: #b91c1c;
  --chip-violet-bg: rgba(237, 233, 254, 0.80); --chip-violet-fg: #6d28d9;

  /* Code surfaces */
  --code-bg: #1e1e2e;
  --code-fg: #cdd6f4;
  --code-head-bg: #181825;
  --code-head-fg: #9aa5b1;
  --code-inline-bg: rgba(99, 102, 241, 0.10);
  --code-inline-fg: #4338ca;

  /* Blur + saturation */
  --blur-shell: 42px;   --sat-shell: 180%;
  --blur-panel: 20px;   --sat-panel: 150%;
  --blur-dock: 24px;    --sat-dock: 160%;
  --blur-overlay: 18px; --sat-overlay: 140%;
  --blur-field: 10px;

  /* Radii */
  --radius-shell: 32px;
  --radius-tab: 24px;
  --radius-panel: 22px;
  --radius-row: 18px;
  --radius-card: 14px;
  --radius-sm: 10px;
  --radius-pill: 999px;

  /* Elevation */
  --shadow-shell: 0 32px 90px rgba(var(--shadow-rgb), 0.35), inset 0 1px 0 var(--specular), inset 0 -1px 0 var(--specular-soft);
  --shadow-panel: 0 6px 22px rgba(var(--shadow-rgb), 0.06), inset 0 1px 0 var(--specular);
  --shadow-dock: 0 12px 34px rgba(var(--shadow-rgb), 0.12), inset 0 1px 0 var(--specular);
  --shadow-lift: 0 12px 30px rgba(var(--shadow-rgb), 0.12), inset 0 1px 0 var(--specular);

  /* Layout */
  --sidebar-width: 280px;
  --header-height: 56px;
  --content-max: 820px;
  --gutter: 20px;

  /* Typography */
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'SF Mono', Consolas, 'Liberation Mono', monospace;

  /* Motion */
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-rise: cubic-bezier(0.21, 1.02, 0.73, 1);

  color-scheme: light;
}

/* Follow the OS when the user hasn't chosen */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #0a0e1a;
    --blob-1: rgba(129, 140, 248, 0.20);
    --blob-2: rgba(217, 70, 239, 0.14);
    --blob-3: rgba(56, 189, 248, 0.14);

    --glass-fill: rgba(30, 41, 59, 0.55);
    --glass-fill-strong: rgba(30, 41, 59, 0.74);
    --glass-fill-soft: rgba(30, 41, 59, 0.42);
    --glass-fill-60: rgba(30, 41, 59, 0.60);
    --glass-fill-65: rgba(30, 41, 59, 0.66);
    --glass-border: rgba(148, 163, 184, 0.18);
    --glass-border-soft: rgba(148, 163, 184, 0.12);
    --glass-border-bright: rgba(148, 163, 184, 0.26);
    --specular: rgba(255, 255, 255, 0.08);
    --specular-soft: rgba(255, 255, 255, 0.05);

    --shadow-rgb: 0, 0, 0;

    --ink: #f1f5f9;
    --text: #e2e8f0;
    --text-2: #cbd5e1;
    --text-3: #b6c2d4;
    --muted: #94a3b8;
    --faint: #64748b;

    --hairline: rgba(148, 163, 184, 0.12);
    --hairline-strong: rgba(148, 163, 184, 0.20);

    --accent-2: #818cf8;
    --accent-soft: rgba(129, 140, 248, 0.18);
    --accent-border: rgba(129, 140, 248, 0.45);

    --chip-blue-bg: rgba(59, 130, 246, 0.20);   --chip-blue-fg: #93c5fd;
    --chip-green-bg: rgba(16, 185, 129, 0.20);  --chip-green-fg: #6ee7b7;
    --chip-amber-bg: rgba(245, 158, 11, 0.20);  --chip-amber-fg: #fcd34d;
    --chip-red-bg: rgba(239, 68, 68, 0.20);     --chip-red-fg: #fca5a5;
    --chip-violet-bg: rgba(139, 92, 246, 0.22); --chip-violet-fg: #c4b5fd;

    --code-bg: #10151f;
    --code-head-bg: #0b0f18;
    --code-inline-bg: rgba(129, 140, 248, 0.16);
    --code-inline-fg: #c7d2fe;

    color-scheme: dark;
  }
}

/* Explicit dark toggle — beats the OS in both directions */
:root[data-theme="dark"] {
  --ground: #0a0e1a;
  --blob-1: rgba(129, 140, 248, 0.20);
  --blob-2: rgba(217, 70, 239, 0.14);
  --blob-3: rgba(56, 189, 248, 0.14);

  --glass-fill: rgba(30, 41, 59, 0.55);
  --glass-fill-strong: rgba(30, 41, 59, 0.74);
  --glass-fill-soft: rgba(30, 41, 59, 0.42);
  --glass-fill-60: rgba(30, 41, 59, 0.60);
  --glass-fill-65: rgba(30, 41, 59, 0.66);
  --glass-border: rgba(148, 163, 184, 0.18);
  --glass-border-soft: rgba(148, 163, 184, 0.12);
  --glass-border-bright: rgba(148, 163, 184, 0.26);
  --specular: rgba(255, 255, 255, 0.08);
  --specular-soft: rgba(255, 255, 255, 0.05);

  --shadow-rgb: 0, 0, 0;

  --ink: #f1f5f9;
  --text: #e2e8f0;
  --text-2: #cbd5e1;
  --text-3: #b6c2d4;
  --muted: #94a3b8;
  --faint: #64748b;

  --hairline: rgba(148, 163, 184, 0.12);
  --hairline-strong: rgba(148, 163, 184, 0.20);

  --accent-2: #818cf8;
  --accent-soft: rgba(129, 140, 248, 0.18);
  --accent-border: rgba(129, 140, 248, 0.45);

  --chip-blue-bg: rgba(59, 130, 246, 0.20);   --chip-blue-fg: #93c5fd;
  --chip-green-bg: rgba(16, 185, 129, 0.20);  --chip-green-fg: #6ee7b7;
  --chip-amber-bg: rgba(245, 158, 11, 0.20);  --chip-amber-fg: #fcd34d;
  --chip-red-bg: rgba(239, 68, 68, 0.20);     --chip-red-fg: #fca5a5;
  --chip-violet-bg: rgba(139, 92, 246, 0.22); --chip-violet-fg: #c4b5fd;

  --code-bg: #10151f;
  --code-head-bg: #0b0f18;
  --code-inline-bg: rgba(129, 140, 248, 0.16);
  --code-inline-fg: #c7d2fe;

  color-scheme: dark;
}

/* ═══ 2. RESET & BASE ════════════════════════════════════ */

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

html { height: 100%; background: transparent; }

body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Ambient wash: the #f4f6fb ground plus three radial colour blobs. */
  background:
    radial-gradient(900px circle at 88% -8%, var(--blob-1), transparent 55%),
    radial-gradient(800px circle at -8% 108%, var(--blob-2), transparent 55%),
    radial-gradient(600px circle at 50% 120%, var(--blob-3), transparent 55%),
    var(--ground);
  background-attachment: fixed;
}

h1, h2, h3 { font-weight: 800; letter-spacing: -0.02em; color: var(--ink); }
button, textarea, input { font-family: inherit; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

@keyframes lgFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes lgRise {
  from { transform: translateY(24px) scale(0.98); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes thinkPulse {
  0%, 80%, 100% { opacity: 0.35; transform: scale(1); }
  40% { opacity: 1; transform: scale(1.35); }
}
@keyframes fadeInText {
  from { opacity: 0; transform: translateX(-4px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* ═══ 3. BRAND MARK (violet hero gradient) ═══════════════ */

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--hero-a) 0%, var(--hero-b) 100%);
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.40);
}

.brand-mark--lg {
  width: 48px; height: 48px; border-radius: 15px;
  box-shadow: 0 10px 26px rgba(99, 102, 241, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.brand-mark--xl {
  width: 62px; height: 62px; border-radius: 19px;
  box-shadow: 0 14px 34px rgba(99, 102, 241, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

/* ═══ 4. APP LAYOUT ══════════════════════════════════════ */

.app { height: 100vh; display: flex; flex-direction: column; }
.main-app { display: flex; height: 100vh; overflow: hidden; }

/* ═══ 5. BUTTONS ═════════════════════════════════════════ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 10px 22px;
  border: 1px solid var(--glass-border-soft);
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.18s ease;
  -webkit-backdrop-filter: blur(var(--blur-field));
  backdrop-filter: blur(var(--blur-field));
}

.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.95), rgba(37, 99, 235, 0.95));
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.35);
  box-shadow: 0 6px 18px rgba(59, 130, 246, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.40);
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 10px 26px rgba(59, 130, 246, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.btn-lg { width: 100%; padding: 13px 22px; font-size: 14px; }
.ms-logo { flex-shrink: 0; border-radius: 2px; }

/* Glass icon button — sidebar close, sign out, sidebar toggle */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: var(--glass-fill-soft);
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.18s ease;
  -webkit-backdrop-filter: blur(var(--blur-field));
  backdrop-filter: blur(var(--blur-field));
  box-shadow: inset 0 1px 0 var(--specular);
}

.btn-icon:hover { background: var(--glass-fill-strong); color: var(--ink); transform: scale(1.05); }
.btn-icon:active { transform: scale(0.95); }

.btn-new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-bottom: 16px;
  padding: 11px 18px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: var(--radius-pill);
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.95), rgba(37, 99, 235, 0.95));
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.18s ease;
  box-shadow: 0 6px 18px rgba(59, 130, 246, 0.30), inset 0 1px 0 rgba(255, 255, 255, 0.40);
}

.btn-new-chat:hover {
  box-shadow: 0 10px 24px rgba(59, 130, 246, 0.38), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.btn-new-chat:active { transform: scale(0.97); }

/* ═══ 6. LOGIN SCREEN ════════════════════════════════════ */

.login-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}

.login-card {
  position: relative;
  width: min(420px, 100%);
  padding: 42px 40px 30px;
  text-align: center;
  overflow: hidden;
  border-radius: var(--radius-shell);
  border: 1px solid var(--glass-border-soft);
  background: linear-gradient(165deg, var(--glass-fill-strong) 0%, var(--glass-fill-60) 100%);
  -webkit-backdrop-filter: blur(var(--blur-shell)) saturate(var(--sat-shell));
  backdrop-filter: blur(var(--blur-shell)) saturate(var(--sat-shell));
  box-shadow: var(--shadow-shell);
  animation: lgRise 0.3s var(--ease-rise);
}

/* Ambient colour blobs behind the glass card */
.login-card::before,
.login-card::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.5;
  pointer-events: none;
  z-index: 0;
}

.login-card::before {
  width: 300px; height: 300px; top: -130px; right: -90px;
  background: radial-gradient(circle, #818cf8 0%, #38bdf8 60%, transparent 100%);
}

.login-card::after {
  width: 280px; height: 280px; bottom: -140px; left: -90px;
  background: radial-gradient(circle, #f0abfc 0%, #fb7185 70%, transparent 100%);
}

.login-card > * { position: relative; z-index: 1; }
.login-logo { margin-bottom: 18px; }

.login-card h1 {
  font-size: 30px;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.login-subtitle { font-size: 13.5px; color: var(--muted); margin-bottom: 30px; }

.login-error {
  margin-top: 16px;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  background: var(--chip-red-bg);
  color: var(--chip-red-fg);
  font-size: 12.5px;
  font-weight: 700;
}

.login-foot {
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px solid var(--hairline);
  font-size: 11.5px;
  color: var(--faint);
}

/* ═══ 7. SIDEBAR ═════════════════════════════════════════ */

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  padding: var(--gutter) 0 var(--gutter) var(--gutter);
  z-index: 100;
  transition: transform 0.3s var(--ease);
}

.sidebar-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 16px;
  border-radius: var(--radius-panel);
  border: 1px solid var(--glass-border);
  background: var(--glass-fill);
  -webkit-backdrop-filter: blur(var(--blur-panel)) saturate(var(--sat-panel));
  backdrop-filter: blur(var(--blur-panel)) saturate(var(--sat-panel));
  box-shadow: var(--shadow-panel);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--hairline);
}

.sidebar-title {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--ink);
}

/* The close button only makes sense in the mobile drawer */
.sidebar-close { display: none; }

.sidebar-label {
  padding: 0 6px;
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.sidebar-conversations {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  margin: 0 -4px;
  padding: 0 4px 4px;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 12px;
  margin-bottom: 4px;
  border-radius: var(--radius-card);
  border: 1px solid transparent;
  font-size: 13px;
  color: var(--text-3);
  cursor: pointer;
  transition: all 0.18s ease;
}

.conv-item:hover {
  background: var(--glass-fill-60);
  border-color: var(--glass-border-bright);
  color: var(--ink);
  box-shadow: inset 0 1px 0 var(--specular);
}

.conv-item.active {
  background: var(--glass-fill-strong);
  border-color: var(--glass-border-bright);
  color: var(--ink);
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(var(--shadow-rgb), 0.10), inset 0 1px 0 var(--specular);
}

.conv-item-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-item-delete {
  display: none;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: all 0.15s ease;
}

.conv-item:hover .conv-item-delete,
.conv-item.active .conv-item-delete { display: flex; }

.conv-item-delete:hover { background: var(--chip-red-bg); color: var(--chip-red-fg); }

/* Empty state rendered by DylanUI.renderConversationList */
.conv-empty { padding: 18px 12px; font-size: 12px; text-align: center; color: var(--faint); }

.sidebar-footer {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--hairline);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-row);
  border: 1px solid var(--glass-border-bright);
  background: var(--glass-fill-60);
  box-shadow: inset 0 1px 0 var(--specular);
}

.user-avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--hero-a) 0%, var(--hero-b) 100%);
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.32);
}

.user-details { flex: 1; min-width: 0; }

.user-name {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Role chips — L1 blue / L2 violet / L3 amber */
.user-role-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  padding: 2px 11px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--glass-border-bright);
  background: var(--glass-fill-60);
  color: var(--text-2);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  box-shadow: inset 0 1px 0 var(--specular);
}

.user-role-badge.role-L1 { background: var(--chip-blue-bg);   color: var(--chip-blue-fg); }
.user-role-badge.role-L2 { background: var(--chip-violet-bg); color: var(--chip-violet-fg); }
.user-role-badge.role-L3 { background: var(--chip-amber-bg);  color: var(--chip-amber-fg); }

/* ═══ 8. CHAT AREA + HEADER DOCK ═════════════════════════ */

.chat-area {
  flex: 1;
  min-width: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--header-height);
  flex-shrink: 0;
  margin: var(--gutter) var(--gutter) 0;
  padding: 0 8px 0 18px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--glass-border-soft);
  background: var(--glass-fill-soft);
  -webkit-backdrop-filter: blur(var(--blur-dock)) saturate(var(--sat-dock));
  backdrop-filter: blur(var(--blur-dock)) saturate(var(--sat-dock));
  box-shadow: 0 8px 24px rgba(var(--shadow-rgb), 0.08), inset 0 1px 0 var(--specular);
}

.chat-header-title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--ink);
}

.chat-header .user-role-badge { margin-top: 0; margin-right: 8px; }
.sidebar-toggle { margin-left: -8px; }

/* ═══ 9. MESSAGES CONTAINER + WELCOME ════════════════════ */

.messages-container {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px var(--gutter) 8px;
  scroll-behavior: smooth;
}

.welcome-message {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 40px 8px 24px;
  text-align: center;
  animation: lgRise 0.35s var(--ease-rise);
}

.welcome-message h2 { margin: 18px 0 6px; font-size: 26px; }
.welcome-message > p { margin-bottom: 26px; font-size: 14px; color: var(--muted); }

.welcome-capabilities {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  text-align: left;
}

.capability-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  padding: 15px 16px;
  border-radius: var(--radius-row);
  border: 1px solid var(--glass-border);
  background: var(--glass-fill);
  -webkit-backdrop-filter: blur(var(--blur-panel)) saturate(var(--sat-panel));
  backdrop-filter: blur(var(--blur-panel)) saturate(var(--sat-panel));
  box-shadow: var(--shadow-panel);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s var(--ease);
}

.capability-card:hover {
  background: var(--glass-fill-strong);
  border-color: var(--accent-border);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lift);
}

.capability-card:active { transform: scale(0.985); }

.capability-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border-bright);
  box-shadow: inset 0 1px 0 var(--specular);
}

.capability-icon--blue   { background: var(--chip-blue-bg);   color: var(--chip-blue-fg); }
.capability-icon--violet { background: var(--chip-violet-bg); color: var(--chip-violet-fg); }
.capability-icon--amber  { background: var(--chip-amber-bg);  color: var(--chip-amber-fg); }
.capability-icon--green  { background: var(--chip-green-bg);  color: var(--chip-green-fg); }

.capability-text { display: block; min-width: 0; }

.capability-card strong {
  display: block;
  margin-bottom: 2px;
  font-size: 13px;
  font-weight: 800;
  color: var(--ink);
}

.capability-desc { display: block; font-size: 12px; line-height: 1.45; color: var(--muted); }

/* ═══ 10. MESSAGES ═══════════════════════════════════════ */

.messages {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding-bottom: 8px;
}

.message { display: flex; gap: 12px; margin-bottom: 18px; animation: msgIn 0.25s ease; }

.message-avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  margin-top: 4px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
}

.message-avatar.bot {
  background: linear-gradient(135deg, var(--hero-a) 0%, var(--hero-b) 100%);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
}

.message-avatar.user {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.95), rgba(37, 99, 235, 0.95));
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.32);
}

.message-body { flex: 1; min-width: 0; }

.message-sender {
  margin-bottom: 5px;
  padding-left: 2px;
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Glass bubble */
.message-content {
  padding: 14px 18px;
  border-radius: var(--radius-row);
  border: 1px solid var(--glass-border);
  background: var(--glass-fill);
  -webkit-backdrop-filter: blur(var(--blur-panel)) saturate(var(--sat-panel));
  backdrop-filter: blur(var(--blur-panel)) saturate(var(--sat-panel));
  box-shadow: var(--shadow-panel);
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

/* ═══ 11. MARKDOWN INSIDE MESSAGES ═══════════════════════ */

.message-content > *:first-child { margin-top: 0; }
.message-content > *:last-child { margin-bottom: 0; }
.message-content p { margin-bottom: 10px; }

.message-content h1,
.message-content h2,
.message-content h3 {
  margin: 16px 0 8px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.message-content h1 { font-size: 18px; }
.message-content h2 { font-size: 16px; }
.message-content h3 { font-size: 14.5px; }

.message-content strong { font-weight: 800; color: var(--ink); }
.message-content em { font-style: italic; }
.message-content ul,
.message-content ol { margin: 0 0 10px; padding-left: 22px; }
.message-content li { margin-bottom: 5px; }
.message-content li::marker { color: var(--accent-2); font-weight: 700; }

.message-content a {
  color: var(--info-strong);
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid rgba(59, 130, 246, 0.35);
  transition: all 0.15s ease;
}

.message-content a:hover { color: var(--info); border-bottom-color: var(--info); }

.message-content blockquote {
  margin: 10px 0;
  padding: 8px 14px;
  border-left: 3px solid var(--accent-2);
  border-radius: 0 12px 12px 0;
  background: var(--accent-soft);
  color: var(--text-3);
}

.message-content hr {
  height: 1px;
  margin: 14px 0;
  border: none;
  background: var(--hairline-strong);
}

/* Inline code */
.message-content code {
  padding: 2px 7px;
  border-radius: 7px;
  background: var(--code-inline-bg);
  color: var(--code-inline-fg);
  font-family: var(--font-mono);
  font-size: 12.5px;
}

/* Fenced code blocks — markdown.js emits .code-header followed by <pre> */
.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  padding: 8px 14px;
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  background: var(--code-head-bg);
  color: var(--code-head-fg);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.btn-copy {
  padding: 3px 11px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.06);
  color: var(--code-head-fg);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-copy:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.32);
  color: #ffffff;
}

.message-content pre {
  margin: 12px 0;
  padding: 14px 16px;
  border-radius: var(--radius-card);
  background: var(--code-bg);
  color: var(--code-fg);
  overflow-x: auto;
}

.code-header + pre { margin-top: 0; border-radius: 0 0 var(--radius-card) var(--radius-card); }

.message-content pre code {
  padding: 0;
  background: none;
  color: inherit;
  font-size: 12.5px;
  line-height: 1.6;
}

.message-content pre::-webkit-scrollbar { height: 8px; }
.message-content pre::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-pill);
}

/* Tables — display:block so a wide table scrolls inside the bubble
   instead of overflowing it (markdown.js emits a bare <table>). */
.message-content table {
  display: block;
  width: max-content;
  max-width: 100%;
  margin: 12px 0;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--glass-border-bright);
  border-radius: var(--radius-card);
  overflow-x: auto;
  font-size: 12.5px;
  background: var(--glass-fill-60);
}

.message-content th,
.message-content td {
  padding: 9px 13px;
  text-align: left;
  border-bottom: 1px solid var(--hairline);
}

.message-content th {
  background: var(--accent-soft);
  color: var(--ink);
  font-weight: 800;
  white-space: nowrap;
}

.message-content tbody tr:last-child td { border-bottom: none; }
.message-content tbody tr:nth-child(even) td { background: rgba(var(--shadow-rgb), 0.02); }

/* ═══ 12. TOOL CHIPS + THINKING INDICATOR ════════════════ */

.tool-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 4px 6px 4px 0;
  padding: 4px 13px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--glass-border-bright);
  background: var(--chip-blue-bg);
  color: var(--chip-blue-fg);
  font-size: 11.5px;
  font-weight: 800;
  white-space: nowrap;
  box-shadow: inset 0 1px 0 var(--specular);
}

.tool-status.complete { background: var(--chip-green-bg); color: var(--chip-green-fg); }

.tool-status .spinner {
  width: 11px;
  height: 11px;
  flex-shrink: 0;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  opacity: 0.75;
  animation: spin 0.6s linear infinite;
}

.thinking-indicator {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 5px 15px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--glass-border-bright);
  background: var(--chip-violet-bg);
  color: var(--chip-violet-fg);
  font-size: 12px;
  font-weight: 700;
  box-shadow: inset 0 1px 0 var(--specular);
}

.thinking-indicator .thinking-dots { display: inline-flex; gap: 4px; }

.thinking-indicator .thinking-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.35;
  animation: thinkPulse 1.4s infinite;
}

.thinking-indicator .thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-indicator .thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
.thinking-indicator .thinking-text { animation: fadeInText 0.3s ease; }

/* Legacy fallback — chat.js still strips .typing-indicator */
.typing-indicator { display: inline-flex; gap: 4px; padding: 8px 0; }

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: bounce 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

/* ═══ 13. FLOATING CAPSULE INPUT DOCK ════════════════════ */

.input-area { flex-shrink: 0; padding: 8px var(--gutter) 16px; }

.input-container {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 8px 8px 8px 20px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--glass-border-bright);
  background: var(--glass-fill-65);
  -webkit-backdrop-filter: blur(var(--blur-dock)) saturate(var(--sat-dock));
  backdrop-filter: blur(var(--blur-dock)) saturate(var(--sat-dock));
  box-shadow: var(--shadow-dock);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.input-container:focus-within {
  background: var(--glass-fill-strong);
  border-color: var(--accent-border);
  box-shadow: var(--shadow-dock), 0 0 0 4px var(--accent-soft);
}

.message-input {
  flex: 1;
  min-width: 0;
  min-height: 24px;
  max-height: 132px;   /* JS caps at 200px; CSS keeps the capsule sane */
  padding: 8px 0;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  overflow-y: auto;
}

.message-input::placeholder { color: var(--faint); }
.message-input:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-send {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.95), rgba(37, 99, 235, 0.95));
  color: #ffffff;
  cursor: pointer;
  transition: all 0.18s ease;
  box-shadow: 0 6px 18px rgba(59, 130, 246, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.40);
}

.btn-send:hover:not(:disabled) {
  box-shadow: 0 10px 24px rgba(59, 130, 246, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.btn-send:active:not(:disabled) { transform: scale(0.94); }

.btn-send:disabled {
  background: var(--glass-fill-60);
  border-color: var(--glass-border-bright);
  color: var(--faint);
  box-shadow: inset 0 1px 0 var(--specular);
  cursor: not-allowed;
}

.input-hint {
  max-width: var(--content-max);
  margin: 9px auto 0;
  text-align: center;
  font-size: 11px;
  color: var(--faint);
}

/* ═══ 14. SCROLLBARS ═════════════════════════════════════ */

.messages-container,
.sidebar-conversations,
.message-input {
  scrollbar-width: thin;
  scrollbar-color: rgba(var(--shadow-rgb), 0.22) transparent;
}

.messages-container::-webkit-scrollbar,
.sidebar-conversations::-webkit-scrollbar,
.message-input::-webkit-scrollbar { width: 10px; }

.messages-container::-webkit-scrollbar-track,
.sidebar-conversations::-webkit-scrollbar-track,
.message-input::-webkit-scrollbar-track { background: transparent; }

.messages-container::-webkit-scrollbar-thumb,
.sidebar-conversations::-webkit-scrollbar-thumb,
.message-input::-webkit-scrollbar-thumb {
  background: rgba(var(--shadow-rgb), 0.15);
  border-radius: var(--radius-pill);
  border: 3px solid transparent;
  background-clip: content-box;
}

.messages-container::-webkit-scrollbar-thumb:hover,
.sidebar-conversations::-webkit-scrollbar-thumb:hover {
  background: rgba(var(--shadow-rgb), 0.28);
  background-clip: content-box;
}

/* ═══ 15. MOBILE DRAWER + RESPONSIVE ═════════════════════ */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99;
  background: rgba(15, 23, 42, 0.35);
  -webkit-backdrop-filter: blur(var(--blur-overlay)) saturate(var(--sat-overlay));
  backdrop-filter: blur(var(--blur-overlay)) saturate(var(--sat-overlay));
  animation: lgFadeIn 0.25s ease;
}

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

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    padding: 12px;
    transform: translateX(-104%);
  }

  .sidebar.open { transform: translateX(0); }

  .sidebar.open .sidebar-panel {
    box-shadow: 0 32px 90px rgba(var(--shadow-rgb), 0.35), inset 0 1px 0 var(--specular);
  }

  .sidebar-close { display: inline-flex; }
  .welcome-capabilities { grid-template-columns: minmax(0, 1fr); }
}

@media (min-width: 901px) {
  .sidebar-toggle { display: none; }
}

@media (max-width: 600px) {
  :root { --gutter: 12px; }

  .messages-container { padding-top: 16px; }
  .welcome-message { padding: 24px 4px 16px; }
  .welcome-message h2 { font-size: 22px; }
  .message-content { padding: 12px 14px; }
  .input-hint { display: none; }
}

/* ═══ 16. EMBEDDED MODE (420×620 iframe widget) ══════════
   The host page supplies the background, so the ambient wash and
   the blobs are dropped and every surface goes compact.          */

body.dylan-embedded { overflow: hidden; background: transparent; }

.dylan-embedded .sidebar,
.dylan-embedded .sidebar-overlay { display: none !important; }

.dylan-embedded .app,
.dylan-embedded .main-app,
.dylan-embedded .chat-area,
.dylan-embedded .login-screen { height: 100vh; }

/* Login */
.dylan-embedded .login-screen { padding: 12px; }

.dylan-embedded .login-card {
  padding: 26px 22px 20px;
  border-radius: var(--radius-tab);
  border-color: var(--glass-border);
  box-shadow: none;
  animation: none;
}

.dylan-embedded .login-card::before,
.dylan-embedded .login-card::after { display: none; }

.dylan-embedded .login-logo { margin-bottom: 12px; }
.dylan-embedded .brand-mark--xl { width: 44px; height: 44px; border-radius: 14px; }
.dylan-embedded .brand-mark--xl svg { width: 24px; height: 24px; }
.dylan-embedded .login-card h1 { font-size: 20px; margin-bottom: 4px; }
.dylan-embedded .login-subtitle { font-size: 12.5px; margin-bottom: 20px; }
.dylan-embedded .login-foot { display: none; }

/* Compact header — always visible in the widget */
.dylan-embedded .chat-header {
  display: flex !important;
  height: 44px;
  margin: 10px 10px 0;
  padding: 0 6px 0 14px;
}

.dylan-embedded .chat-header .sidebar-toggle { display: none; }

/* Compact welcome */
.dylan-embedded .messages-container { padding: 12px 10px 4px; }
.dylan-embedded .welcome-message { padding: 18px 4px 12px; }
.dylan-embedded .brand-mark--lg { width: 38px; height: 38px; border-radius: 12px; }
.dylan-embedded .brand-mark--lg svg { width: 20px; height: 20px; }
.dylan-embedded .welcome-message h2 { margin: 10px 0 4px; font-size: 18px; }
.dylan-embedded .welcome-message > p { margin-bottom: 14px; font-size: 12.5px; }

.dylan-embedded .welcome-capabilities {
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}

.dylan-embedded .capability-card { gap: 10px; padding: 10px 12px; border-radius: var(--radius-card); }
.dylan-embedded .capability-icon { width: 26px; height: 26px; }
.dylan-embedded .capability-icon svg { width: 14px; height: 14px; }
.dylan-embedded .capability-card strong { font-size: 12.5px; }
.dylan-embedded .capability-desc { font-size: 11.5px; }

/* Compact messages */
.dylan-embedded .message { gap: 8px; margin-bottom: 14px; }
.dylan-embedded .message-avatar { width: 26px; height: 26px; font-size: 11px; }

.dylan-embedded .message-content {
  padding: 11px 13px;
  border-radius: var(--radius-card);
  font-size: 13px;
}

/* Compact input dock */
.dylan-embedded .input-area { padding: 6px 10px 10px; }
.dylan-embedded .input-container { padding: 6px 6px 6px 16px; }
.dylan-embedded .message-input { max-height: 96px; font-size: 13px; }
.dylan-embedded .btn-send { width: 34px; height: 34px; }
.dylan-embedded .btn-send svg { width: 16px; height: 16px; }
.dylan-embedded .input-hint { display: none; }

/* ═══ 17. REDUCED MOTION ═════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }

  .messages-container { scroll-behavior: auto; }
  .capability-card:hover,
  .btn-icon:hover { transform: none; }
}
