/* ==========================================================================
   AI Library – Design System  |  v3 – Unified Clean
   ========================================================================== */

/* ─── Reset & Base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body[data-page="profile"] {
  overflow-y: auto;
  overflow-x: hidden;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  line-height: 1.5;
  background:
    radial-gradient(circle at top left,  hsl(236, 37%, 92%), transparent 36%),
    radial-gradient(circle at top right, hsla(92, 56%, 42%, 0.09), transparent 26%),
    linear-gradient(180deg, hsl(236, 20%, 98%) 0%, var(--bg) 50%, var(--bg-deep) 100%);
}

a { color: inherit; text-decoration: none; transition: color 0.2s ease; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ─── CSS Variables ─────────────────────────────────────────────────────── */
:root {
  color-scheme: light;

  --brand-blue:        hsl(236, 37%, 33%);
  --brand-blue-glow:   hsl(236, 37%, 45%);
  --brand-green:       hsl(92,  56%, 42%);
  --brand-green-hover: hsl(92,  56%, 36%);

  --bg:             hsl(236, 20%, 97%);
  --bg-deep:        hsl(236, 18%, 93%);
  --surface:        rgba(255, 255, 255, 0.90);
  --surface-strong: #ffffff;
  --surface-muted:  hsl(236, 18%, 97%);

  --ink:       hsl(236, 24%, 12%);
  --ink-soft:  hsl(236, 12%, 46%);

  --accent:        var(--brand-blue);
  --accent-strong: hsl(236, 37%, 24%);
  --accent-soft:   hsl(236, 37%, 94%);
  --accent-warm:   var(--brand-green);
  --line:          rgba(54, 58, 116, 0.12);

  --shadow:    0 24px 60px rgba(54, 58, 116, 0.12);
  --shadow-sm: 0 1px 3px rgba(54, 58, 116, 0.05), 0 1px 2px rgba(54, 58, 116, 0.02);
  --shadow-md: 0 4px 12px rgba(54, 58, 116, 0.08);

  --radius-sm: 12px;
  --radius-md: 20px;
  --radius-lg: 26px;

  --font-heading: 'Source Serif 4', Georgia, serif;
  --font-body:    'Manrope', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --sidebar-w:      260px;
  --sidebar-w-slim:  60px;
}

/* ─── Utility ───────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ─── App Shell ─────────────────────────────────────────────────────────── */
.webui-layout {
  display: flex;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* ─── Sidebar ───────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w-slim);
  height: 100%;
  flex-shrink: 0;
  position: relative;        /* anchor for absolute footer */
  background: var(--surface-strong);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  transition: width 0.22s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
  z-index: 20;
}

.sidebar.retracted { width: var(--sidebar-w-slim); }

/* Allow dropdowns to overflow when expanded */
.sidebar:not(.retracted) { overflow: visible; }

.sidebar-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0.6rem;
  white-space: nowrap;
  flex-shrink: 0;
  border-bottom: 1px solid var(--line);
  min-height: 96px;
}

.sidebar-brand-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  grid-column: 2;
  flex: 1;
  min-width: 0;
}

.sidebar-logo-full {
  height: clamp(64px, 7vw, 84px);
  width: auto;
  max-width: 100%;
  object-fit: contain; /* Prevents rectangular distortion completely */
  object-position: center;
  opacity: 1;
  display: block;
  flex-shrink: 0;
  image-rendering: auto;
  image-rendering: -webkit-optimize-contrast;
  filter: contrast(1.06) saturate(1.04);
  transition: opacity 0.15s ease;
}
.sidebar-logo-badge {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #ffffff;
  font-size: 0.9rem;
  font-weight: 800;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.05em;
  box-shadow: var(--shadow-sm);
  user-select: none;
}

.sidebar.retracted .sidebar-logo-full {
  display: none !important;
  opacity: 0;
}

.sidebar.retracted .sidebar-logo-badge {
  display: flex !important;
}

.sidebar.retracted .sidebar-brand-wrapper {
  justify-content: center;
}


.sidebar-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink);
  overflow: hidden;
  opacity: 1;
  transition: opacity 0.15s ease;
  white-space: nowrap;
}

.sidebar-brand {
  color: var(--accent);
}

body[data-page="home"] .ai-library-label {
  color: var(--accent);
}

body[data-page="profile"] #profileEyebrow {
  color: var(--accent);
}

.sidebar.retracted .sidebar-title { opacity: 0; pointer-events: none; }

.sidebar-toggle {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--ink-soft);
  grid-column: 3;
  justify-self: end;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: background 0.15s, color 0.15s;
}
.sidebar-toggle:hover { 
  background: var(--accent-soft); 
  color: var(--accent-strong);
}

/* Middle scrollable area */
.sidebar-nav {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  padding: 0.4rem 0.6rem;
  padding-bottom: 10rem;     /* clearance so content doesn't go behind footer */
  gap: 2px;
  scrollbar-width: none;
  -ms-overflow-style: none;  /* IE/Edge */
}
.sidebar-nav::-webkit-scrollbar { display: none; }

.sidebar-nav hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 0.4rem 0;
}

.sidebar-history-label {
  padding: 0.5rem 0.7rem 0.25rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  transition: opacity 0.15s;
}
.sidebar.retracted .sidebar-history-label { opacity: 0; }

