:root {
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --bg-side: #f5f6f8;
  --line: #e6e8ec;
  --line-strong: #d9dce2;
  --text: #1b1f24;
  --text-2: #5a6270;
  --text-3: #8c93a1;
  --brand: #4d6bfe;
  --brand-dark: #3b55e6;
  --brand-soft: #eef1ff;
  --danger: #e04f4f;
  --radius: 14px;
  --shadow: 0 8px 28px rgba(20, 26, 40, .10);
}

* { box-sizing: border-box; }

/* 保证 hidden 属性始终生效（否则会被 .app / .lightbox 等的 display 覆盖） */
[hidden] { display: none !important; }

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

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

button { font-family: inherit; cursor: pointer; }
.mt10 { margin-top: 10px; }

/* ---------------- 登录页 ---------------- */
.login-view {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(900px 420px at 12% -10%, #eaf0ff 0%, rgba(234, 240, 255, 0) 62%),
    radial-gradient(760px 380px at 92% 8%, #eefaf4 0%, rgba(238, 250, 244, 0) 60%),
    var(--bg-soft);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 34px 30px 26px;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 13px; flex: none;
  background: linear-gradient(135deg, #5b7cff, #3d5bf0);
  color: #fff; font-weight: 700; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
  letter-spacing: .5px;
}
.brand h1 { margin: 0; font-size: 21px; font-weight: 650; letter-spacing: .3px; }
.brand-sub { color: var(--text-2); font-size: 13.5px; margin: 12px 0 20px; line-height: 1.6; }

.tabs {
  display: flex; gap: 4px; background: var(--bg-side);
  border-radius: 11px; padding: 4px; margin-bottom: 18px;
}
.tab {
  flex: 1; height: 34px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text-2); font-size: 14px; font-weight: 550;
}
.tab.active { background: #fff; color: var(--brand-dark); box-shadow: 0 1px 4px rgba(20,26,40,.10); }

.input {
  width: 100%; height: 44px; border: 1px solid var(--line-strong);
  border-radius: 11px; padding: 0 13px; font-size: 14.5px; color: var(--text);
  background: #fff; outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(77, 107, 254, .13); }
.input::placeholder { color: var(--text-3); }

.btn-primary {
  width: 100%; height: 46px; margin-top: 16px; border: 0; border-radius: 12px;
  background: var(--brand); color: #fff; font-size: 15.5px; font-weight: 600;
  transition: background .16s;
}
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:disabled { opacity: .6; cursor: default; }

.login-error {
  margin: 14px 0 0; padding: 10px 12px; border-radius: 10px;
  background: #fdf0f0; color: var(--danger); font-size: 13px;
}
.login-foot { text-align: center; color: var(--text-3); font-size: 11.5px; margin: 20px 0 0; }

/* ---------------- 主应用 ---------------- */
.app { display: flex; height: 100%; overflow: hidden; }

.sidebar {
  width: 268px; flex: none; background: var(--bg-side);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.side-top { padding: 14px 12px 10px; }
.new-chat {
  width: 100%; height: 42px; border-radius: 11px; border: 1px solid var(--line-strong);
  background: #fff; color: var(--text); font-size: 14px; font-weight: 550;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: .15s;
}
.new-chat:hover { border-color: var(--brand); color: var(--brand); }
.new-chat .plus { font-size: 16px; line-height: 1; }

.conv-list { flex: 1; overflow-y: auto; padding: 4px 10px 10px; min-height: 0; }
.conv-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; border-radius: 10px; margin-bottom: 2px;
  font-size: 13.8px; color: var(--text-2); cursor: pointer; user-select: none;
}
.conv-item:hover { background: #e9ebef; }
.conv-item.active { background: #e2e7ff; color: var(--brand-dark); font-weight: 550; }
.conv-item .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .del {
  flex: none; opacity: 0; border: 0; background: transparent; color: var(--text-3);
  font-size: 15px; line-height: 1; padding: 2px 4px; border-radius: 6px;
}
.conv-item:hover .del { opacity: 1; }
.conv-item .del:hover { color: var(--danger); background: #fff; }
.conv-empty { color: var(--text-3); font-size: 13px; padding: 18px 12px; text-align: center; }

.side-bottom { border-top: 1px solid var(--line); padding: 10px 12px 12px; }
.usage-line { font-size: 12px; color: var(--text-3); margin-bottom: 4px; }
.usage-line b { color: var(--text-2); font-weight: 600; }
.user-row { display: flex; align-items: center; gap: 9px; margin-top: 7px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  background: var(--brand-soft); color: var(--brand-dark);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 650; text-transform: uppercase;
}
.user-name {
  flex: 1; min-width: 0; font-size: 13.5px; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.link-btn { border: 0; background: transparent; color: var(--text-3); font-size: 12.5px; padding: 4px; }
.link-btn:hover { color: var(--danger); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 56px; flex: none; display: flex; align-items: center; gap: 12px;
  padding: 0 18px; border-bottom: 1px solid var(--line); background: #fff;
}
.menu-btn { display: none; }
.conv-title {
  flex: 1; min-width: 0; font-size: 15px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.model-pick { flex: none; }
.model-pick select {
  height: 34px; max-width: 240px; border: 1px solid var(--line-strong);
  border-radius: 9px; background: #fff; color: var(--text);
  font-size: 13.5px; padding: 0 8px; outline: none;
}
.model-pick select:focus { border-color: var(--brand); }

.free-notice {
  flex: none; font-size: 12px; color: #8a5a00;
  background: #fff7e6; border: 1px solid #ffe1a8;
  border-radius: 8px; padding: 3px 9px; white-space: nowrap;
}

.messages { flex: 1; overflow-y: auto; padding: 26px 20px 8px; min-height: 0; }
.msg-wrap { max-width: 820px; margin: 0 auto; }

.msg { display: flex; gap: 12px; margin-bottom: 24px; }
.msg .who {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}
.msg.user { flex-direction: row-reverse; }
.msg.user .who { background: var(--brand); color: #fff; }
.msg.assistant .who { background: var(--brand-soft); color: var(--brand-dark); }
.msg .body { min-width: 0; max-width: 100%; }
.msg.user .body {
  background: var(--brand-soft); border-radius: 14px 4px 14px 14px;
  padding: 10px 14px; max-width: 78%;
}
.msg.assistant .body { flex: 1; padding-top: 2px; }

.msg .text { word-wrap: break-word; overflow-wrap: anywhere; }
.msg .text > :first-child { margin-top: 0; }
.msg .text > :last-child { margin-bottom: 0; }
.msg .text p { margin: 0 0 10px; }
.msg .text h1, .msg .text h2, .msg .text h3, .msg .text h4 {
  margin: 16px 0 8px; line-height: 1.4; font-weight: 650;
}
.msg .text h1 { font-size: 19px; }
.msg .text h2 { font-size: 17px; }
.msg .text h3 { font-size: 15.5px; }
.msg .text ul, .msg .text ol { margin: 0 0 10px; padding-left: 22px; }
.msg .text li { margin: 3px 0; }
.msg .text blockquote {
  margin: 0 0 10px; padding: 2px 12px; border-left: 3px solid var(--line-strong);
  color: var(--text-2);
}
.msg .text a { color: var(--brand); text-decoration: none; border-bottom: 1px solid rgba(77,107,254,.35); }
.msg .text code {
  background: #f1f2f5; border-radius: 5px; padding: 1.5px 5px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: .88em; color: #c7254e;
}
.msg .text pre {
  margin: 0 0 12px; background: #1f2430; border-radius: 11px;
  padding: 13px 15px; overflow-x: auto;
}
.msg .text pre code {
  background: transparent; color: #e6e9f0; padding: 0; font-size: 13px; line-height: 1.6;
}
.msg .text table { border-collapse: collapse; margin: 0 0 12px; font-size: 13.5px; }
.msg .text th, .msg .text td { border: 1px solid var(--line-strong); padding: 6px 10px; }
.msg .text th { background: var(--bg-soft); font-weight: 600; }

.msg .thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.msg .thumbs img {
  width: 108px; height: 108px; object-fit: cover; border-radius: 10px;
  border: 1px solid var(--line); cursor: zoom-in; background: var(--bg-soft);
}

.think {
  border: 1px solid var(--line); background: var(--bg-soft);
  border-radius: 11px; margin-bottom: 12px; overflow: hidden;
}
.think summary {
  cursor: pointer; padding: 8px 12px; font-size: 13px; color: var(--text-2);
  list-style: none; user-select: none;
}
.think summary::-webkit-details-marker { display: none; }
.think summary::before { content: "▸ "; color: var(--text-3); }
.think[open] summary::before { content: "▾ "; }
.think .think-inner {
  padding: 0 12px 11px; font-size: 13.5px; color: var(--text-2);
  white-space: pre-wrap; word-wrap: break-word; max-height: 320px; overflow-y: auto;
}

.msg .meta { display: flex; gap: 12px; align-items: center; margin-top: 8px; }
.msg .meta button {
  border: 0; background: transparent; color: var(--text-3); font-size: 12.5px; padding: 2px 0;
}
.msg .meta button:hover { color: var(--brand); }
.msg .meta .tokens { font-size: 12px; color: var(--text-3); margin-left: auto; }

.msg .err {
  margin-top: 8px; padding: 9px 12px; border-radius: 10px;
  background: #fdf0f0; color: var(--danger); font-size: 13px;
}

.cursor {
  display: inline-block; width: 7px; height: 15px; margin-left: 2px;
  background: var(--brand); vertical-align: -2px; border-radius: 2px;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

.welcome { max-width: 820px; margin: 6vh auto 0; text-align: center; }
.welcome h2 { font-size: 24px; margin: 0 0 8px; font-weight: 650; }
.welcome p { color: var(--text-2); margin: 0 0 26px; font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.chip {
  border: 1px solid var(--line-strong); background: #fff; color: var(--text-2);
  border-radius: 999px; padding: 8px 15px; font-size: 13.5px; transition: .15s;
}
.chip:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }

.composer-wrap { flex: none; padding: 8px 20px 14px; background: #fff; }
.composer {
  max-width: 820px; margin: 0 auto; border: 1px solid var(--line-strong);
  border-radius: 16px; padding: 9px 10px 9px 14px; background: #fff;
  display: flex; align-items: flex-end; gap: 8px;
  box-shadow: 0 2px 12px rgba(20, 26, 40, .05);
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(77,107,254,.12); }
.composer textarea {
  flex: 1; min-width: 0; border: 0; outline: none; resize: none;
  font-family: inherit; font-size: 15px; line-height: 1.6; color: var(--text);
  max-height: 190px; padding: 8px 0; background: transparent;
}
.composer textarea::placeholder { color: var(--text-3); }

.icon-btn {
  flex: none; height: 34px; padding: 0 11px; border-radius: 9px;
  border: 1px solid var(--line-strong); background: #fff; color: var(--text-2); font-size: 13px;
}
.icon-btn:hover { border-color: var(--brand); color: var(--brand); }

.send-btn {
  flex: none; height: 34px; padding: 0 18px; border: 0; border-radius: 9px;
  background: var(--brand); color: #fff; font-size: 14px; font-weight: 600;
}
.send-btn:hover { background: var(--brand-dark); }
.send-btn.stop { background: var(--text-2); }
.send-btn:disabled { opacity: .5; cursor: default; }

.attachments {
  max-width: 820px; margin: 0 auto 8px; display: flex; flex-wrap: wrap; gap: 8px;
}
.att {
  position: relative; width: 62px; height: 62px; border-radius: 10px;
  overflow: hidden; border: 1px solid var(--line-strong); background: var(--bg-soft);
}
.att img { width: 100%; height: 100%; object-fit: cover; display: block; }
.att .rm {
  position: absolute; top: 2px; right: 2px; width: 18px; height: 18px;
  border: 0; border-radius: 50%; background: rgba(0, 0, 0, .55); color: #fff;
  font-size: 12px; line-height: 1; display: flex; align-items: center; justify-content: center;
  padding: 0;
}
.hint { text-align: center; color: var(--text-3); font-size: 11.5px; margin: 8px 0 0; }

/* ---------------- 表格附件 ---------------- */
.att-file {
  width: auto; min-width: 132px; max-width: 220px; height: 62px;
  padding: 8px 26px 8px 10px; position: relative;
  display: block; background: #fff;
}
.att-file-ic {
  width: 22px; height: 22px; border-radius: 6px; background: var(--brand-soft);
  color: var(--brand-dark); font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; margin-bottom: 3px;
}
.att-file-name {
  font-size: 12px; color: var(--text); font-weight: 550;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.att-file-meta { font-size: 11px; color: var(--text-3); }

.file-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.file-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 8px; padding: 3px 9px; font-size: 12px; color: var(--text-2);
  max-width: 100%;
}
.file-chip-ic {
  width: 16px; height: 16px; border-radius: 4px; background: var(--brand-soft);
  color: var(--brand-dark); font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex: none;
}
.file-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------- HTML 报告 ---------------- */
.report-host { padding: 0; }
.report-frame {
  width: 100%; border: 1px solid var(--line); border-radius: 12px;
  background: #fff; display: block;
}
.report-building {
  display: flex; align-items: center; gap: 7px;
  padding: 16px 18px; border: 1px dashed var(--line-strong); border-radius: 12px;
  color: var(--text-2); font-size: 13.5px; background: var(--bg-soft);
}
.report-building-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--brand);
  animation: rb 1.1s ease-in-out infinite;
}
.report-building-dot:nth-child(2) { animation-delay: .16s; }
.report-building-dot:nth-child(3) { animation-delay: .32s; }
@keyframes rb { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.report-overlay {
  position: fixed; inset: 0; z-index: 70; background: rgba(12, 15, 22, .9);
  display: flex; flex-direction: column; padding: 14px;
}
.report-overlay-bar {
  flex: none; display: flex; align-items: center; justify-content: space-between;
  color: #fff; font-size: 14px; padding: 2px 4px 10px;
}
.report-overlay-body { flex: 1; min-height: 0; }
.report-overlay-body .report-frame { height: 100% !important; border: 0; }

/* ---------------- 浮层 ---------------- */
.lightbox {
  position: fixed; inset: 0; background: rgba(12, 15, 22, .82);
  display: flex; align-items: center; justify-content: center; z-index: 60; padding: 30px;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

.toast {
  position: fixed; left: 50%; top: 26px; transform: translateX(-50%);
  background: #232833; color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 13.5px; z-index: 80; box-shadow: 0 8px 24px rgba(0, 0, 0, .22);
  max-width: 82vw; text-align: center;
}

.scrim { position: fixed; inset: 0; background: rgba(12, 15, 22, .4); z-index: 40; }
.scrim[hidden] { display: none; }

/* ---------------- 移动端 ---------------- */
@media (max-width: 820px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 50;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; }
  .msg.user .body { max-width: 88%; }
  .messages { padding: 18px 14px 8px; }
  .composer-wrap { padding: 8px 12px 12px; }
  .model-pick select { max-width: 130px; }
  .msg .thumbs img { width: 84px; height: 84px; }
}
