:root {
  color-scheme: light;
  --bg: #f4f8ff;
  --surface: #ffffff;
  --surface-strong: #eef5ff;
  --primary: #0f5fd9;
  --primary-dark: #0b3d91;
  --text: #10233f;
  --muted: #5b6b86;
  --border: rgba(15, 95, 217, 0.16);
  --shadow: 0 24px 60px rgba(10, 34, 77, 0.12);
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

body {
  margin: 0;
  font-family: 'Inter', 'Segoe UI', sans-serif;
  background:
    radial-gradient(circle at top left, rgba(15, 95, 217, 0.16), transparent 24%),
    linear-gradient(135deg, #f7faff 0%, #eef4ff 100%);
  color: var(--text);
  line-height: 1.5;
}

button,
input {
  font: inherit;
}

.page-shell {
  min-height: 100vh;
  padding: 24px clamp(20px, 4vw, 48px) 40px;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1180px;
  margin: 0 auto 36px;
  width: 100%;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #20a4ff);
  color: white;
  box-shadow: 0 10px 20px rgba(15, 95, 217, 0.25);
}

.topnav {
  display: flex;
  gap: 22px;
}

.topnav a {
  text-decoration: none;
  color: var(--muted);
  font-weight: 500;
  transition: color 0.2s;
}

.topnav a:hover {
  color: var(--primary);
}

/* =========================================
   AUTH PAGE STYLES
   ========================================= */
.hero-grid {
  max-width: 1180px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 32px;
  align-items: center;
  width: 100%;
  flex: 1;
}

.hero-copy {
  padding: 16px 0;
}

.eyebrow {
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--primary);
  font-weight: 700;
  font-size: 0.78rem;
}

.hero-copy h1 {
  margin: 0 0 16px;
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: 1.08;
  color: #07162c;
}

.hero-text {
  margin: 0 0 24px;
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--muted);
  max-width: 560px;
}

.feature-list {
  padding: 0;
  margin: 0;
  display: grid;
  gap: 12px;
  list-style: none;
}

.feature-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 600;
}

.feature-list li::before {
  content: '✓';
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: rgba(15, 95, 217, 0.12);
  color: var(--primary);
  font-size: 13px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 26px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

.card-kicker {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}

.card-header h2 {
  margin: 0;
  font-size: 1.3rem;
}

.pill {
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--primary-dark);
  font-size: 0.85rem;
  font-weight: 700;
}

.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface-strong);
  border-radius: 14px;
  padding: 5px;
  margin-bottom: 18px;
}

.mode-btn {
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.mode-btn.active {
  background: white;
  color: var(--primary-dark);
  box-shadow: 0 10px 18px rgba(15, 95, 217, 0.12);
}

.auth-form {
  display: none;
  flex-direction: column;
  gap: 14px;
}

.auth-form.active-form {
  display: flex;
}

label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
}

input {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(16, 35, 63, 0.12);
  background: #fdfefe;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 95, 217, 0.1);
}

button {
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.1s, box-shadow 0.2s;
}

button:active {
  transform: scale(0.98);
}

