:root {
  color-scheme: light;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background: #ffffff;
  color: #0d0d0d;
}

* { box-sizing: border-box; }

html {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  position: fixed;
  inset: 0;
  width: 100%;
  background: #ffffff;
}

button, textarea { font: inherit; }
button { cursor: pointer; }

.shell {
  height: 100dvh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 248px 1fr;
  overflow: hidden;
  overscroll-behavior: none;
}

.sidebar {
  position: fixed;
  z-index: 20;
  inset: 0 auto 0 0;
  width: 248px;
  height: 100dvh;
  border-right: 1px solid #ececec;
  background: #f9f9f9;
  padding: 12px 6px;
  overflow: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 18;
  border: 0;
  background: rgba(0, 0, 0, 0.28);
}

.sidebar-backdrop[hidden] {
  display: none;
}

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

.sidebar-collapsed .sidebar {
  display: none;
}

.sidebar-collapsed .chat-area {
  grid-column: 1;
}

.sidebar-collapsed .composer {
  left: 50%;
  width: min(640px, calc(100vw - 48px));
}

.sidebar-collapsed .conversation {
  width: min(760px, calc(100vw - 48px));
}

.sidebar-icon-button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #202123;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  -webkit-tap-highlight-color: transparent;
}

.sidebar-icon-button:hover {
  background: #eeeeee;
}

.sidebar-restore {
  position: fixed;
  z-index: 30;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  background: #ffffff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 34px;
  padding: 0 8px;
  margin-bottom: 10px;
}

.sidebar-title {
  color: #0d0d0d;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0;
}

.sidebar-toggle {
  margin-right: -2px;
}

.menu-icon,
.sidebar-panel-icon {
  position: relative;
  display: block;
  width: 18px;
  height: 18px;
}

.menu-icon::before,
.menu-icon::after,
.menu-icon {
  border-top: 2px solid currentColor;
}

.menu-icon::before,
.menu-icon::after {
  content: "";
  position: absolute;
  left: 0;
  width: 18px;
}

.menu-icon::before { top: 6px; }
.menu-icon::after { top: 14px; }

.sidebar-panel-icon {
  border: 1.8px solid currentColor;
  border-radius: 4px;
}

.sidebar-panel-icon::before {
  content: "";
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 6px;
  border-left: 1.8px solid currentColor;
}

.new-chat-button,
.sidebar-link {
  width: 100%;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  color: #0d0d0d;
  text-align: left;
  font-size: 14px;
}

.new-chat-button:hover,
.sidebar-link:hover,
.chat-list-item:hover,
.chat-list-item.active,
.context-menu button:hover {
  background: #eeeeee;
}

.context-menu button {
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #0d0d0d;
  text-align: left;
  padding: 0 8px;
}

.chat-section-title {
  margin: 22px 0 8px;
  padding: 0 8px;
  color: #5f5f5f;
  font-size: 13px;
  font-weight: 600;
}

.chat-list {
  display: grid;
  gap: 1px;
  padding-bottom: 18px;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
}

.user-panel {
  display: grid;
  gap: 6px;
  padding: 10px;
  color: #5f5f5f;
  font-size: 12px;
}

.user-panel span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-panel button,
.auth-card button {
  height: 34px;
  border: 1px solid #d9d9d9;
  border-radius: 8px;
  background: #ffffff;
  color: #0d0d0d;
}

.chat-list-item {
  width: 100%;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #0d0d0d;
  overflow: hidden;
  padding: 0 10px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.context-menu {
  position: fixed;
  z-index: 20;
  width: 132px;
  border: 1px solid #d9d9d9;
  border-radius: 10px;
  background: #ffffff;
  padding: 6px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.14);
}

.context-menu button {
  width: 100%;
  height: 34px;
  padding: 0 10px;
}

#deleteChatButton {
  color: #b91c1c;
}

.chat-area {
  grid-column: 2;
  min-width: 0;
  height: 100dvh;
  overflow: hidden;
}

