:root {
  color-scheme: light;
  --bg: #f7f7f5;
  --panel: #ffffff;
  --sidebar: #efefec;
  --surface: #f4f4f1;
  --surface-hover: #e5e5df;
  --text: #20201e;
  --muted: #74746e;
  --border: #dfdfda;
  --accent: #171715;
  --accent-text: #ffffff;
  --green: #1f9d62;
  --red: #c74444;
  --shadow: 0 14px 40px rgba(30, 30, 25, 0.09);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

button,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  height: 100%;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  padding: 14px 12px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.brand-row,
.topbar,
.composer-footer {
  display: flex;
  align-items: center;
}

.brand-row {
  justify-content: space-between;
  min-height: 40px;
  padding: 0 6px 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  font-weight: 650;
  text-decoration: none;
}

.brand-mark,
.empty-mark {
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 750;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
}

.new-thread-button {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 9px;
  padding: 10px 11px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  text-align: left;
}

.new-thread-button:hover,
.icon-button:hover {
  background: var(--surface-hover);
}

.sidebar-label {
  padding: 20px 10px 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.thread-list {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.thread-item {
  display: block;
  width: 100%;
  margin: 2px 0;
  padding: 9px 10px;
  overflow: hidden;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-item:hover {
  background: var(--surface-hover);
}

.thread-item.active {
  background: var(--panel);
  box-shadow: 0 1px 2px rgba(30, 30, 25, 0.06);
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 10px 2px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--border);
}

.connection-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  background: var(--green);
  border-radius: 50%;
}

.connection-dot.offline {
  background: var(--red);
}

.connection-state {
  margin-left: auto;
}

.main-panel {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--panel);
  overflow: hidden;
}

.topbar {
  min-height: 68px;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
}

.thread-heading {
  min-width: 0;
  flex: 1;
}

.thread-heading h1,
.thread-heading p {
  overflow: hidden;
  margin: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-heading h1 {
  font-size: 14px;
  font-weight: 650;
}

.thread-heading p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.icon-button {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
}

.auth-button,
.primary-button {
  padding: 8px 12px;
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
}

.auth-button {
  max-width: min(220px, 28vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.primary-button {
  padding: 11px 18px;
  font-size: 14px;
}

.login-state {
  max-width: 560px;
}

.conversation {
  min-height: 0;
  padding: 38px max(24px, calc((100% - 780px) / 2));
  overflow-y: auto;
  overscroll-behavior: contain;
}

.empty-state {
  max-width: 620px;
  margin: min(14vh, 120px) auto 0;
  text-align: center;
}

.empty-mark {
  width: 48px;
  height: 48px;
  margin: 0 auto 20px;
  border-radius: 14px;
  font-size: 22px;
}

.empty-state h2 {
  margin: 0;
  font-size: clamp(24px, 4vw, 34px);
  letter-spacing: -0.03em;
}

.empty-state p {
  margin: 10px 0 28px;
  color: var(--muted);
}

.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.suggestion-grid button {
  min-height: 78px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
}

.suggestion-grid button:hover {
  background: var(--surface);
}

.message {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 12px;
  max-width: 780px;
  margin: 0 auto 28px;
}

.message-avatar {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 12px;
  font-weight: 700;
}

.message.user .message-avatar {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.message-content {
  min-width: 0;
  padding-top: 4px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.message-meta {
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 650;
}

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 20px;
}

.typing-indicator span {
  width: 5px;
  height: 5px;
  background: var(--muted);
  border-radius: 50%;
  animation: typing-pulse 1.1s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 140ms;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 280ms;
}

@keyframes typing-pulse {
  0%,
  60%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }

  30% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.composer-wrap {
  padding: 12px max(24px, calc((100% - 780px) / 2)) 18px;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0), var(--panel) 18%);
}

.composer {
  padding: 12px;
  background: var(--panel);
  border: 1px solid #cfcfc9;
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.composer:focus-within {
  border-color: #8f8f88;
  box-shadow: 0 0 0 3px rgba(30, 30, 25, 0.07), var(--shadow);
}

.composer.disabled {
  opacity: 0.55;
}

.composer textarea {
  display: block;
  width: 100%;
  max-height: 180px;
  padding: 2px 2px 12px;
  resize: none;
  background: transparent;
  color: var(--text);
  border: 0;
  outline: 0;
  line-height: 1.5;
}

.composer textarea::placeholder {
  color: #989890;
}

.composer-footer {
  justify-content: space-between;
}

.context-chip {
  display: inline-flex;
  max-width: calc(100% - 52px);
  align-items: center;
  gap: 7px;
  padding: 6px 9px;
  overflow: hidden;
  background: var(--surface);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.send-button {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  font-size: 18px;
  font-weight: 700;
}

.send-button:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

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

.scrim {
  position: fixed;
  z-index: 10;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
}

.mobile-only {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #171715;
    --panel: #1d1d1a;
    --sidebar: #242421;
    --surface: #2b2b27;
    --surface-hover: #32322e;
    --text: #f1f1ed;
    --muted: #aaa9a1;
    --border: #363631;
    --accent: #f1f1ed;
    --accent-text: #181816;
    --shadow: 0 16px 44px rgba(0, 0, 0, 0.28);
  }

  .composer-wrap {
    background: linear-gradient(to bottom, rgba(29, 29, 26, 0), var(--panel) 18%);
  }

  .composer {
    border-color: #505049;
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .mobile-only {
    display: grid;
  }

  .sidebar {
    position: fixed;
    z-index: 20;
    inset: 0 auto 0 0;
    width: min(86vw, 320px);
    transform: translateX(-102%);
    transition: transform 160ms ease;
    box-shadow: var(--shadow);
  }

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

  .main-panel {
    height: 100%;
  }

  .conversation {
    padding: 28px 18px;
  }

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

  .suggestion-grid {
    grid-template-columns: 1fr;
  }

  .suggestion-grid button {
    min-height: auto;
  }
}
