/* ── Reset ── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }

/* ── Variables ── */
:root {
  --text-primary: #1a1a1e;
  --text-secondary: rgba(0,0,0,.65);
  --text-muted: rgba(0,0,0,.35);
  --accent: #5b8fa8;
  --danger: #d1453b;
  --toast-bg: rgba(30,30,30,.85);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 13px;
  --radius-pill: 999px;
  --glass-fill: rgba(255,255,255,0.55);
  --glass-border-glow: rgba(80,150,210,0.25);
}

/* ── Body ── */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", "PingFang SC", sans-serif;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(180,210,240,0.35) 0%, transparent 55%),
    radial-gradient(ellipse at 80% 100%, rgba(220,200,180,0.25) 0%, transparent 50%),
    radial-gradient(ellipse at 45% 50%, rgba(200,215,225,0.15) 0%, transparent 55%),
    #f0eeeb;
  background-attachment: fixed;
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

/* ── Glass card (gradient border via background-clip) ── */
.glass {
  background-image:
    linear-gradient(135deg, rgba(80,150,210,0.25), rgba(200,170,140,0.12)),
    linear-gradient(var(--glass-fill), var(--glass-fill));
  background-origin: border-box;
  background-clip: padding-box, border-box;
  backdrop-filter: blur(14px) saturate(180%) contrast(105%);
  -webkit-backdrop-filter: blur(14px) saturate(180%) contrast(105%);
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  box-shadow: 0px 4px 24px rgba(0,0,0,0.04), 0px 8px 40px rgba(0,0,0,0.02);
  color: var(--text-primary);
  position: relative;
  transition: all .3s cubic-bezier(0.4,0,0.2,1);
}
.glass:hover {
  box-shadow: 0px 4px 28px rgba(0,0,0,0.06), 0px 12px 48px rgba(0,0,0,0.03);
}

/* ── Glass hover button ── */
.glass-hover {
  background: rgba(0,0,0,0.03);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all .25s ease;
  color: var(--text-secondary);
}
.glass-hover:hover {
  background: rgba(0,0,0,0.06);
  border-color: rgba(0,0,0,0.12);
  color: var(--text-primary);
  transform: translateY(-1px);
}

/* ── Layout ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 800px;
  margin: 0 auto;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 22px;
  flex-shrink: 0;
  z-index: 20;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}
.header-left h1 {
  font-size: 17px;
  font-weight: 700;
  white-space: nowrap;
  letter-spacing: -0.3px;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* ── Session selector ── */
.session-selector { position: relative; }
.session-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  font-size: 13px;
  border-radius: var(--radius-md);
}
.session-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.arrow { font-size: 11px; transition: transform .25s; }
.arrow.up { transform: rotate(180deg); }

.session-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 220px;
  max-width: 280px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 6px;
  z-index: 100;
  background-image:
    linear-gradient(135deg, rgba(80,150,210,0.2), rgba(200,170,140,0.1)),
    linear-gradient(rgba(255,255,255,0.8), rgba(255,255,255,0.8));
  background-origin: border-box;
  background-clip: padding-box, border-box;
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  box-shadow: 0px 8px 40px rgba(0,0,0,0.08);
}
.session-dropdown::-webkit-scrollbar { width: 4px; }
.session-dropdown::-webkit-scrollbar-thumb { background: rgba(0,0,0,.1); border-radius: 2px; }

.dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: background .12s;
  color: var(--text-secondary);
}
.dropdown-item:hover { background: rgba(0,0,0,0.04); color: var(--text-primary); }
.dropdown-item.active { background: rgba(91,143,168,0.08); color: var(--accent); font-weight: 600; }
.dropdown-item.new { color: var(--accent); font-weight: 600; }