/* Sidebar buttons */
.sidebar-btn {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  background: transparent;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  text-align: left;
  cursor: pointer;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s;
  width: 100%;
}
.sidebar-btn:hover { background: var(--accent-soft); color: var(--accent-strong); }
.sidebar.retracted .sidebar-btn { justify-content: center; }

.sidebar-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.sidebar-label {
  overflow: hidden;
  opacity: 1;
  transition: opacity 0.15s;
  white-space: nowrap;
}
.sidebar.retracted .sidebar-label { opacity: 0; pointer-events: none; }

/* ─── Sidebar Footer ────────────────────────────────────────────────────── */
.sidebar-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  padding: 0.4rem 0.6rem 0.6rem;
  gap: 2px;
  border-top: 1px solid var(--line);
  background: var(--surface-strong);
  z-index: 25;
  transition: width 0.22s cubic-bezier(.4,0,.2,1);
}

.sidebar.retracted .sidebar-footer {
  width: var(--sidebar-w-slim);
}

/* Language dropdown */
.sidebar-lang-wrap { position: relative; }

.sidebar-lang-trigger {
  width: 100%;
  justify-content: flex-start;
}

.sidebar-lang-arrow {
  margin-left: auto;
  flex-shrink: 0;
  color: var(--ink-soft);
  transition: transform 0.2s;
}
.sidebar.retracted .sidebar-lang-arrow { display: none; }

.sidebar-lang-dropdown {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  width: 180px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 300;
  overflow: hidden;
}
.sidebar.retracted .sidebar-lang-dropdown {
  left: calc(100% + 8px);
  bottom: auto;
  top: 0;
}

.sidebar-lang-option {
  width: 100%;
  border: none;
  background: transparent;
  padding: 0.6rem 0.85rem;
  text-align: left;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--ink);
  transition: background 0.12s;
}
.sidebar-lang-option:hover  { background: var(--accent-soft); }
.sidebar-lang-option.active { font-weight: 700; color: var(--accent-strong); background: var(--accent-soft); }
.lang-flag-text { font-size: 1.1rem; line-height: 1; }

/* User avatar row — always at very bottom */
#sidebarUserProfileLink {
  display: block;
  text-decoration: none;
  color: inherit;
  border-top: 1px solid var(--line);
  margin-top: 0.3rem;
  padding-top: 0.3rem;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.45rem 0.5rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.sidebar-user:hover { background: var(--accent-soft); }

.sidebar-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: 0.03em;
  user-select: none;
}

.sidebar-user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}
.sidebar.retracted .sidebar-user-info { display: none !important; }

.sidebar-user-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-email {
  font-size: 0.72rem;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── Main Area ─────────────────────────────────────────────────────────── */
.webui-main {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  position: relative;
  background: transparent;
}

/* Home page should allow vertical scrolling in the main column. */
body[data-page="home"] .webui-main {
  overflow-y: auto;
  overflow-x: hidden;
}

/*
  EMPTY STATE: two pseudo-spacers push the welcome+input group to sit
  at ~38% from top — the Gemini "above center" feel.
*/
.webui-main:not(.is-active)::before {
  content: '';
  flex: 1 0 0;
  max-height: 10vh;
}
.webui-main:not(.is-active)::after {
  content: '';
  flex: 1.6 0 0;
}

/* ACTIVE STATE: spacers gone, chat-window fills remaining space */
.webui-main.is-active::before,
.webui-main.is-active::after {
  display: none;
}

/* ─── Welcome Screen ────────────────────────────────────────────────────── */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 760px;
  padding: 0 1.5rem;
  text-align: center;
  flex-shrink: 0;
}

.chat-eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.55rem;
}

.chat-header {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: clamp(1.9rem, 4vw, 3rem);
  color: var(--ink);
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin-bottom: 1.5rem;
}

/* ─── Suggestions ───────────────────────────────────────────────────────── */
.suggestions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  width: 100%;
  max-width: 700px;
  margin-bottom: 1.5rem;
}

.suggestion-btn {
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 0.9rem 1rem;
  color: var(--ink);
  font-size: 0.83rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  line-height: 1.45;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--shadow-sm);
  min-height: 4.8rem; /* Keeps cards uniform regardless of content lines */
}
.suggestion-btn:hover {
  border-color: rgba(54, 58, 116, 0.22);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

/* Skeleton Container explicitly matches the .suggestions layout grid */
.skeleton-suggestions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  width: 100%;
}

