*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --blue: #2563eb;
  --blue-strong: #1d4ed8;
  --red: #f87171;
  --purple: #c084fc;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-soft: 0 20px 50px rgba(5, 6, 10, 0.45);
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--page-bg);
  color: var(--text-primary);
  transition: background 0.3s ease, color 0.3s ease;
}

body[data-theme='dark'] {
  --page-bg: #05060a;
  --panel-bg: #10131c;
  --panel-border: #1f2433;
  --sidebar-bg: linear-gradient(165deg, rgba(37, 99, 235, 0.15), rgba(192, 132, 252, 0.08));
  --sidebar-border: rgba(255, 255, 255, 0.08);
  --text-primary: #f4f6fb;
  --text-muted: #9ba3b7;
  --bubble-user: rgba(37, 99, 235, 0.12);
  --bubble-bot: rgba(255, 255, 255, 0.06);
  --input-bg: rgba(14, 19, 32, 0.85);
  --input-border: rgba(255, 255, 255, 0.08);
  --history-active: rgba(255, 255, 255, 0.08);
}

body[data-theme='light'] {
  --page-bg: #f5f6fb;
  --panel-bg: #ffffff;
  --panel-border: rgba(15, 23, 42, 0.08);
  --sidebar-bg: linear-gradient(165deg, rgba(37, 99, 235, 0.08), rgba(248, 113, 113, 0.08));
  --sidebar-border: rgba(15, 23, 42, 0.08);
  --text-primary: #0f172a;
  --text-muted: #5f6475;
  --bubble-user: rgba(37, 99, 235, 0.12);
  --bubble-bot: rgba(15, 23, 42, 0.06);
  --input-bg: rgba(248, 250, 255, 0.9);
  --input-border: rgba(15, 23, 42, 0.12);
  --history-active: rgba(37, 99, 235, 0.12);
}

.app-shell {
  display: flex;
  gap: 1.5rem;
  max-width: 1340px;
  margin: 0 auto;
  padding: 1.5rem;
  height: 100vh;
  overflow: hidden;
}

@media (max-width: 1024px) {
  .app-shell {
    flex-direction: column;
    padding: 1rem;
    height: auto;
    min-height: 100vh;
  }
}

.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--sidebar-border);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  max-height: 100%;
  overflow-y: auto;
}

@media (max-width: 1024px) {
  .sidebar {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    align-items: stretch;
    height: auto;
  }
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  font-weight: 600;
  text-transform: uppercase;
  color: #fff;
}

.brand-gradient {
  position: absolute;
  inset: 0;
  background: conic-gradient(from 120deg, var(--blue), var(--purple), var(--red), var(--blue));
  opacity: 0.85;
}

.brand-initials {
  position: relative;
  z-index: 1;
  letter-spacing: 0.08em;
}

.brand-copy .brand-name {
  font-weight: 600;
  margin: 0;
}

.brand-copy .brand-tagline {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.new-chat-btn {
  width: 100%;
  border: 1px dashed rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  font-size: 0.95rem;
  color: var(--text-primary);
  background: transparent;
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.new-chat-btn:hover {
  border-color: rgba(255, 255, 255, 0.65);
  transform: translateY(-1px);
}

.history-label {
  text-transform: uppercase;
  font-size: 0.76rem;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-right: 0.25rem;
}

.history-empty {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.history-list::-webkit-scrollbar {
  width: 6px;
}

.history-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 999px;
}

.history-item {
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 0.85rem 0.9rem;
  background: transparent;
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
  font-size: 0.9rem;
}

.history-item .title {
  display: block;
  font-weight: 500;
  margin-bottom: 0.15rem;
}

.history-item .timestamp {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.history-item:hover,
.history-item.active {
  background: var(--history-active);
  border-color: rgba(255, 255, 255, 0.1);
}

.chat-panel {
  flex: 1;
  background: var(--panel-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-soft);
  height: 100%;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--panel-border);
}

.chat-names {
  margin-bottom: 0.35rem;
}

.brand-label {
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.04em;
  font-size: 0.95rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.active-chat-title {
  margin: 0.2rem 0 0;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-primary);
}

.chat-meta h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
}

.chat-meta p {
  margin: 0.15rem 0 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.header-button {
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  padding: 0.45rem 1rem;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.9rem;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.header-button:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.theme-toggle {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 1.1rem;
  transition: transform 0.2s ease;
}

.theme-toggle:hover {
  transform: rotate(8deg) scale(1.05);
}

.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chat-container::-webkit-scrollbar {
  width: 10px;
}

.chat-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
}

.empty-state {
  text-align: center;
  margin: auto;
  max-width: 360px;
  color: var(--text-muted);
}

.empty-state h2 {
  color: var(--text-primary);
  margin: 0.25rem 0;
}

.empty-eyebrow {
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  color: var(--text-muted);
}

.message {
  max-width: 720px;
  padding: 1rem 1.2rem;
  border-radius: var(--radius-md);
  line-height: 1.55;
  font-size: 0.98rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user {
  align-self: flex-end;
  background: var(--bubble-user);
  border: 1px solid rgba(37, 99, 235, 0.35);
}

.message.bot {
  align-self: flex-start;
  background: var(--bubble-bot);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.message.loading {
  font-style: italic;
  color: var(--text-muted);
}

.composer {
  padding: 1rem 1.5rem 1.5rem;
  border-top: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.typing-status {
  min-height: 1.2rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  padding: 0.85rem 0.9rem;
  border-radius: var(--radius-md);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  backdrop-filter: blur(12px);
}

#messageInput {
  flex: 1;
  background: transparent;
  border: none;
  font-size: 1rem;
  color: var(--text-primary);
  resize: none;
  max-height: 160px;
  outline: none;
}

#messageInput::placeholder {
  color: var(--text-muted);
}

.send-button {
  width: 46px;
  height: 46px;
  border-radius: 999px;
  border: none;
  background: linear-gradient(120deg, var(--blue), var(--purple));
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.send-button svg {
  width: 24px;
  height: 24px;
  fill: #fff;
}

.send-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.send-button:not(:disabled):hover {
  transform: translateY(-1px) scale(1.02);
}

.error-message {
  display: none;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(248, 113, 113, 0.4);
  color: #fee2e2;
  background: rgba(248, 113, 113, 0.16);
  font-size: 0.88rem;
}

body[data-theme='light'] .error-message {
  color: #b91c1c;
  background: rgba(248, 113, 113, 0.12);
}

.error-message.show {
  display: block;
}

@media (max-width: 640px) {
  .sidebar {
    flex-direction: column;
  }

  body {
    overflow: auto;
  }

  .chat-panel {
    border-radius: 16px;
    height: auto;
  }

  .composer {
    padding: 0.85rem;
  }

  .chat-container {
    padding: 1rem;
  }
}
