:root {
  --primary: #16a34a;
  --primary-dark: #15803d;
  --primary-light: #f0fdf4;
  --text: #111827;
  --text-secondary: #4b5563;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --bg: #ffffff;
  --surface: #f3f4f6;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

/* ── Utils ── */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ── Inputs / Buttons ── */
input[type="text"], input[type="tel"] {
  width: 100%;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 14px;
  font-size: 15px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  outline: none;
}
input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(22,163,74,.12); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 48px;
  border-radius: 12px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  padding: 0 20px;
  transition: opacity .15s;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--primary); color: #fff; width: 100%; }
.btn-primary:not(:disabled):hover { background: var(--primary-dark); }
.btn-ghost { background: var(--surface); color: var(--text-secondary); }
.btn-text {
  background: transparent;
  color: var(--text-secondary);
  border: none;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  padding: 6px 8px;
  border-radius: 8px;
}
.btn-text:hover { color: var(--text); background: var(--surface); }
.btn-danger-text { color: var(--danger); }
.btn-danger-text:hover { background: var(--danger-bg); }

/* ── Login page ── */
.login-page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 0 28px;
  position: relative;
}

.lang-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  height: 36px;
  padding: 0 14px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
}

.brand {
  margin-top: 100px;
  text-align: center;
}
.brand-logo {
  max-width: 160px;
  max-height: 72px;
  width: auto;
  height: auto;
  border-radius: 12px;
  margin: 0 auto;
  display: block;
}
.brand-name {
  margin-top: 20px;
  font-size: 26px;
  font-weight: 700;
}
.brand-tagline {
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 14px;
}

.login-form {
  margin-top: 56px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  display: block;
}
.otp-row {
  display: flex;
  gap: 10px;
}
.otp-row input { flex: 1; }
.otp-row .btn { flex-shrink: 0; width: auto; min-width: 100px; font-size: 14px; }

.login-hint {
  margin-top: 6px;
  font-size: 13px;
  color: var(--primary);
  min-height: 20px;
  text-align: center;
}
.login-error {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  min-height: 20px;
}

