:root {
  color-scheme: dark;
  --bg: #020617;
  --panel: rgba(15, 23, 42, 0.92);
  --panel-strong: rgba(15, 23, 42, 0.98);
  --border: rgba(148, 163, 184, 0.28);
  --text: #ececec;
  --muted: rgba(148, 163, 184, 0.9);
  --accent: #38bdf8;
  --shadow: 0 18px 55px rgba(2, 6, 23, 0.65);
}

* {
  box-sizing: border-box;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  appearance: none;
  -webkit-appearance: none;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: radial-gradient(circle at top, #020617, #000);
  color: var(--text);
  overflow: hidden;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 292px 1fr;
  overflow: hidden;
}

.sidebar-collapsed .app-shell {
  grid-template-columns: 0 1fr;
}

.sidebar {
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.98), rgba(2, 6, 23, 0.98));
  border-right: 1px solid rgba(148, 163, 184, 0.18);
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  gap: 10px;
  min-width: 0;
  overflow: hidden;
  min-height: 0;
  height: 100vh;
}

.sidebar[hidden] {
  display: none;
}

.sidebar-collapsed .sidebar {
  width: 0;
  padding: 0;
  border-right: 0;
}

.sidebar-collapsed .sidebar-actions,
.sidebar-collapsed .sidebar-section-title,
.sidebar-collapsed .chat-list,
.sidebar-collapsed .sidebar-footer,
.sidebar-collapsed .sidebar-brand {
  display: none !important;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 8px;
}

.ico-sidebar {
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
}

.ico-sidebar::before {
  content: "⟨";
  font-size: 18px;
  line-height: 1;
  color: rgba(226, 232, 240, 0.92);
  transform: translateY(-1px);
}

.sidebar-collapsed .ico-sidebar::before {
  content: "⟩";
}

.sidebar-toggle {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 999px;
}

.sidebar-collapsed .sidebar .sidebar-toggle {
  display: grid !important;
  position: fixed;
  left: 12px;
  top: 12px;
  z-index: 60;
}

.sidebar-collapsed #sidebarToggleBtn {
  display: grid !important;
  position: fixed !important;
  left: 12px;
  top: 12px;
  z-index: 60;
}

.sidebar-brand {
  color: var(--muted);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  min-width: 0;
}

.brand-mark {
  width: 25px;
  height: 25px;
  display: inline-block;
  border-radius: 4px;
  object-fit: cover;
}

.sidebar-actions {
  display: grid;
  gap: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  border-radius: 12px;
  padding: 10px 10px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  cursor: pointer;
  line-height: 1;
}

.nav-item:hover {
  background: rgba(56, 189, 248, 0.08);
  border-color: rgba(56, 189, 248, 0.25);
}

.nav-ico {
  width: 18px;
  display: inline-flex;
  justify-content: center;
  color: var(--muted);
}

.nav-search {
  cursor: text;
}

.nav-search input {
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  width: 100%;
  font-size: 13px;
  padding: 0;
}

.sidebar-section-title {
  margin-top: 8px;
  padding: 4px 8px;
  color: var(--muted);
  font-size: 12px;
}

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

.chat-item {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 10px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.chat-item-main {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 2px;
}

.chat-item-menu-btn {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  color: rgba(236, 236, 236, 0.7);
  display: grid;
  place-items: center;
}

.chat-item:hover .chat-item-menu-btn {
  background: rgba(255, 255, 255, 0.04);
}

.chat-item-menu-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

.chat-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.chat-item.active {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.08);
}

.chat-item-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-meta {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-menu {
  position: fixed;
  min-width: 190px;
  background: #2a2a2a;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 6px;
  z-index: 200;
  box-shadow: 0 16px 55px rgba(0, 0, 0, 0.55);
}

.chat-item-menu[hidden] {
  display: none;
}

.menu-item {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: rgba(236, 236, 236, 0.92);
  padding: 10px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
}

.menu-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.menu-item.danger {
  color: #fb7185;
}

.menu-item.danger:hover {
  background: rgba(251, 113, 133, 0.12);
}

.sidebar-footer {
  border-top: 1px solid rgba(148, 163, 184, 0.18);
  padding-top: 10px;
  position: sticky;
  bottom: 0;
  background: transparent;
}

.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(2, 6, 23, 0.45);
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.account-email {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
  overflow: hidden;
}

.main-topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  color: var(--muted);
  border-bottom: 1px solid rgba(148, 163, 184, 0.18);
}

.main-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.main-right {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
  max-width: 60vw;
}

.topbar-btn {
  padding: 7px 10px;
  font-size: 12px;
  border-radius: 10px;
}

#contextValue {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 34vw;
}

.auth-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(6px);
  z-index: 160;
}

.auth-modal[hidden] {
  display: none;
}