/* Skeleton cards precisely replicate the size and shape of suggestion-btn */
.skeleton-line {
  min-height: 4.8rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent; /* Mimics button border structural bounds */
  background: linear-gradient(90deg, rgba(54,58,116,0.04) 25%, rgba(54,58,116,0.09) 50%, rgba(54,58,116,0.04) 75%);
  background-size: 400% 100%;
  animation: shimmer 1.4s infinite linear;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Keep responsive collapse clean on small screens */
@media (max-width: 768px) {
  .suggestions, .skeleton-suggestions {
    grid-template-columns: 1fr !important;
  }
}

/* ─── Chat Window ───────────────────────────────────────────────────────── */
.chat-window {
  flex: 1 1 0;
  min-height: 0;       /* CRITICAL: allows shrink so footer stays visible */
  width: 100%;
  max-width: 760px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1.5rem 1.5rem 1rem;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.chat-window::-webkit-scrollbar { display: none; }

/* ─── Chat Footer Wrap (regenerate + input — always together at bottom) ─── */
.chat-footer-wrap {
  /* Override any position:fixed from other stylesheets */
  position: static !important;
  left: auto !important;
  transform: none !important;
  bottom: auto !important;
  pointer-events: auto !important;

  width: 100%;
  max-width: 760px;
  flex-shrink: 0;      /* NEVER compress — always fully visible */
  display: flex;
  flex-direction: column;
  background: transparent;
  padding: 0.5rem 0 1rem;
  z-index: auto;
}

.chat-mini-footer {
  text-align: center;
  margin-top: 0.55rem;
  font-size: 0.8rem;
  color: var(--ink-soft);
  opacity: 0.9;
  user-select: none;
}

/* ─── Regenerate Bar ────────────────────────────────────────────────────── */
.regenerate-container {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.5rem 1.5rem 0.4rem;
}

.action-btn-pill {
  border: 1px solid var(--line);
  background: var(--surface-strong);
  border-radius: 999px;
  padding: 0.45rem 1.1rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
}
.action-btn-pill:hover {
  color: var(--accent);
  border-color: rgba(54, 58, 116, 0.25);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.action-btn-pill .icon     { font-size: 1rem; }
.action-btn-pill .icon-svg { flex-shrink: 0; }

/* ─── Input Area ────────────────────────────────────────────────────────── */
.chat-input-area,
.chat-input-area.bottom,
.chat-input-area.centered {
  width: 100%;
  padding: 0 1.5rem 0;
  background: transparent;
  /* Kill ALL position overrides from styles.css and app.js */
  position: static !important;
  left: auto !important;
  right: auto !important;
  top: auto !important;
  bottom: auto !important;
  transform: none !important;
  z-index: auto !important;
}

.searchContainer {
  display: flex;
  flex-direction: column;
  background: var(--surface-strong);
  border-radius: 24px;
  border: 1.5px solid var(--line);
  box-shadow: 0 2px 12px rgba(54,58,116,0.07);
  padding: 0.5rem 0.75rem 0.6rem;
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
}
.searchContainer:focus-within {
  border-color: rgba(54,58,116,0.35);
  box-shadow: 0 4px 20px rgba(54,58,116,0.11);
}

textarea#userInput {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  padding: 0.55rem 0.5rem 0.3rem 0.6rem;
  font-size: 1rem;
  line-height: 1.55;
  max-height: 200px;
  overflow-y: auto;
  color: var(--ink);
  font-family: var(--font-body);
}
textarea#userInput::placeholder { color: var(--ink-soft); }

.input-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

/* Right-side button group (gear + send) */
.input-actions-right {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.round-submit {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--brand-blue);
  color: white;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.1s, opacity 0.15s;
}
.round-submit:hover  { background: var(--brand-blue-glow); }
.round-submit:active { transform: scale(0.93); }

/* ─── Settings Pill Button ──────────────────────────────────────────────── */
.settings-pill {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.2s;
}

.settings-pill:hover {
  background: var(--accent-soft);
  border-color: rgba(54,58,116,0.22);
  color: var(--accent-strong);
  transform: rotate(30deg);
}

/* Settings popup — positioned above the input area */
.settings-popup {
  position: fixed;
  bottom: 5.5rem;
  right: calc(50% - 340px);   /* align near right side of the input pill */
  width: 300px;
  box-sizing: border-box;
  overflow-y: auto;
  max-height: 70vh;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  z-index: 200;
  animation: settingsIn 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes settingsIn {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ─── Behavior Dropdown ─────────────────────────────────────────────────── */
.behavior-dropdown { position: relative; }

.behavior-dropdown-button {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.75rem 0.35rem 0.65rem;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.behavior-dropdown-button:hover {
  background: var(--accent-soft);
  border-color: rgba(54,58,116,0.2);
  color: var(--accent-strong);
}
.behavior-dropdown-name  { font-size: 0.82rem; font-weight: 600; }
.behavior-dropdown-arrow { font-size: 0.8rem; }

.behavior-dropdown-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  width: min(92vw, 420px);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(54,58,116,0.13);
  z-index: 1000;
  overflow: hidden;
}

.behavior-dropdown-item {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0.7rem 0.9rem;
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(150px, 1fr) auto;
  column-gap: 1rem;
  align-items: center;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s;
}
.behavior-dropdown-item:hover  { background: var(--accent-soft); }
.behavior-dropdown-item.active { background: hsl(236, 37%, 96%); }

.behavior-item-name {
  font-size: 0.85rem;
  font-weight: 600;
  display: block;
  color: var(--ink);
  line-height: 1.3;
  white-space: normal;
  overflow-wrap: anywhere;
}

.behavior-item-description {
  font-size: 0.78rem;
  color: #4a6575;
  display: block;
  line-height: 1.3;
  white-space: normal;
  overflow-wrap: anywhere;
}

.behavior-item-check {
  font-size: 0.9rem;
  color: var(--accent-warm);
  opacity: 0;
  justify-self: end;
}
.behavior-dropdown-item.active .behavior-item-check { opacity: 1; }

/* ─── Chat Bubbles ──────────────────────────────────────────────────────── */
.chat-message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: msgIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  background: transparent !important; /* Outer container must be transparent */
  border: none !important;            /* Strip outer double border lines */
  box-shadow: none !important;        /* Strip outer double shadow layers */
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chat-message.user-message { align-self: flex-end; }
.chat-message.ai-message   { align-self: flex-start; }

.message-content {
  padding: 0.85rem 1.15rem;
  border-radius: var(--radius-md);
  font-size: 0.93rem;
  line-height: 1.65;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
  max-width: 100%;
  box-sizing: border-box;
}

.user-message .message-content {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong)) !important;
  color: #fff !important;
  border-bottom-right-radius: 5px !important;
  box-shadow: 0 4px 14px rgba(54, 58, 116, 0.22) !important;
  border: none !important;
}

/* AI Bubble styling exclusively handled here on the inner content layer */
.ai-message .message-content {
  background: var(--surface-strong) !important;
  color: var(--ink) !important;
  border-bottom-left-radius: 5px !important;
  border: 1px solid var(--line) !important;
  box-shadow: var(--shadow-sm) !important;
}

.referenceList {
  margin-top: 0.75rem;
  padding-top: 0.6rem;
  border-top: 1px dashed rgba(54, 58, 116, 0.2);
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.referenceList li { font-size: 0.8rem; }
.referenceList a  { color: var(--accent); font-weight: 600; text-decoration: underline; cursor: pointer; }
.referenceList a:hover { color: var(--brand-blue-glow); }

.message-icon-container {
  margin-top: 0.2rem;
  display: flex;
  justify-content: flex-end;
}

.info-icon {
  font-size: 0.78rem;
  cursor: pointer;
  color: var(--ink-soft);
  position: relative;
  display: inline-block;
  line-height: 1;
}
.info-icon .tooltip {
  visibility: hidden;
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.65rem;
  position: absolute;
  z-index: 10;
  bottom: 125%;
  right: 0;
  width: 240px;
  font-size: 0.72rem;
  opacity: 0;
  transition: opacity 0.15s;
  box-shadow: var(--shadow-md);
  white-space: normal;
  pointer-events: none;
}
.info-icon:hover .tooltip { visibility: visible; opacity: 1; }

/* ─── Typing Indicator ──────────────────────────────────────────────────── */
.typing-indicator-container,
.chat-window .chat-message.typing-indicator-container {
  background: transparent !important;
  background-color: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
}

/* Force the inner element to contain the layout bounds safely */
.typing-indicator-container .message-content {
  background: var(--surface-strong) !important;
  color: var(--ink) !important;
  border: 1px solid var(--line) !important;
  box-shadow: var(--shadow-sm) !important;
  display: inline-flex !important;
  align-items: center;
  padding: 0.6rem 0.9rem !important;
  border-radius: var(--radius-md) !important;
  border-bottom-left-radius: 5px !important;
  width: auto !important;
  max-width: max-content !important;
}

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
}

.typing-indicator span {
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-soft);
  animation: typingBounce 1.4s infinite ease-in-out both;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); }
  40%           { transform: scale(1); }
}

