:root {
  color-scheme: light;
  --sidebar: #f7f7f8;
  --border: #e8eaf0;
  --text: #0f172a;
  --muted: #9aa3b2;
  --soft: #f4f6f8;
  --chip: #f3f4f6;
  --blue: #1677ff;
  --blue-soft: #e9f1ff;
  font-family:
    "Inter", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system,
    BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: #cfd8e6 transparent;
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: #cfd8e6;
  background-clip: padding-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: #ffffff;
  overflow: hidden;
}

button,
textarea {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  width: 100vw;
  height: 100vh;
  background: #fff;
}

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

.app-shell.sidebar-collapsed .sidebar {
  overflow: hidden;
  border-right: 0;
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  min-width: 0;
  border-right: 1px solid var(--border);
  background: var(--sidebar);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 58px;
  padding: 0 16px;
  font-size: 18px;
}

.avatar {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(145deg, #ffffff, #dff4ff);
  box-shadow: inset 0 0 0 1px rgba(22, 119, 255, 0.12);
}

.doctor-logo {
  position: relative;
  width: 30px;
  height: 30px;
}

.doctor-logo span {
  position: absolute;
  display: block;
}

.cap {
  top: 2px;
  left: 6px;
  width: 19px;
  height: 8px;
  border-radius: 6px 6px 3px 3px;
  background: linear-gradient(135deg, #1677ff, #37c7ff);
  transform: rotate(-8deg);
}

.cap::before {
  position: absolute;
  top: -4px;
  left: 3px;
  width: 14px;
  height: 6px;
  content: "";
  clip-path: polygon(50% 0, 100% 55%, 50% 100%, 0 55%);
  background: #155bd4;
}

.cap::after {
  position: absolute;
  top: 4px;
  right: -6px;
  width: 8px;
  height: 1px;
  content: "";
  background: #155bd4;
  transform: rotate(32deg);
}

.face {
  top: 9px;
  left: 7px;
  width: 17px;
  height: 16px;
  border-radius: 48%;
  background:
    radial-gradient(circle at 25% 58%, rgba(255, 149, 171, 0.34), transparent 14%),
    radial-gradient(circle at 76% 58%, rgba(255, 149, 171, 0.34), transparent 14%),
    linear-gradient(180deg, #fff3df, #f4cfad);
}

.face::after {
  position: absolute;
  left: 6px;
  bottom: 3px;
  width: 5px;
  height: 3px;
  content: "";
  border-bottom: 1px solid #9f6456;
  border-radius: 0 0 999px 999px;
}

.glasses {
  top: 14px;
  left: 9px;
  width: 13px;
  height: 4px;
  border-right: 1px solid #155bd9;
  border-left: 1px solid #155bd9;
}

.glasses::before,
.glasses::after {
  position: absolute;
  width: 4px;
  height: 4px;
  content: "";
  border: 1px solid #155bd9;
  border-radius: 50%;
}

.glasses::before {
  left: -2px;
}

.glasses::after {
  right: -2px;
}

.coat {
  bottom: 1px;
  left: 4px;
  width: 22px;
  height: 10px;
  border-radius: 9px 9px 4px 4px;
  background: linear-gradient(135deg, #fff, #dff4ff);
}

.tie {
  bottom: 4px;
  left: 14px;
  width: 3px;
  height: 7px;
  border-radius: 4px;
  background: #1677ff;
}

.new-chat,
.history button {
  display: flex;
  align-items: center;
  min-width: 0;
  border-radius: 12px;
  color: #111827;
  cursor: pointer;
  text-align: left;
}

.new-chat {
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  margin: 8px 14px 20px;
  color: var(--blue);
  background: var(--blue-soft);
  box-shadow: inset 0 0 0 1px rgba(22, 119, 255, 0.18);
  font-weight: 700;
}

.new-chat:hover {
  background: #dfeaff;
}

.history {
  min-height: 0;
  padding: 0 14px 14px;
  overflow-y: auto;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 9px 10px;
}

.history-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.history-head small {
  color: #c0c5ce;
  font-size: 12px;
}

.history-open {
  width: 100%;
  gap: 8px;
  min-height: 38px;
  padding: 0 10px;
  color: #3f4654;
  background: transparent;
  font-size: 14px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.history-open::before {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  content: "";
  border: 1px solid #d9dee7;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, #c8d0dc 0 2px, transparent 3px),
    #fff;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  align-items: center;
  border-radius: 12px;
}

.history-item.active {
  background: #eef4ff;
}

.history-delete {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border-radius: 8px;
  color: #a6afbd;
  background: transparent;
  cursor: pointer;
  font-size: 17px;
  opacity: 0;
}

.history-item:hover .history-delete,
.history-item.active .history-delete {
  opacity: 1;
}

.history-delete:hover {
  color: #d33f5f;
  background: #ffeef2;
}

.history-empty {
  padding: 12px 9px;
  color: #b4bbc7;
  font-size: 13px;
}

.history-open:hover,
.new-chat:hover {
  background: #eef2f7;
}

.main-stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(circle at 50% 38%, rgba(22, 119, 255, 0.035), transparent 32%),
    #ffffff;
}

.sidebar-auth {
  padding: 12px 14px 14px;
  border-top: 1px solid var(--border);
}

.auth-button {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 12px;
  color: var(--blue);
  background: var(--blue-soft);
  box-shadow: inset 0 0 0 1px rgba(22, 119, 255, 0.18);
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
}

.auth-button:hover {
  background: #dfeaff;
}

.topbar {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.88);
  flex-shrink: 0;
}

.topbar > div {
  grid-column: 2;
  display: grid;
  justify-items: center;
  gap: 3px;
}

.topbar strong {
  font-size: 14px;
}

.topbar span {
  color: #c0c5ce;
  font-size: 11px;
}

.sidebar-toggle {
  width: 34px;
  height: 34px;
  margin-left: 12px;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  font-size: 18px;
}

.sidebar-toggle:hover {
  background: #f3f4f6;
}

.chat-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.empty-state {
  position: absolute;
  top: 28%;
  left: 50%;
  z-index: 1;
  width: min(1120px, calc(100% - 80px));
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
}

.empty-state h1 {
  margin: 0 0 28px;
  font-size: clamp(26px, 3vw, 34px);
  line-height: 1.2;
  letter-spacing: 0;
}

.topic-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  pointer-events: auto;
}

.topic-grid button {
  min-height: 42px;
  padding: 0 17px;
  border-radius: 11px;
  color: #111827;
  background: var(--chip);
  cursor: pointer;
  font-size: 14px;
  transition:
    background 160ms ease,
    transform 160ms ease,
    box-shadow 160ms ease;
}

.topic-grid button:hover {
  background: #eaf2ff;
  box-shadow: 0 8px 22px rgba(22, 119, 255, 0.12);
  transform: translateY(-1px);
}

.messages {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 16px;
  min-height: 0;
  padding: 32px max(34px, calc((100% - 900px) / 2)) 24px;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.message {
  display: grid;
  gap: 8px;
  max-width: min(780px, 92%);
}

.message.user {
  align-self: flex-end;
}

.message.assistant {
  align-self: flex-start;
}

.label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.mini-avatar {
  position: relative;
  display: inline-block;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 58%, #f5d4b7 0 34%, transparent 35%),
    linear-gradient(145deg, #ffffff, #dff4ff);
  box-shadow: inset 0 0 0 1px rgba(22, 119, 255, 0.12);
}

.mini-avatar::before {
  position: absolute;
  top: 3px;
  left: 5px;
  width: 12px;
  height: 5px;
  content: "";
  border-radius: 4px 4px 2px 2px;
  background: linear-gradient(135deg, #1677ff, #35d4ff);
  transform: rotate(-8deg);
}

.mini-avatar::after {
  position: absolute;
  right: 5px;
  bottom: 4px;
  width: 12px;
  height: 7px;
  content: "";
  border-radius: 6px 6px 3px 3px;
  background: linear-gradient(135deg, #ffffff, #dff4ff);
}

.bubble {
  padding: 13px 16px;
  border-radius: 14px;
  line-height: 1.72;
  overflow-wrap: anywhere;
}

.bubble p {
  margin: 0;
}

.bubble p + p,
.bubble ul + p,
.bubble ol + p,
.bubble p + ul,
.bubble p + ol {
  margin-top: 10px;
}

.bubble ul,
.bubble ol {
  margin: 0;
  padding-left: 1.35em;
}

.bubble li + li {
  margin-top: 4px;
}

.bubble code {
  padding: 2px 5px;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.07);
  font-family: Consolas, "SFMono-Regular", Menlo, monospace;
  font-size: 0.92em;
}

.bubble pre {
  margin: 0;
  padding: 12px;
  overflow-x: auto;
  border-radius: 10px;
  background: #111827;
  color: #eef2ff;
}

.bubble pre code {
  padding: 0;
  background: transparent;
  color: inherit;
}

.message-actions {
  display: flex;
  gap: 6px;
  margin-top: -2px;
}

.message-actions button {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 8px;
  color: #667085;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
}

.message-actions button:hover {
  color: var(--blue);
  background: #eef4ff;
}

.follow-ups {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}

.follow-ups > span {
  display: inline-flex;
  align-items: center;
  color: #98a2b3;
  font-size: 12px;
}

.follow-ups button {
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  color: #344054;
  background: #f3f6fa;
  cursor: pointer;
  font-size: 12px;
}

.follow-ups button:hover {
  color: var(--blue);
  background: #eaf2ff;
}

.assistant .bubble {
  color: #1f2937;
  background: #f6f7f9;
}

.user .bubble {
  color: white;
  background: var(--blue);
  box-shadow: 0 10px 24px rgba(22, 119, 255, 0.18);
}

.assistant.streaming .bubble::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 1.1em;
  margin-left: 3px;
  vertical-align: -2px;
  background: var(--blue);
  animation: blink 1s steps(2, start) infinite;
}

.input-zone {
  position: relative;
  z-index: 2;
  display: grid;
  flex-shrink: 0;
  gap: 10px;
  width: min(800px, calc(100% - 68px));
  margin: 0 auto 16px;
  padding: 14px 16px;
  border: 1px solid rgba(22, 119, 255, 0.35);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow:
    0 24px 70px rgba(22, 119, 255, 0.14),
    0 0 0 4px rgba(22, 119, 255, 0.035);
}

.mode-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
}

.thinking-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #334155;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.thinking-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch {
  position: relative;
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: #d8dee8;
  transition: background 160ms ease;
}

.switch::before {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  content: "";
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 5px rgba(15, 23, 42, 0.18);
  transition: transform 160ms ease;
}

.thinking-toggle input:checked + .switch {
  background: var(--blue);
}

.thinking-toggle input:checked + .switch::before {
  transform: translateX(14px);
}

.thinking-toggle.loading {
  opacity: 0.62;
  cursor: wait;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 82px;
  gap: 12px;
}

textarea {
  width: 100%;
  max-height: 150px;
  min-height: 36px;
  padding: 7px 4px;
  resize: none;
  border: 0;
  outline: none;
  color: var(--text);
  background: transparent;
  line-height: 1.55;
}

textarea::placeholder {
  color: #b6bfca;
}

.composer button {
  min-height: 36px;
  border-radius: 999px;
  color: white;
  background: var(--blue);
  cursor: pointer;
  font-weight: 700;
}

.composer button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.error .bubble {
  color: #8f2443;
  background: #fff0f3;
}

.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.34);
}

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