.sess-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.sess-del {
  color: rgba(0,0,0,.25);
  padding: 0 6px;
  border-radius: 4px;
  font-size: 12px;
  flex-shrink: 0;
  margin-left: 6px;
  opacity: .5;
}
.dropdown-item:hover .sess-del { opacity: 1; }
.sess-del:hover { background: rgba(209,69,59,.1); color: var(--danger); }
@media (max-width: 768px) {
  .sess-del { opacity: .7; padding: 4px 8px; }
}

.divider { height: 1px; background: rgba(0,0,0,.06); margin: 4px 8px; }

.balance-btn { padding: 5px 10px; font-size: 13px; border-radius: var(--radius-md); }

/* ── Toolbar ── */
.toolbar {
  flex-shrink: 0;
  padding: 10px 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Switch (thinking toggle) */
.think-area {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.think-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  user-select: none;
}
.think-switch {
  display: inline-flex;
  height: 24px;
  width: 44px;
  cursor: pointer;
  align-items: center;
  border-radius: 999px;
  border: 2px solid transparent;
  transition: background .2s, box-shadow .2s;
  background: rgba(0,0,0,0.15);
  padding: 0;
  outline: none;
  flex-shrink: 0;
  position: relative;
}
.think-switch:hover {
  background: rgba(0,0,0,0.22);
}
.think-switch[data-state="checked"] {
  background: var(--accent);
}
.think-switch[data-state="checked"]:hover {
  background: #4d7f96;
}
.think-switch:focus-visible {
  box-shadow: 0 0 0 2px rgba(91,143,168,0.3);
}
.think-switch.shake {
  animation: shake .35s ease;
}
.think-switch.shake::after {
  content: '✕';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  color: rgba(209,69,59,0.5);
  pointer-events: none;
  animation: xFade .35s ease;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-3px); }
  40% { transform: translateX(3px); }
  60% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
}
@keyframes xFade {
  0% { opacity: 1; transform: scale(.5); }
  50% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1); }
}
.think-switch-knob {
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  transition: transform .2s cubic-bezier(0.4,0,0.2,1);
  pointer-events: none;
}
.think-switch-knob[data-state="unchecked"] {
  transform: translateX(0);
}
.think-switch-knob[data-state="checked"] {
  transform: translateX(20px);
}

.tool-style-btn {
  padding: 5px 10px;
  border-radius: var(--radius-md);
  font-size: 13px;
  cursor: pointer;
}

/* ── Messages ── */
.msg-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg-wrap::-webkit-scrollbar { width: 5px; }
.msg-wrap::-webkit-scrollbar-track { background: transparent; }
.msg-wrap::-webkit-scrollbar-thumb { background: rgba(0,0,0,.06); border-radius: 3px; }

.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  user-select: none;
  color: var(--text-muted);
}
.empty-icon { font-size: 48px; opacity: .4; }
.empty-text { font-size: 14px; }

.msg {
  max-width: 80%;
  padding: 10px 16px;
  border-radius: var(--radius-lg);
  line-height: 1.65;
  font-size: 14px;
  animation: fadeIn .25s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0);   }
}

.msg.user {
  align-self: flex-end;
  background: rgba(91,143,168,0.08);
  border: 1px solid rgba(91,143,168,0.12);
  border-bottom-right-radius: 5px;
}
.msg.user:hover {
  border-color: rgba(91,143,168,0.2);
}