/* ─── Header / Shell ────────────────────────────────────────────────────── */
.pp-header {
  display: none !important;
  height: 0 !important;
  min-height: 0 !important;
  padding: 0 !important;
  border: none !important;
}

.pp-brand { display: flex; align-items: center; gap: 0.85rem; }
.brand-logo-link { display: flex; align-items: center; }
.brand-logo {
  height: clamp(42px, 4vw, 56px);
  width: auto;
  display: block;
  image-rendering: auto;
  image-rendering: -webkit-optimize-contrast;
  filter: contrast(1.06) saturate(1.04);
}

.brand-sub {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
  border-left: 1px solid var(--line);
  padding-left: 0.85rem;
}

.pp-nav { display: flex; gap: 0.3rem; }
.pp-nav a {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink-soft);
  padding: 0.5rem 0.9rem;
  border: 1px solid transparent;
  border-radius: 999px;
  transition: all 0.15s;
}
.pp-nav a:hover  { color: var(--accent); background: var(--accent-soft); border-color: rgba(54,58,116,0.12); }
.pp-nav a.active { color: var(--accent); background: var(--accent-soft); border-color: rgba(54,58,116,0.2); font-weight: 700; }

.pp-right { display: flex; align-items: center; gap: 0.75rem; }

.name-btn {
  border: 0; background: transparent;
  font-weight: 600; font-size: 0.86rem;
  color: var(--ink); cursor: pointer;
}

.avatar {
  width: 32px; height: 32px; border-radius: 999px;
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: #fff; display: inline-flex; align-items: center;
  justify-content: center; font-size: 0.75rem;
  font-weight: 700; letter-spacing: 0.04em;
}

.sign-btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid transparent; border-radius: 999px;
  background: var(--brand-green); color: #fff;
  font-weight: 700; font-size: 0.82rem;
  padding: 0.55rem 1.1rem; cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.sign-btn:hover { background: var(--brand-green-hover); transform: translateY(-1px); }