.auth-dialog {
  position: relative;
  width: min(420px, 100%);
  padding: 22px;
  border: 1px solid rgba(22, 119, 255, 0.16);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.18);
}

.auth-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  color: #667085;
  background: transparent;
  cursor: pointer;
  font-size: 20px;
}

.auth-close:hover {
  color: var(--blue);
  background: #eef4ff;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 34px 18px 0;
  padding: 4px;
  border-radius: 12px;
  background: #f3f6fa;
}

.auth-tabs button {
  height: 34px;
  border-radius: 9px;
  color: #667085;
  background: transparent;
  cursor: pointer;
  font-weight: 700;
}

.auth-tabs button.active {
  color: var(--blue);
  background: #fff;
  box-shadow: 0 4px 12px rgba(22, 119, 255, 0.1);
}

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

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

.auth-form label {
  display: grid;
  gap: 6px;
  color: #344054;
  font-size: 13px;
  font-weight: 700;
}

.auth-form input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid #dbe3ef;
  border-radius: 10px;
  outline: none;
  color: var(--text);
  background: #fff;
}

.auth-form input:focus {
  border-color: rgba(22, 119, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(22, 119, 255, 0.08);
}

.code-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 104px;
  gap: 8px;
}

.code-row button {
  border-radius: 10px;
  color: var(--blue);
  background: var(--blue-soft);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.code-row button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.auth-msg {
  min-height: 18px;
  margin: 0;
  color: #8f2443;
  font-size: 12px;
}

.auth-msg.success {
  color: #027a48;
}

.auth-submit {
  height: 40px;
  border-radius: 999px;
  color: #fff;
  background: var(--blue);
  cursor: pointer;
  font-weight: 700;
}

.auth-submit:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.confirm-dialog {
  position: relative;
  display: grid;
  gap: 14px;
  width: min(360px, 100%);
  padding: 24px;
  border: 1px solid rgba(22, 119, 255, 0.16);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.18);
}