/* ── Chat page ── */
.chat-page {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.topbar-logo {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  object-fit: contain;
}
.topbar-name {
  font-size: 17px;
  font-weight: 600;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.menu-icon {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 6px 4px;
  margin-right: 6px;
  cursor: pointer;
  flex-shrink: 0;
}
.menu-icon span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}

/* messages */
.msg-scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.msg-row { display: flex; }
.msg-row.is-user { justify-content: flex-end; }
.msg-row.is-ai   { justify-content: flex-start; }

.bubble {
  max-width: 80%;
  padding: 11px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bubble-user { background: var(--primary); color: #fff; border-bottom-right-radius: 6px; }
.bubble-ai   { background: var(--surface); color: var(--text); border-bottom-left-radius: 6px; }

.bubble-text { white-space: pre-wrap; word-break: break-word; }

/* markdown inside AI bubble */
.bubble-md { word-break: break-word; line-height: 1.65; color: inherit; }
.bubble-md p { margin: 0 0 8px; }
.bubble-md p:last-child { margin-bottom: 0; }
.bubble-md h1,.bubble-md h2,.bubble-md h3,
.bubble-md h4,.bubble-md h5,.bubble-md h6 { font-weight: 700; margin: 12px 0 6px; line-height: 1.3; }
.bubble-md h1 { font-size: 19px; }
.bubble-md h2 { font-size: 17px; }
.bubble-md h3 { font-size: 15px; }
.bubble-md h4,.bubble-md h5,.bubble-md h6 { font-size: 14px; }
.bubble-md strong { font-weight: 700; }
.bubble-md em { font-style: italic; }
.bubble-md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  background: rgba(0,0,0,.07);
  padding: 2px 6px;
  border-radius: 4px;
}
.bubble-md pre {
  background: rgba(0,0,0,.06);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}
.bubble-md pre code { background: transparent; padding: 0; font-size: 13px; line-height: 1.55; }
.bubble-md ul,.bubble-md ol { padding-left: 22px; margin: 6px 0; }
.bubble-md li { margin: 3px 0; }
.bubble-md a { color: var(--primary); text-decoration: underline; }
.bubble-md blockquote {
  border-left: 3px solid rgba(0,0,0,.18);
  padding-left: 12px;
  margin: 8px 0;
  color: rgba(0,0,0,.65);
}
.bubble-md hr { border: none; border-top: 1px solid rgba(0,0,0,.12); margin: 12px 0; }
.bubble-md table { border-collapse: collapse; margin: 8px 0; font-size: 13px; }
.bubble-md th,.bubble-md td { border: 1px solid rgba(0,0,0,.15); padding: 5px 10px; }
.bubble-md th { background: rgba(0,0,0,.04); font-weight: 600; }

/* markdown overrides inside green user bubble */
.bubble-user .bubble-md a { color: #fff; }
.bubble-user .bubble-md code { background: rgba(255,255,255,.18); }
.bubble-user .bubble-md pre { background: rgba(255,255,255,.12); }
.bubble-user .bubble-md pre code { background: transparent; }
.bubble-user .bubble-md blockquote { border-left-color: rgba(255,255,255,.45); color: rgba(255,255,255,.9); }
.bubble-user .bubble-md th { background: rgba(255,255,255,.15); }
.bubble-user .bubble-md th,.bubble-user .bubble-md td { border-color: rgba(255,255,255,.4); }
.bubble-user .bubble-md hr { border-top-color: rgba(255,255,255,.3); }

/* images in bubble */
.bubble-images { display: flex; flex-wrap: wrap; gap: 6px; }
.bubble-image { width: 160px; height: 160px; object-fit: cover; border-radius: 10px; cursor: pointer; }

/* thinking dots */
.thinking { display: flex; gap: 5px; align-items: center; padding: 4px 0; }
.thinking span {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted);
  animation: blink 1.2s infinite;
}
.thinking span:nth-child(2) { animation-delay: .2s; }
.thinking span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,60%,100%{ opacity:.3; transform:scale(.85); } 30%{ opacity:1; transform:scale(1); } }

/* bottom */
.bottom { flex-shrink: 0; border-top: 1px solid var(--border); padding: 8px 12px 12px; }
.action-row {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-bottom: 10px;
}
.action-pill {
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding: 0 16px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  gap: 4px;
}
.action-pill:hover { border-color: var(--text-muted); color: var(--text); }
.action-pill.primary { background: var(--primary-light); border-color: var(--primary-light); color: var(--primary); }
.action-pill.primary:hover { background: #dcfce7; }

/* image preview strip */
.preview-strip { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.preview-item { position: relative; width: 68px; height: 68px; }
.preview-thumb { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; }
.preview-rm {
  position: absolute; top: -6px; right: -6px;
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(0,0,0,.75); color: #fff;
  border: none; cursor: pointer;
  font-size: 13px; line-height: 20px; text-align: center;
}
.preview-status {
  position: absolute; inset: 0; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
}
.preview-status.uploading { background: rgba(255,255,255,.7); color: var(--text-secondary); }
.preview-status.failed { background: rgba(220,38,38,.8); color: #fff; font-weight: 700; }

.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border-radius: 24px;
  padding: 8px 8px 8px 14px;
}
.attach-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg); border: 1px solid var(--border);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-size: 22px; color: var(--text-muted); line-height: 1;
}
.composer-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  outline: none;
  resize: none;
  min-height: 24px;
  max-height: 120px;
  line-height: 1.5;
}
.send-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--primary); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.send-btn:disabled { background: #d1d5db; cursor: default; }
.send-icon { width: 0; height: 0; border-top: 8px solid transparent; border-bottom: 8px solid transparent; border-left: 12px solid #fff; margin-left: 2px; }

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

/* drawer */
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 100;
}
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: 82%; max-width: 340px;
  background: var(--bg); z-index: 101;
  transform: translateX(-105%); transition: transform .25s ease;
  display: flex; flex-direction: column;
  box-shadow: 4px 0 20px rgba(0,0,0,.1);
}
.drawer.open { transform: translateX(0); }

.drawer-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 16px 14px;
  border-bottom: 1px solid var(--border);
}
.drawer-title { font-size: 17px; font-weight: 600; }
.drawer-header-right { display: flex; align-items: center; gap: 4px; }
.drawer-clear { font-size: 13px; color: var(--danger); cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.drawer-clear:hover { background: var(--danger-bg); }
.drawer-close { font-size: 26px; color: var(--text-muted); cursor: pointer; padding: 0 4px; line-height: 1; }

.drawer-list { flex: 1; overflow-y: auto; }
.drawer-item { display: flex; align-items: stretch; border-bottom: 1px solid var(--border); }
.drawer-item.active { background: var(--primary-light); }
.drawer-item-main { flex: 1; padding: 14px 8px 14px 16px; cursor: pointer; min-width: 0; }
.drawer-item-main:hover { background: var(--surface); }
.drawer-item-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-item-time { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.drawer-item-del { width: 44px; display: flex; align-items: center; justify-content: center; font-size: 18px; color: #d1d5db; cursor: pointer; }
.drawer-item-del:hover { color: var(--danger); }
.drawer-empty { text-align: center; padding: 40px 16px; color: var(--text-muted); font-size: 14px; }

/* loading overlay */
.full-loading {
  position: fixed; inset: 0; background: rgba(255,255,255,.6);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.full-loading-box {
  background: #111827; color: #fff; border-radius: 12px; padding: 14px 24px; font-size: 14px;
}