/* Hide shell-rendered account controls — now in sidebar */
#shell .pp-right .avatar,
#shell .pp-right .account-link,
#shell .pp-right .name-btn,
#shell .pp-right .sign-btn,
#shell .pp-right .lang-switcher,
#shell .header-actions .avatar,
#shell .header-actions .account-link,
#shell .header-actions .name-btn,
#shell .header-actions .sign-btn,
#shell .header-actions .lang-switcher {
  display: none !important;
}

/* ─── Settings Popup ────────────────────────────────────────────────────── */
.settings-popup {
  position: fixed; width: 300px;
  box-sizing: border-box; overflow-y: auto;
  background: rgba(255,255,255,0.97);
  backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 1.25rem; z-index: 200;
}

.settings-title-row h3 {
  font-family: var(--font-heading);
  font-size: 1.05rem; letter-spacing: -0.02em;
  color: var(--ink); margin-bottom: 1rem;
}

.settings-control-group {
  margin-bottom: 0.85rem;
  display: flex; flex-direction: column; gap: 0.3rem;
}
.settings-control-group label {
  font-size: 0.78rem; font-weight: 600;
  display: flex; justify-content: space-between;
  align-items: center; color: var(--ink);
}
.value-badge {
  background: var(--accent); color: #fff;
  font-size: 0.7rem; font-weight: 700;
  padding: 0.08rem 0.4rem; border-radius: 999px;
}
.settings-control-group input[type="range"] {
  width: 100%; accent-color: var(--accent); cursor: pointer;
}
.help-text { font-size: 0.68rem; color: var(--ink-soft); }

.settings-save-btn {
  width: 100%; border: 0; background: var(--accent); color: #fff;
  font-weight: 700; font-size: 0.83rem; padding: 0.6rem;
  border-radius: 999px; cursor: pointer; margin-top: 0.5rem;
  transition: background 0.2s, transform 0.1s;
}
.settings-save-btn:hover { background: var(--brand-blue-glow); transform: translateY(-1px); }

/* ─── Token Usage ───────────────────────────────────────────────────────── */
.token_usage { margin-top: 0.75rem; }
.token_usage hr, .behavior-settings-section hr {
  border: 0; border-top: 1px solid var(--line); margin: 0.75rem 0;
}
.section-label {
  font-size: 0.68rem; text-transform: uppercase;
  font-weight: 700; letter-spacing: 0.12em;
  color: var(--ink-soft); margin-bottom: 0.5rem;
}
.usage-metric { margin-bottom: 0.65rem; }
.usage-metric label {
  font-size: 0.73rem; font-weight: 500;
  display: block; margin-bottom: 0.2rem; color: var(--ink);
}
.progress-bar-wrap {
  height: 5px; background: var(--bg);
  border-radius: 999px; overflow: hidden;
}
.progress-bar-fill {
  height: 100%; border-radius: 999px;
  transition: width 0.5s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.3s;
}

/* ─── Reference Toast ───────────────────────────────────────────────────── */
.ref-toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 0.6rem;
  background: var(--ink); color: #fff; border-radius: 999px;
  padding: 0.55rem 1rem 0.55rem 0.8rem; font-size: 0.85rem;
  font-weight: 500; box-shadow: 0 4px 20px rgba(0,0,0,0.22);
  z-index: 9999; white-space: nowrap;
}
.ref-toast.hidden { display: none !important; }

.ref-toast-spinner {
  width: 13px; height: 13px;
  border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff;
  border-radius: 50%; animation: spin 0.7s linear infinite; flex-shrink: 0;
}
.ref-toast-spinner.done { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.ref-toast-action {
  background: rgba(255,255,255,0.18); border: 1px solid rgba(255,255,255,0.3);
  color: #fff; border-radius: 999px; padding: 0.18rem 0.7rem;
  font-size: 0.8rem; font-weight: 600; cursor: pointer; transition: background 0.15s;
}
.ref-toast-action:hover  { background: rgba(255,255,255,0.28); }
.ref-toast-action.hidden { display: none; }

.ref-toast-close {
  background: transparent; border: none;
  color: rgba(255,255,255,0.55); font-size: 0.85rem;
  cursor: pointer; padding: 0 0.1rem; line-height: 1;
}
.ref-toast-close:hover { color: #fff; }

/* ─── PDF Popup ─────────────────────────────────────────────────────────── */
.pdf-popup {
  position: fixed; inset: 0;
  background: rgba(18, 20, 48, 0.5); backdrop-filter: blur(6px);
  z-index: 1000; display: flex;
  justify-content: center; align-items: center; padding: 2rem;
}
.pdf-popup-content {
  background: var(--surface-strong); border: 1px solid rgba(255,255,255,0.72);
  border-radius: var(--radius-md); box-shadow: var(--shadow);
  width: 100%; max-width: 900px; height: 100%; position: relative;
  overflow: hidden; display: flex;
  flex-direction: column; justify-content: center; align-items: center;
}
.pdf-close-btn {
  position: absolute; top: 0.6rem; right: 0.6rem;
  width: 30px; height: 30px; border: none; border-radius: 999px;
  background: rgba(54, 58, 116, 0.15); color: var(--ink);
  font-size: 0.95rem; cursor: pointer; display: flex;
  align-items: center; justify-content: center; z-index: 10; transition: background 0.2s;
}
.pdf-close-btn:hover { background: rgba(54, 58, 116, 0.3); }

.pdf-loader {
  display: flex; flex-direction: column; align-items: center;
  gap: 0.75rem; color: var(--ink-soft); font-size: 0.88rem;
}
.loader-spinner { font-size: 2.5rem; color: var(--accent); }
.loader-spinner.spinning { animation: rotate 1s linear infinite; }
@keyframes rotate { to { transform: rotate(360deg); } }

.pdf-container { width: 100%; height: 100%; overflow-y: auto; position: relative; }
.pageWrapper { position: relative; }
.pageWrapper canvas { display: block; }

svg.overlay polygon {
  fill: hsla(54, 100%, 50%, 0.35);
  stroke: none; transition: opacity 0.3s;
}

/* ─── Auth Pages ─────────────────────────────────────────────────────────── */
.auth-wrap { width: min(clamp(600px, 75vw, 1000px), calc(100% - 2rem)); margin: 2rem auto; }
.auth-card {
  background: var(--surface); border: 1px solid rgba(255,255,255,0.72);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  padding: 2.5rem; backdrop-filter: blur(4px);
}
.auth-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 3rem; }
.auth-grid h2 { font-family: var(--font-heading); font-size: 1.3rem; margin-bottom: 1.25rem; letter-spacing: -0.02em; }

.form-rows { display: flex; flex-direction: column; gap: 1rem; }
.form-rows label { font-size: 0.8rem; font-weight: 600; display: flex; flex-direction: column; gap: 0.35rem; }
.form-rows input {
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  padding: 0.65rem 1rem; outline: none;
  font-size: 0.9rem; background: var(--surface-muted);
}
.form-rows input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(54,58,116,0.08); }