.msg.assistant {
  align-self: flex-start;
  background: rgba(255,255,255,0.35);
  border: 1px solid rgba(0,0,0,0.04);
  border-bottom-left-radius: 5px;
  word-break: break-word;
  white-space: pre-wrap;
  backdrop-filter: blur(4px);
}
.msg.assistant:hover {
  border-color: rgba(0,0,0,0.08);
}
.msg.assistant.streaming::after {
  content: '▍';
  animation: blink .85s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.msg.error {
  align-self: center;
  background: rgba(209,69,59,.08);
  border: 1px solid rgba(209,69,59,.12);
  color: #c0392b;
  font-size: 13px;
  max-width: 92%;
}

/* ── Thinking section ── */
.think-section { border-bottom: 1px solid rgba(0,0,0,.04); }
.think-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 8px 16px 4px;
  border: 0;
  background: none;
  cursor: pointer;
  color: var(--accent);
  font-size: 13px;
  font-family: inherit;
  user-select: none;
}
.think-hd { font-weight: 600; }
.think-arrow { margin-left: auto; font-size: 12px; transition: transform .25s; }
.think-arrow.open { transform: rotate(180deg); }
.think-content {
  padding: 0 16px 10px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Input area ── */
.input-area {
  flex-shrink: 0;
  padding: 12px 24px 20px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  min-height: 70px;
}

.input-area textarea {
  flex: 1;
  min-height: 42px;
  max-height: 120px;
  background: rgba(255,255,255,0.35);
  border: 1px solid rgba(0,0,0,0.06);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: 0;
  line-height: 1.5;
  transition: border-color .2s;
}
.input-area textarea::placeholder { color: var(--text-muted); }
.input-area textarea:focus { border-color: rgba(91,143,168,0.3); }
.input-area textarea:disabled { opacity: .45; }

.input-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.btn-send {
  padding: 5px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  text-align: center;
  color: var(--accent);
}
.btn-send.disabled { opacity: .35; cursor: not-allowed; }

/* ── Balance / Style popup ── */
.balance-overlay {
  position: fixed; inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.08);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fadeIn .2s ease;
}
.balance-popup {
  width: 320px;
  overflow: hidden;
  animation: popIn .25s ease;
}
@keyframes popIn {
  from { opacity: 0; transform: scale(.92) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.bp-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px 0;
  font-weight: 600;
  font-size: 15px;
}
.bp-close {
  background: none; border: 0;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
}
.bp-close:hover { background: rgba(0,0,0,.04); color: var(--text-primary); }
.bp-body { padding: 14px 22px 18px; min-height: 60px; }
.bp-loading, .bp-error { text-align: center; padding: 20px 0; font-size: 14px; color: var(--text-muted); }
.bp-error { color: #c0392b; }
.bp-list { display: flex; flex-direction: column; gap: 6px; }
.bp-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid rgba(0,0,0,.04);
}
.bp-row:last-child { border-bottom: 0; }
.bp-row dt { font-size: 13px; color: var(--text-muted); }
.bp-row dd { font-size: 14px; font-weight: 600; }
.bp-row dd.num { font-family: 'Menlo', 'Consolas', monospace; color: var(--accent); }

.style-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: background .12s;
  color: var(--text-secondary);
}
.style-option:hover { background: rgba(0,0,0,.04); color: var(--text-primary); }
.style-option.active { background: rgba(91,143,168,0.08); color: var(--accent); font-weight: 600; }
.so-check { font-weight: 700; }

/* 风格编辑器 */
.style-option textarea:focus { border-color: rgba(91,143,168,0.3) !important; }
.style-option input:focus { color: var(--text-primary); }

/* ── Toast ── */
.toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--toast-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #fff;
  padding: 10px 22px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 200;
  white-space: nowrap;
  pointer-events: none;
}
.toast-fade-enter-active { animation: toastIn .3s ease; }
.toast-fade-leave-active { animation: toastOut .25s ease; }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0);    }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateX(-50%) translateY(0);    }
  to   { opacity: 0; transform: translateX(-50%) translateY(-8px); }
}

/* ── Mobile ── */
@media (max-width: 480px) {
  .header { padding: 10px 16px; }
  .header-left h1 { font-size: 15px; }
  .session-btn { max-width: 130px; font-size: 13px; }
  .toolbar { padding: 8px 16px 0; }
  .msg-wrap { padding: 12px 16px 6px; }
  .msg { max-width: 92%; font-size: 15px; }
  .input-area { padding: 8px 16px 16px; }
}