.conversation {
  width: min(760px, calc(100vw - 320px));
  height: 100%;
  margin: 0 auto;
  padding: 52px 0 130px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.empty-state {
  min-height: 45vh;
  display: grid;
  place-content: end center;
  text-align: center;
}

.empty-state h1 {
  max-width: 760px;
  margin: 0;
  color: #202123;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.42;
}

.empty-state p {
  max-width: 760px;
  margin: 10px 0 0;
  color: #707070;
  font-size: 10px;
  line-height: 1.4;
}

.message {
  display: grid;
  gap: 8px;
  margin: 0 0 28px;
}

.message.user { justify-items: end; }

.bubble {
  max-width: min(720px, 100%);
  border-radius: 18px;
  padding: 12px 16px;
  white-space: pre-wrap;
  line-height: 1.62;
  font-size: 15px;
  background: #ffffff;
}

.user .bubble { background: #f4f4f4; }

.sources {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.source {
  border: 1px solid #e3e3e3;
  border-radius: 10px;
  padding: 10px 12px;
  background: #fafafa;
  color: #5f5f5f;
  text-align: left;
  font-size: 13px;
  line-height: 1.45;
}

.source:hover { background: #f4f4f4; }

.source-title {
  color: #202123;
  font-weight: 600;
}

.composer {
  position: fixed;
  left: calc(248px + ((100vw - 248px) / 2));
  bottom: 30px;
  transform: translateX(-50%);
  width: min(640px, calc(100vw - 320px));
  border: 1px solid #d9d9d9;
  border-radius: 28px;
  background: #ffffff;
  box-shadow: 0 18px 55px rgba(0, 0, 0, 0.08);
}

.is-empty .conversation { padding-bottom: 0; }

.is-empty .composer {
  top: calc(50% + 42px);
  bottom: auto;
}

.composer-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 34px;
  gap: 8px;
  align-items: center;
  padding: 8px;
}

.attach-button,
#submitButton {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
}

.attach-button {
  background: transparent;
  color: #0d0d0d;
  font-size: 24px;
  line-height: 1;
}

.attach-button:hover { background: #f4f4f4; }
.attach-button input { display: none; }

#questionInput {
  width: 100%;
  max-height: 160px;
  min-height: 24px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 2px 0;
  color: #0d0d0d;
  line-height: 1.5;
}

#submitButton {
  background: #0d0d0d;
  color: #ffffff;
  font-size: 18px;
  font-weight: 700;
}

#submitButton:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.attachment-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px 0;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 260px;
  border: 1px solid #e3e3e3;
  border-radius: 8px;
  padding: 6px 8px;
  background: #fafafa;
  color: #5f5f5f;
  font-size: 13px;
}

.attachment-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-chip button {
  border: 0;
  background: transparent;
  color: #707070;
}

.source-dialog {
  width: min(880px, calc(100vw - 32px));
  max-height: min(760px, calc(100vh - 48px));
  border: 1px solid #d9d9d9;
  border-radius: 14px;
  padding: 0;
  background: #ffffff;
  color: #0d0d0d;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.18);
}

.source-dialog::backdrop { background: rgba(0, 0, 0, 0.22); }

.source-dialog-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding: 18px 20px;
  border-bottom: 1px solid #ececec;
}

.source-dialog h2 {
  margin: 0 0 5px;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: 0;
}

.source-dialog p {
  margin: 0;
  color: #707070;
  font-size: 13px;
}

#closeSourceDialog,
#closeKnowledgeDialog {
  height: 34px;
  border: 1px solid #d9d9d9;
  border-radius: 8px;
  background: #ffffff;
}

#sourceText,
#knowledgeStats {
  margin: 0;
  padding: 20px;
  max-height: 620px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font: 15px/1.72 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

.error { color: #b91c1c; }

.auth-dialog {
  width: min(380px, calc(100vw - 32px));
  border: 1px solid #d9d9d9;
  border-radius: 16px;
  padding: 0;
  background: #ffffff;
  color: #0d0d0d;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.18);
}

.auth-dialog::backdrop { background: rgba(255, 255, 255, 0.78); }

.auth-card {
  display: grid;
  gap: 12px;
  padding: 24px;
}

.auth-card h2 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: 0;
}

.auth-card input {
  height: 42px;
  border: 1px solid #d9d9d9;
  border-radius: 10px;
  padding: 0 12px;
  outline: 0;
}

.auth-card input:focus { border-color: #0d0d0d; }

#authError {
  min-height: 18px;
  margin: 0;
  color: #b91c1c;
  font-size: 13px;
}

#authSubmitButton {
  border-color: #0d0d0d;
  background: #0d0d0d;
  color: #ffffff;
}

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }

  .sidebar {
    width: min(280px, 86vw);
    height: 100dvh;
    border-right: 1px solid #ececec;
    border-bottom: 0;
    box-shadow: 18px 0 42px rgba(0, 0, 0, 0.12);
    transition: transform 180ms ease;
  }

  .sidebar-collapsed .sidebar {
    display: flex;
    transform: translateX(-100%);
  }

  .sidebar-collapsed .composer {
    width: calc(100vw - 24px);
  }

  .sidebar-collapsed .conversation {
    width: calc(100vw - 24px);
  }

  .sidebar-backdrop {
    display: block;
  }

  .chat-area { grid-column: 1; }

  .conversation {
    width: calc(100vw - 24px);
    padding-top: 28px;
  }

  .composer {
    left: 50%;
    width: calc(100vw - 24px);
    bottom: 12px;
  }
}