.flat-btn {
  border: 0; background: var(--accent); color: #fff;
  font-weight: 700; padding: 0.75rem; border-radius: 999px;
  cursor: pointer; width: 100%; margin-top: 0.5rem;
  transition: background 0.2s, transform 0.1s;
}
.flat-btn:hover { background: var(--brand-blue-glow); transform: translateY(-1px); }

.entra-btn {
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  border: 1.5px solid var(--line); background: var(--surface-strong);
  color: var(--ink); font-weight: 600; padding: 0.75rem;
  border-radius: 999px; cursor: pointer; width: 100%;
  transition: background 0.2s, border-color 0.2s;
}
.entra-btn:hover { background: var(--accent-soft); border-color: rgba(54,58,116,0.22); }

/* ─── Search & Results ───────────────────────────────────────────────────── */
.search-wrap, .access-wrap { width: min(clamp(600px, 75vw, 1100px), calc(100% - 2rem)); margin: 2rem auto; }
.search-input-wrap { display: flex; gap: 0.5rem; margin-bottom: 2rem; }
.search-input-wrap input {
  flex: 1; border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  padding: 0.7rem 1rem; outline: none; background: var(--surface-strong);
}
.search-input-wrap input:focus { border-color: var(--accent); }
.search-query-btn {
  border: 0; background: var(--accent); color: #fff; font-weight: 700;
  padding: 0 1.5rem; border-radius: 999px; cursor: pointer; transition: background 0.2s;
}
.search-query-btn:hover { background: var(--brand-blue-glow); }

.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; margin-top: 1.5rem; }
.topic-card {
  background: var(--surface); border: 1px solid rgba(255,255,255,0.72);
  border-radius: var(--radius-md); padding: 1.25rem; font-weight: 600;
  box-shadow: var(--shadow-sm); cursor: pointer; transition: all 0.2s;
}
.topic-card:hover { border-color: rgba(54,58,116,0.2); transform: translateY(-2px); box-shadow: var(--shadow-md); }

.result-item {
  background: var(--surface); border: 1px solid rgba(255,255,255,0.72);
  border-radius: var(--radius-md); padding: 1.5rem; margin-bottom: 1rem;
  box-shadow: var(--shadow-sm); transition: box-shadow 0.2s;
}
.result-item:hover { box-shadow: var(--shadow-md); }
.result-item h3 { font-family: var(--font-heading); font-size: 1.1rem; color: var(--accent); margin-bottom: 0.5rem; }
.result-item p  { font-size: 0.88rem; color: var(--ink-soft); margin-bottom: 1rem; }

/* ─── Access Denied ──────────────────────────────────────────────────────── */
.access-card {
  background: var(--surface); border: 1px solid rgba(255,255,255,0.72);
  border-radius: var(--radius-lg); padding: 3rem; text-align: center; box-shadow: var(--shadow);
}
.access-card h1 { font-family: var(--font-heading); font-size: 1.8rem; margin-bottom: 0.5rem; }
.access-card p  { color: var(--ink-soft); margin-bottom: 1.5rem; }

/* ─── Footer ────────────────────────────────────────────────────────────── */
.footer {
  text-align: center; padding: 1.2rem 0.4rem;
  font-size: 0.72rem; color: var(--ink-soft);
  background: transparent; flex-shrink: 0;
  width: 100%;
}