.confirm-dialog strong {
  color: var(--text);
  font-size: 18px;
}

.confirm-dialog p {
  margin: 0;
  color: #667085;
  font-size: 14px;
  line-height: 1.6;
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}

.confirm-actions button {
  height: 38px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 700;
}

.confirm-actions button:first-child {
  color: #344054;
  background: #f3f6fa;
}

.confirm-actions .danger {
  color: #fff;
  background: #d92d20;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* ── sidebar backdrop (mobile) ── */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  transition: opacity 200ms ease;
}

.sidebar-backdrop.visible {
  display: block;
  opacity: 1;
}

/* ── mobile responsive ── */
@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
    width: 280px;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 240ms ease;
    box-shadow: none;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 6px 0 24px rgba(0, 0, 0, 0.12);
  }

  .topbar {
    grid-template-columns: 40px 1fr 40px;
  }

  .sidebar-toggle {
    margin-left: 6px;
    font-size: 20px;
  }

  .empty-state {
    top: 16%;
    width: calc(100% - 32px);
  }

  .empty-state h1 {
    font-size: 22px;
    margin-bottom: 18px;
  }

  .messages {
    padding: 16px 12px 14px;
    gap: 12px;
  }

  .message {
    max-width: 95%;
  }

  .bubble {
    padding: 10px 13px;
    font-size: 14px;
    line-height: 1.65;
  }

  .input-zone {
    width: calc(100% - 20px);
    margin-bottom: 10px;
    padding: 10px 12px;
    border-radius: 18px;
  }

  .composer {
    grid-template-columns: minmax(0, 1fr) 64px;
    gap: 8px;
  }

  .composer button {
    min-height: 34px;
    font-size: 13px;
  }

  textarea {
    font-size: 16px; /* prevent iOS zoom */
  }

  .topic-grid {
    justify-content: flex-start;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 3px;
    gap: 8px;
  }

  .topic-grid button {
    white-space: nowrap;
    min-height: 36px;
    padding: 0 13px;
    font-size: 13px;
  }

  .follow-ups {
    gap: 6px;
  }

  .follow-ups button {
    min-height: 28px;
    font-size: 11px;
  }

  .mode-row {
    gap: 8px;
  }

  .thinking-toggle {
    font-size: 12px;
  }
}

@media (max-width: 400px) {
  .empty-state h1 {
    font-size: 19px;
  }

  .bubble {
    padding: 9px 11px;
    font-size: 13.5px;
  }

  .input-zone {
    width: calc(100% - 14px);
    padding: 8px 10px;
  }

  .messages {
    padding: 12px 8px 10px;
  }
}