.auth-form button,
.session-state button {
  background: linear-gradient(135deg, var(--primary), #2092ff);
  color: white;
  box-shadow: 0 12px 24px rgba(15, 95, 217, 0.2);
}

.auth-form button:hover,
.session-state button:hover {
  box-shadow: 0 14px 28px rgba(15, 95, 217, 0.3);
}

.secondary-link {
  background: transparent !important;
  color: var(--primary-dark) !important;
  box-shadow: none !important;
  padding: 0;
  text-align: left;
  font-weight: 600;
}

.secondary-link:hover {
  text-decoration: underline;
}

.status-banner {
  min-height: 24px;
  margin-bottom: 14px;
  font-size: 0.95rem;
  color: var(--primary-dark);
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(15, 95, 217, 0.05);
}

.status-banner.error {
  color: #c0392b;
  background: rgba(192, 57, 43, 0.08);
}

.status-banner.success {
  color: #1f7a4f;
  background: rgba(31, 122, 79, 0.08);
}

.helper-text {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
  font-size: 0.9rem;
}

.session-state {
  display: none;
  padding: 14px;
  border-radius: 16px;
  background: #f4f9ff;
  border: 1px solid rgba(15, 95, 217, 0.14);
  margin-top: 16px;
}

.session-state.active {
  display: block;
}

.session-state h3 {
  margin: 0 0 8px;
  font-size: 1rem;
  color: var(--primary-dark);
}

.session-state p {
  margin: 0 0 12px;
  font-size: 0.9rem;
  color: var(--muted);
}

/* =========================================
   CHAT APP
   ========================================= */
.chat-body {
  overflow: hidden;
}

.chat-app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
  background:
    radial-gradient(circle at top left, rgba(15, 95, 217, 0.12), transparent 28%),
    linear-gradient(160deg, #f7faff 0%, #eef4ff 100%);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
  z-index: 10;
}

.chat-header-start,
.chat-header-end {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.chat-header-end {
  flex-shrink: 0;
}

.brand-compact {
  font-size: 1rem;
}

.brand-compact .brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
}

.icon-btn {
  display: none;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 10px;
  background: var(--surface-strong);
  color: var(--primary-dark);
  box-shadow: none;
  flex-shrink: 0;
}

.session-pill {
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(15, 95, 217, 0.1);
  color: var(--primary-dark);
  font-size: 0.82rem;
  font-weight: 600;
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.secondary-btn {
  background: transparent;
  color: var(--primary-dark);
  box-shadow: none;
  border: 1px solid rgba(15, 95, 217, 0.16);
  padding: 8px 14px;
  font-size: 0.85rem;
  white-space: nowrap;
}

.secondary-btn:hover {
  background: rgba(15, 95, 217, 0.05);
  border-color: var(--primary);
}

.chat-app-body {
  display: grid;
  grid-template-columns: 272px 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ---- Sidebar ---- */
.chat-sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: rgba(255, 255, 255, 0.72);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.chat-sidebar-top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 14px 0;
  flex-shrink: 0;
}

.sidebar-close-btn {
  display: none;
}

.sidebar-tabs {
  display: flex;
  flex: 1;
  gap: 4px;
  padding: 4px;
  background: var(--surface-strong);
  border-radius: 12px;
}

.sidebar-tab {
  flex: 1;
  padding: 8px 10px;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: none;
}

.sidebar-tab.active {
  background: #fff;
  color: var(--primary-dark);
  box-shadow: 0 2px 8px rgba(15, 95, 217, 0.1);
}

.sidebar-panel {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 14px;
  overflow: hidden;
}

.sidebar-panel.active {
  display: flex;
}

.sidebar-section-label {
  margin: 0 0 8px 4px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.new-chat-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-bottom: 14px;
  padding: 11px 14px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #2092ff);
  color: white;
  font-size: 0.88rem;
  box-shadow: 0 6px 16px rgba(15, 95, 217, 0.22);
}

.chat-history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
  margin: 0 -4px;
  padding: 0 4px;
}

.sidebar-status,
.sidebar-empty {
  padding: 20px 8px;
  color: var(--muted);
  font-size: 0.84rem;
  text-align: center;
  line-height: 1.5;
}

.chat-history-item {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  border: none;
  cursor: pointer;
  box-shadow: none;
  transition: background 0.15s;
}

.chat-history-item:hover {
  background: rgba(15, 95, 217, 0.06);
}

.chat-history-item.active {
  background: rgba(15, 95, 217, 0.12);
}

.chat-history-item.active .chat-history-title {
  color: var(--primary-dark);
}

.chat-history-title {
  display: block;
  font-size: 0.86rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.chat-history-date {
  display: block;
  font-size: 0.74rem;
  color: var(--muted);
  font-weight: 500;
}

.load-more-btn {
  margin-top: 8px;
  width: 100%;
  padding: 8px;
  border-radius: 10px;
  background: var(--surface-strong);
  color: var(--primary-dark);
  font-size: 0.8rem;
  font-weight: 600;
  box-shadow: none;
}

.settings-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding-right: 2px;
}

.settings-section {
  margin-bottom: 20px;
}

.settings-heading {
  margin: 0 0 10px;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--primary);
  font-weight: 700;
}

.settings-list {
  margin: 0;
}

.settings-row {
  margin-bottom: 12px;
}

.settings-row dt {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 3px;
}

.settings-row dd {
  margin: 0;
  font-size: 0.86rem;
  font-weight: 500;
  word-break: break-all;
}

.settings-mono {
  font-family: ui-monospace, monospace;
  font-size: 0.76rem;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text);
}

.settings-field select {
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid rgba(16, 35, 63, 0.12);
  background: #fdfefe;
  color: var(--text);
  font-weight: 500;
}

.settings-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.settings-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

.settings-logout-btn {
  margin-top: 12px;
  width: 100%;
  padding: 10px;
  border-radius: 12px;
  background: transparent;
  color: #c0392b;
  border: 1px solid rgba(192, 57, 43, 0.25);
  font-size: 0.86rem;
  box-shadow: none;
  flex-shrink: 0;
}

.settings-logout-btn:hover {
  background: rgba(192, 57, 43, 0.06);
}

/* ---- Main chat area ---- */
.chat-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--surface);
}

.chat-main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid rgba(15, 95, 217, 0.1);
  flex-shrink: 0;
}

.chat-context {
  min-width: 0;
  flex: 1;
}

.chat-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-subtitle {
  margin: 4px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agent-selector {
  position: relative;
  flex-shrink: 0;
}

.agent-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 4px;
}

.agent-dropdown-button {
  min-width: 160px;
  border-radius: 12px;
  border: 1px solid rgba(15, 95, 217, 0.14);
  background: #f8fbff;
  color: var(--primary-dark);
  padding: 9px 14px;
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.88rem;
  box-shadow: none;
  text-transform: capitalize;
}

.agent-dropdown-button:hover {
  border-color: var(--primary);
  background: #fff;
}

.agent-dropdown-button .chevron {
  flex-shrink: 0;
  opacity: 0.6;
}