/* ─── Shell Skeleton ─────────────────────────────────────────────────────── */
.shell-skeleton {
  display: inline-flex; border-radius: 999px;
  background: linear-gradient(90deg, rgba(54,58,116,0.08), rgba(54,58,116,0.14), rgba(54,58,116,0.08));
  background-size: 200% 100%; animation: shellShimmer 1.2s linear infinite;
}
.shell-skeleton-pill   { width: 5.5rem; height: 2.8rem; }
.shell-skeleton-avatar { width: 2.8rem; height: 2.8rem; }
@keyframes shellShimmer {
  from { background-position:  200% 0; }
  to   { background-position: -200% 0; }
}
.header-actions {
  display: flex; align-items: center; gap: 0.75rem;
  min-height: 2.8rem; min-width: 10rem; justify-content: flex-end;
}

/* ─── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .pp-header { padding: 0.75rem 1rem; flex-direction: column; gap: 0.75rem; min-height: auto; }
  .pp-nav { width: 100%; justify-content: center; }
  .auth-grid { grid-template-columns: 1fr; gap: 2rem; }
  .suggestions, .skeleton-suggestions { grid-template-columns: 1fr; }
  .chat-message { max-width: 95%; }
  .pdf-popup { padding: 0.5rem; }
  .chat-input-area { padding: 0 0.75rem 0; }
  .regenerate-container { flex-wrap: wrap; padding: 0.5rem 0.75rem 0.4rem; }
  .ref-toast { width: 90vw; white-space: normal; text-align: center; justify-content: center; }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100%; z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.22s cubic-bezier(.4,0,.2,1), width 0.22s;
    box-shadow: var(--shadow);
  }
  .sidebar:not(.retracted) { transform: translateX(0); width: var(--sidebar-w); }
  /* Keep a slim handle visible so mobile users can reopen the sidebar */
  .sidebar.retracted { transform: translateX(calc(-100% + var(--sidebar-w-slim))); }

  /* Avoid chat content sitting under the slim sidebar handle */
  .webui-main {
    transition: padding-left 0.22s cubic-bezier(.4,0,.2,1);
  }
  .sidebar.retracted + .webui-main {
    padding-left: var(--sidebar-w-slim);
  }
}

@media (max-width: 480px) {
  .searchContainer { border-radius: 18px; }
  .chat-header { font-size: 1.6rem; }
  .welcome-screen { padding: 1rem 1rem 0; }
}

/* ==========================================================================
   NUCLEAR OVERRIDES — must be last in the cascade to beat styles.css
   ========================================================================== */
.webui-main .chat-footer-wrap,
.webui-layout .chat-footer-wrap,
section .chat-footer-wrap,
.chat-footer-wrap.chat-footer-wrap {
  position: static !important;
  left: auto !important;
  right: auto !important;
  top: auto !important;
  bottom: auto !important;
  transform: none !important;
  pointer-events: auto !important;
  width: 100% !important;
  max-width: 760px !important;
  flex-shrink: 0 !important;
}

.webui-main .chat-input-area,
.webui-layout .chat-input-area,
section .chat-input-area,
.chat-input-area.chat-input-area,
.chat-input-area.bottom,
.chat-input-area.centered {
  position: static !important;
  left: auto !important;
  right: auto !important;
  top: auto !important;
  bottom: auto !important;
  transform: none !important;
  z-index: auto !important;
}

/* Empty-state centering (Gemini style) */
.webui-main.is-empty .chat-footer-wrap,
.webui-main:not(.is-active) .chat-footer-wrap {
  position: static !important;
}

/* ─── Page-specific (was styles.css) ─────────────────────────────────────── */
.gear-container { position: relative; }

.gear-button {
  border: 1px solid var(--line);
  background: var(--surface-strong);
  border-radius: 999px;
  width: 38px; height: 38px;
  cursor: pointer; font-size: 1.1rem;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: background 0.2s, transform 0.2s;
  outline: none; color: var(--ink-soft);
}
.gear-button:hover {
  background: var(--accent-soft);
  border-color: rgba(54,58,116,0.22);
  transform: rotate(40deg);
}

.text-action {
  border: 0; background: transparent;
  color: var(--accent); font-size: 0.82rem;
  font-weight: 600; cursor: pointer;
  padding: 0; text-decoration: underline;
}
.text-action:hover { color: var(--brand-blue-glow); }

.admin-output {
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 1rem; font-family: monospace;
  font-size: 0.78rem; max-height: 450px;
  overflow: auto; margin-top: 1.5rem;
}

/* ─── Sidebar footer: ALWAYS visible ─────────────────────────────────────── */
.sidebar-footer,
.sidebar-footer * {
  visibility: visible !important;
}

.sidebar-footer,
.sidebar-footer .sidebar-btn,
.sidebar-footer .sidebar-lang-wrap,
.sidebar-footer .sidebar-user,
.sidebar-footer #sidebarUserProfileLink {
  display: flex !important;
  opacity: 1 !important;
  height: auto !important;
  overflow: visible !important;
  max-height: none !important;
  pointer-events: auto !important;
}

/* The link wrapper needs display:block not flex */
#sidebarUserProfileLink {
  display: block !important;
}


/* ==========================================================================
   PROFILE PAGE COMPONENT LAYOUT RULES (Fixes missing design blocks)
   ========================================================================== */