.auth-card {
  max-width: 440px;
  width: min(440px, calc(100% - 36px));
  background: var(--panel-strong);
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.auth-modal h1 {
  margin: 0 0 6px 0;
  font-size: 20px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.auth-grid {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

label span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type="email"],
input[type="password"],
input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(2, 6, 23, 0.45);
  color: var(--text);
  outline: none;
}

.auth-actions {
  display: flex;
  gap: 10px;
}

.btn,
.text-btn,
.icon-btn {
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(2, 6, 23, 0.45);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover,
.text-btn:hover,
.icon-btn:hover {
  background: rgba(56, 189, 248, 0.10);
  border-color: rgba(56, 189, 248, 0.28);
}

.btn-primary {
  background: rgba(56, 189, 248, 0.14);
  border-color: rgba(56, 189, 248, 0.35);
}

.btn-primary:hover {
  background: rgba(56, 189, 248, 0.18);
}

.text-btn {
  padding: 8px 10px;
  font-size: 12px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 999px;
}

.hint {
  min-height: 18px;
  font-size: 12px;
  color: var(--muted);
}

.hint.error {
  color: #fb7185;
}

.chat-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

html.auth-active .sidebar,
html.auth-active .main-topbar,
html.auth-active #chatPanel {
  opacity: 0.08;
  filter: blur(1px);
  pointer-events: none;
  user-select: none;
}

.hero {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px 16px 0 16px;
}

.hero[hidden] {
  display: none;
}

.hero-title {
  font-size: clamp(26px, 3vw, 44px);
  font-weight: 500;
  color: rgba(226, 232, 240, 0.95);
}

.hero-card {
  width: min(760px, 100%);
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.9), rgba(2, 6, 23, 0.9));
  border-radius: 20px;
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
}

.hero-subtitle {
  margin-top: 8px;
  color: rgba(148, 163, 184, 0.95);
  font-size: 14px;
}

.hero-steps {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.step {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(2, 6, 23, 0.38);
}

.step-num {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: rgba(226, 232, 240, 0.95);
  background: rgba(56, 189, 248, 0.10);
  font-weight: 700;
  font-size: 12px;
  flex: 0 0 auto;
}

.step-title {
  font-weight: 700;
  color: rgba(226, 232, 240, 0.95);
  font-size: 13px;
}

.step-desc {
  margin-top: 3px;
  color: rgba(148, 163, 184, 0.95);
  font-size: 13px;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.hero-context {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.pill {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(2, 6, 23, 0.45);
}

.messages {
  flex: 1;
  overflow: auto;
  padding: 22px 0 18px 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 170px;
}

.msg-row {
  width: min(720px, calc(100% - 36px));
  margin: 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.msg-row.user {
  flex-direction: row-reverse;
}

.avatar {
  min-width: 28px;
  max-width: 120px;
  height: 26px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 650;
  color: rgba(236, 236, 236, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  flex: 0 0 auto;
  margin-top: 3px;
  padding: 0 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.avatar.user {
  background: rgba(99, 102, 241, 0.18);
  border-color: rgba(99, 102, 241, 0.35);
}

.avatar.agent {
  background: rgba(34, 197, 94, 0.14);
  border-color: rgba(34, 197, 94, 0.28);
}

.avatar.system {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.12);
}

.bubble {
  max-width: 100%;
  line-height: 1.45;
  font-size: 14.5px;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
}

.bubble a {
  color: rgba(147, 197, 253, 0.95);
  text-decoration: underline;
  text-decoration-color: rgba(147, 197, 253, 0.5);
  word-break: break-word;
}

.msg-row.user .bubble {
  text-align: left;
}

.bubble.user {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.12);
}

.bubble.agent {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.1);
}

.bubble.system {
  color: var(--muted);
  font-size: 13px;
  background: rgba(255, 255, 255, 0.02);
}

.typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.typing-bubble .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(236, 236, 236, 0.7);
  animation: tx-bounce 1.2s infinite ease-in-out;
}

.typing-bubble .dot:nth-child(2) {
  animation-delay: 0.15s;
}
.typing-bubble .dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes tx-bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.35;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.composer {
  position: sticky;
  bottom: 0;
  z-index: 20;
  background: var(--bg);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding: 12px 0 14px 0;
}

.composer-row {
  width: min(720px, calc(100% - 36px));
  margin: 0 auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  background: #2f2f2f;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  padding: 10px 10px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

.composer-row input[type="text"] {
  border: 0;
  background: transparent;
  padding: 10px 6px;
  color: var(--text);
}

.composer-row input[type="text"]::placeholder {
  color: rgba(236, 236, 236, 0.55);
}

.footer {
  width: min(720px, calc(100% - 36px));
  margin: 10px auto 0 auto;
  text-align: center;
  display: grid;
  gap: 6px;
}

.footer-note {
  font-size: 12px;
  color: var(--muted);
}

.footer-links {
  font-size: 12px;
  color: var(--muted);
}

.footer-links a {
  color: var(--muted);
  text-decoration: none;
}

.footer-links a:hover {
  text-decoration: underline;
}

.footer-links .sep {
  margin: 0 8px;
  color: rgba(236, 236, 236, 0.35);
}

.attachments {
  width: min(720px, calc(100% - 36px));
  margin: 0 auto 10px auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.file-chip {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  font-size: 12px;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
}

.file-chip button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(320px, 92vw);
    z-index: 50;
    box-shadow: var(--shadow);
    transform: translateX(0);
    transition: transform 180ms ease;
  }

  .sidebar-collapsed .sidebar {
    transform: translateX(-110%);
    width: min(320px, 92vw);
    padding: 14px 12px;
    border-right: 1px solid rgba(255, 255, 255, 0.06);
  }
}