.agent-dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: min(280px, 80vw);
  max-height: 320px;
  overflow-y: auto;
  background: #ffffff;
  border: 1px solid rgba(15, 95, 217, 0.14);
  border-radius: 14px;
  box-shadow: 0 18px 45px rgba(15, 95, 217, 0.14);
  z-index: 50;
  padding: 6px;
}

.agent-menu-item {
  width: 100%;
  text-align: left;
  padding: 11px 12px;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  border-radius: 10px;
  box-shadow: none;
}

.agent-menu-item strong {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 3px;
  text-transform: capitalize;
}

.agent-menu-item .agent-tools {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agent-menu-item:hover,
.agent-menu-item.active {
  background: rgba(15, 95, 217, 0.08);
}

.agent-menu-item.active strong {
  color: var(--primary);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  scroll-behavior: smooth;
}

.empty-chat-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 240px;
  text-align: center;
  padding: 32px 24px;
  color: var(--muted);
}

.empty-chat-icon {
  font-size: 2.4rem;
  margin-bottom: 12px;
  line-height: 1;
}

.empty-chat-state h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
  color: var(--text);
}

.empty-chat-state p {
  margin: 0;
  font-size: 0.92rem;
  max-width: 320px;
  line-height: 1.6;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  max-width: min(720px, 88%);
  padding: 14px 16px;
  border-radius: 16px;
  line-height: 1.6;
  animation: fadeIn 0.25s ease-out;
}

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

.message.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--primary), #2092ff);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: #f4f8ff;
  color: var(--text);
  border: 1px solid rgba(15, 95, 217, 0.08);
  border-bottom-left-radius: 4px;
}

.message-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.75rem;
  flex-shrink: 0;
}

.message.user .message-avatar {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

.message.assistant .message-avatar {
  background: rgba(15, 95, 217, 0.15);
  color: var(--primary-dark);
}

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

.message-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
  opacity: 0.75;
}

.message.user .message-label {
  color: rgba(255, 255, 255, 0.9);
}

.message-body {
  word-wrap: break-word;
}

.message-body p:first-child {
  margin-top: 0;
}

.message-body p:last-child {
  margin-bottom: 0;
}

.chat-composer-wrap {
  flex-shrink: 0;
  padding: 16px 24px 20px;
  border-top: 1px solid rgba(15, 95, 217, 0.1);
  background: #fff;
}

.chat-composer {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f8fbff;
  border: 1.5px solid rgba(15, 95, 217, 0.14);
  border-radius: 16px;
  padding: 6px 6px 6px 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-composer:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 95, 217, 0.1);
  background: #fff;
}

.chat-composer input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 0.95rem;
  padding: 11px 0;
  color: var(--text);
  min-width: 0;
}

.chat-composer input::placeholder {
  color: var(--muted);
}

.chat-composer input:focus {
  outline: none;
  box-shadow: none;
  border-color: transparent;
}

.send-button {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, var(--primary), #2092ff);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(15, 95, 217, 0.25);
}

.send-button:hover {
  transform: scale(1.04);
}

.composer-hint {
  margin: 10px 0 0;
  font-size: 0.74rem;
  color: var(--muted);
  text-align: center;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(7, 22, 44, 0.4);
  z-index: 90;
}

/* ---- Chat responsive ---- */
@media (max-width: 900px) {
  .chat-app-body {
    grid-template-columns: 1fr;
  }

  .chat-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(300px, 88vw);
    z-index: 100;
    border-right: none;
    border-radius: 0 16px 16px 0;
    box-shadow: 8px 0 32px rgba(10, 34, 77, 0.15);
    transform: translateX(-105%);
    transition: transform 0.25s ease;
  }

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

  .icon-btn,
  .sidebar-close-btn {
    display: inline-grid;
  }

  .session-pill {
    max-width: 140px;
  }

  .chat-main-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 14px 16px;
  }

  .agent-selector {
    width: 100%;
  }

  .agent-dropdown-button {
    width: 100%;
  }

  .agent-dropdown-menu {
    right: 0;
    left: 0;
    width: 100%;
  }
}

@media (max-width: 640px) {
  .chat-header {
    padding: 10px 14px;
  }

  .session-pill {
    display: none;
  }

  .chat-messages {
    padding: 16px;
  }

  .message {
    max-width: 94%;
    padding: 12px 14px;
  }

  .chat-composer-wrap {
    padding: 12px 14px 16px;
  }

  .composer-hint {
    display: none;
  }
}

/* =========================================
   RESPONSIVE DESIGN (Auth)
   ========================================= */
@media (max-width: 900px) {
  .hero-grid {
    grid-template-columns: 1fr;
  }

  .hero-copy {
    order: 2;
    text-align: center;
  }

  .hero-text {
    margin: 0 auto 24px;
  }

  .feature-list {
    max-width: 400px;
    margin: 0 auto;
  }
}

@media (max-width: 640px) {
  .page-shell {
    padding: 16px;
  }

  .auth-card {
    padding: 20px;
  }
}