/* Page Outer Scrollable Shell Container */
.page-wrap {
  width: min(780px, calc(100% - 2.5rem));
  margin: 2.5rem auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  animation: profileFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes profileFadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Navigation Hierarchy Breadcrumbs */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.breadcrumb a {
  color: var(--accent);
}
.breadcrumb a:hover {
  color: var(--brand-blue-glow);
  text-decoration: underline;
}

.breadcrumb-sep {
  color: var(--line);
  font-weight: 400;
}

/* Main Visual Form Layout Panel */
.profile-section {
  background: var(--surface-strong);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

/* Top Hero Badge Row */
.profile-hero {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding-bottom: 1.75rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 1.5rem;
}

.profile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #ffffff;
  font-size: 1.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px var(--accent-soft);
  flex-shrink: 0;
  user-select: none;
}

.profile-hero-info {
  display: flex;
  flex-direction: column;
}

.profile-title {
  font-family: var(--font-heading);
  font-size: 1.85rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.2;
}

/* Notice/Explainer block */
.profile-notice {
  font-size: 0.88rem;
  color: var(--ink-soft);
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  padding: 1rem 1.25rem;
  border-radius: 8px;
  line-height: 1.55;
  margin-bottom: 2rem;
}

/* Form Headings and Containers */
.profile-form-wrap {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.profile-form-heading {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
}

/* Two-column responsive input wrapper grid */
.profile-field-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem 1.5rem;
}

/* Form Input Element Label Structures */
.profile-label {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink);
}

.profile-label .req {
  color: #ef4444;
  margin-left: 0.15rem;
}

/* Input Fields, Dropdowns & Controls */
.profile-label input[type="text"],
.profile-label input[type="email"],
.profile-label input[type="tel"],
.profile-label select {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.72rem 1.1rem;
  font-size: 0.93rem;
  color: var(--ink);
  background: var(--surface-strong);
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
  -webkit-appearance: none;
  appearance: none;
}

.profile-label input:focus,
.profile-label select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3.5px var(--accent-soft);
}

/* Select custom dropdown chevron icon alignment */
.profile-label select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23646884' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1.1rem center;
  background-size: 1rem;
  padding-right: 2.5rem;
  cursor: pointer;
}

/* Block style modifier override for Read-Only parameters */
.profile-label .input-readonly {
  background: var(--surface-muted) !important;
  color: var(--ink-soft) !important;
  border-color: var(--line) !important;
  cursor: not-allowed;
}

/* Helper utility for forcing elements full width inside grid matrices */
.profile-label--full {
  grid-column: span 2;
}

/* Transaction Status & Notification blocks */
.profile-msg {
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.45;
}

.profile-msg.success-state {
  background: hsl(92, 56%, 95%);
  color: hsl(92, 56%, 24%);
  border: 1px solid rgba(132, 188, 52, 0.25);
}

.profile-msg.error-state {
  background: hsl(0, 84%, 97%);
  color: hsl(0, 84%, 30%);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

/* Execution Button Trigger Adjustments */
.profile-save-btn {
  margin-top: 0.5rem;
  padding: 0.85rem;
  font-size: 0.93rem;
  align-self: flex-start;
  min-width: 140px;
}

/* Responsive constraints on compressed screens */
@media (max-width: 640px) {
  .profile-section {
    padding: 1.5rem;
  }
  .profile-field-grid {
    grid-template-columns: 1fr;
  }
  .profile-label--full {
    grid-column: span 1;
  }
  .profile-save-btn {
    width: 100%;
  }
}
/* ==========================================================================
   STREAMING DOUBLE-BUBBLE STABILITY OVERRIDES
   ========================================================================== */

/* The root row wrapper should never draw boundaries, card surfaces, or shadows */
.chat-window .chat-message,
.chat-window .chat-message.ai-message,
.chat-window .typing-indicator-container {
  background: transparent !important;
  background-color: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
}

/* Force only the actual leaf text content wrapper to inherit card surfaces */
.chat-window .chat-message .message-content {
  background: var(--surface-strong) !important;
  color: var(--ink) !important;
  border: 1px solid var(--line) !important;
  box-shadow: var(--shadow-sm) !important;
  padding: 0.85rem 1.15rem !important;
  border-radius: var(--radius-md) !important;
  border-bottom-left-radius: 5px !important;
}

/* Prevent double borders if message content wrappers are nested inside each other */
.chat-window .message-content .message-content {
  background: transparent !important;
  background-color: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  margin: 0 !important;
  border-radius: 0 !important;
}

/* Ensure user-messages keep their custom linear gradient intact */
.chat-window .user-message .message-content {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong)) !important;
  color: #ffffff !important;
  border-bottom-right-radius: 5px !important;
  border-bottom-left-radius: var(--radius-md) !important;
  border: none !important;
}

/* ─── GLOBAL SCROLL RESTORE FOR NON-APP PAGES ─── */
body[data-page="access-denied"],
body[data-page="landing"],
body[data-page="public"] {
  height: auto !important;
  min-height: 100vh !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
}

html:has(body[data-page="access-denied"]),
html:has(body[data-page="landing"]),
html:has(body[data-page="public"]) {
  height: auto !important;
  overflow: auto !important;
}