/* moved to templates/index.css */
/* 可选的自定义样式，Tailwind 已经提供大部分样式 */
/* 隐藏所有滚动条（仍可滚动） */
* { scrollbar-width: none; -ms-overflow-style: none; }
*::-webkit-scrollbar { width: 0 !important; height: 0 !important; background: transparent !important; }

/* 主题色与中性色变量 */
:root {
  /* brand */
  --theme: #10b981;
  --theme-500: #10b981;
  --theme-400: #34d399;
  --theme-600: #059669;

  /* neutral scale */
  --neutral-50: #f8fafc;
  --neutral-100: #f1f5f9;
  --neutral-200: #e2e8f0;
  --neutral-400: #94a3b8;
  --neutral-700: #334155;

  /* light theme tokens */
  --bg: #f1f5f9;                 /* page background */
  --surface: #ffffff;            /* cards, panels */
  --surface-modal: #ffffff;      /* modal surface (distinct from page) */
  --surface-elev: #ffffff;       /* elevated surfaces (toast/modal) */
  --surface-translucent: rgba(255,255,255,0.95);
  --text: #0f172a;               /* primary text */
  --muted: #475569;              /* secondary text */
  --border: #e2e8f0;             /* borders */
  --link: #0ea5e9;               /* links */

  --bubble-mine-bg: #f0fdf4;
  --bubble-other-bg: #f8fafc;
  --bubble-mine-border: rgba(16,185,129,0.25);
  --bubble-other-border: #e2e8f0;

  --code-bg: #f1f5f9;
  --code-fg: #0f172a;
  --pre-bg: #f1f5f9;
  --pre-fg: #0f172a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #0f172a;
    --surface-modal: #111827;    /* darker than surface for contrast */
    --surface-elev: #111827;
    --surface-translucent: rgba(15,23,42,0.9);
    --text: #e5e7eb;
    --muted: #94a3b8;
    --border: #243147;
    --link: #38bdf8;

    /* 更柔和的“我方气泡”配色，避免过饱和发绿 */
    /* 我方气泡：更中性的深色，减少绿色偏色 */
    --bubble-mine-bg: #1e293b;          /* slate-800 */
    --bubble-other-bg: #0f172a;         /* 深色表面 */
    --bubble-mine-border: #334155;      /* slate-700 */
    --bubble-other-border: #243147;

    --code-bg: #0b1220;
    --code-fg: #e5e7eb;
    --pre-bg: #0b1220;
    --pre-fg: #f1f5f9;
  }
}

/* 手动覆盖：当设置 data-theme="light"/"dark" 时，强制使用对应主题变量（优先级高于系统） */
:root[data-theme='light'] {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-modal: #ffffff;
  --surface-translucent: rgba(255,255,255,0.95);
  --text: #0f172a;
  --muted: #475569;
  --border: #e2e8f0;
  --link: #0ea5e9;
  --bubble-mine-bg: #f0fdf4;
  --bubble-other-bg: #f8fafc;
  --bubble-mine-border: rgba(16,185,129,0.25);
  --bubble-other-border: #e2e8f0;
  --code-bg: #f1f5f9;
  --code-fg: #0f172a;
  --pre-bg: #f1f5f9;
  --pre-fg: #0f172a;
}

:root[data-theme='dark'] {
  --bg: #0b1220;
  --surface: #0f172a;
  --surface-modal: #111827;
  --surface-translucent: rgba(15,23,42,0.9);
  --text: #e5e7eb;
  --muted: #94a3b8;
  --border: #243147;
  --link: #38bdf8;
  --bubble-mine-bg: #0f2a1f;
  --bubble-other-bg: #0f172a;
  --bubble-mine-border: rgba(16,185,129,0.35);
  --bubble-other-border: #243147;
  --code-bg: #0b1220;
  --code-fg: #e5e7eb;
  --pre-bg: #0b1220;
  --pre-fg: #f1f5f9;
}

/* Composer 控件高度（媒体查询分别设置） */
@media (max-width: 640px) {
  :root { --composer-h: 40px; }
}
@media (min-width: 641px) {
  :root { --composer-h: 44px; }
}

/* 背景装饰：低透明度渐变球 + 轻网格 */
.bg-decor {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    radial-gradient(600px 600px at 10% 15%, rgba(16,185,129,0.12), transparent 60%),
    radial-gradient(600px 600px at 85% 80%, rgba(139,92,246,0.10), transparent 60%),
    linear-gradient(transparent, transparent);
}
.bg-decor::before { /* dark-mode friendly overlay */
  content: ""; position: absolute; inset: 0;
}
.bg-decor::after { /* 极轻网格 */
  content: ""; position: absolute; inset: 0; background-image:
    linear-gradient(rgba(15,23,42,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15,23,42,0.03) 1px, transparent 1px);
  background-size: 40px 40px; opacity: .5; mix-blend-mode: normal;
}
@media (prefers-color-scheme: dark) { .bg-decor { background-image: none; } .bg-decor::after { background-image: none; } }
:root[data-theme='dark'] .bg-decor { background-image: none; }
:root[data-theme='dark'] .bg-decor::after { background-image: none; }

/* 卡片组件 */
.card {
  position: relative; border-radius: 4px; background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(15,23,42,0.06), 0 1px 2px rgba(15,23,42,0.04);
  transition: all .25s cubic-bezier(.4,0,.2,1);
  color: var(--text);
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 20px rgba(15,23,42,0.10), 0 6px 8px rgba(15,23,42,0.06);
  border-color: var(--border);
  background: linear-gradient(180deg, rgba(16,185,129,0.02), var(--surface));
}
.card-icon {
  width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 4px; background: rgba(16,185,129,0.12); color: var(--theme-600);
}
.font-semibold { font-weight: 500; }
.card-title { font-weight: 500; color: var(--text); }
.card-desc { font-size: 12px; color: var(--muted); }
.card-meta { font-size: 12px; color: var(--muted); }

/* 统一按钮样式与反馈 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  border-radius: 4px; padding: .5rem .875rem; font-weight: 500; transition: all .2s cubic-bezier(.4,0,.2,1);
  border: 1px solid var(--border); background: var(--surface); color: var(--theme-600);
}
.btn:hover { box-shadow: 0 6px 12px rgba(16,185,129,0.12); transform: translateY(-2px); border-color: rgba(16,185,129,0.4); }
.btn-primary { background: var(--theme-500); color: #fff; border-color: transparent; }
.btn-primary:hover { background: var(--theme-600); box-shadow: 0 6px 14px rgba(16,185,129,0.22); }
.pressable:active { transform: scale(.95); }
.btn:focus-visible, .link:focus-visible, input:focus-visible, textarea:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(16,185,129,0.35); }

/* 链接下划线动画 */
.link { color: var(--link); text-decoration: none; background-image: linear-gradient(currentColor,currentColor); background-repeat: no-repeat; background-size: 0 1px; background-position: 0 100%; transition: background-size .2s cubic-bezier(.4,0,.2,1), color .2s; }
.link:hover { background-size: 100% 1px; }

/* 入场动画 */
@keyframes fadeInDown { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.anim-fadeInDown { animation: fadeInDown .7s cubic-bezier(.4,0,.2,1) both; }
.anim-fadeInUp { animation: fadeInUp .7s cubic-bezier(.4,0,.2,1) both; }
.anim-fadeIn { animation: fadeIn .7s cubic-bezier(.4,0,.2,1) both; }
.anim-delay-05 { animation-delay: .05s; }
.anim-delay-1 { animation-delay: .1s; }
.anim-delay-2 { animation-delay: .2s; }
.anim-delay-3 { animation-delay: .3s; }
.anim-delay-4 { animation-delay: .4s; }

/* iOS 安全区域适配 */
.pb-safe {
  padding-bottom: env(safe-area-inset-bottom);
  padding-bottom: constant(safe-area-inset-bottom);
}

/* 移动端输入体验：避免 iOS 聚焦缩放 */
input, button {
  font-size: 16px;
}

/* 占位符：一行、隐藏溢出、省略号；使用媒体查询控制字号 */
#textInput::placeholder,
#textInput::-webkit-input-placeholder,
#textInput::-moz-placeholder,
#textInput:-ms-input-placeholder,
#textInput::-ms-input-placeholder {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (max-width: 640px) {
  #textInput::placeholder { font-size: 12px; }
}
@media (min-width: 641px) {
  #textInput::placeholder { font-size: 13px; }
}

/* 当没有输入内容时，输入框高度与发送按钮统一 */
#textInput:placeholder-shown {
  height: var(--composer-h);
  min-height: var(--composer-h);
  padding-top: 0; padding-bottom: 0;
  line-height: calc(var(--composer-h) - 2px);
  overflow-y: hidden;
}
#sendBtn { height: var(--composer-h); }

/* 滚动优化，避免页面级别回弹影响 */
html, body { overscroll-behavior: contain; max-width: 100vw; overflow-x: hidden; }
body { background: var(--bg) !important; color: var(--text); }

/* 表单控件（深浅主题自适应） */
.input { display: inline-block; width: 100%; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; height: 38px; line-height: 22px;
}
.input:disabled { opacity: .6; cursor: not-allowed; }
.input::placeholder { color: var(--muted); opacity: .9; }
select.input, .input.select { appearance: none; -webkit-appearance: none; -moz-appearance: none; padding-right: 34px; position: relative; }
select.input { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }

.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 6px; }
.form-help { font-size: 12px; color: var(--muted); }

.section-title { font-weight: 600; color: var(--text); border-bottom: 2px solid var(--theme-400); padding-bottom: 6px; margin-bottom: 12px; }
.settings-section { padding: 8px 0; }

/* Skeleton (dark-mode friendly) */
.skeleton-bar { background: var(--border); }
.skeleton-pill { background: var(--border); }
.skeleton-title { color: var(--muted); }

/* 聊天容器滚动优化 */
#messages {
  overscroll-behavior: contain;
}

/* 移动端：减少消息区两侧留白，并让气泡小角更贴近边缘 */
@media (max-width: 640px) {
  #messages { padding-left: 6px; padding-right: 6px; }
  #messages .bubble-wrap { padding-left: 2px; padding-right: 2px; }
  .bubble-tail-right::after { right: -6px; }
  .bubble-tail-left::after { left: -6px; }
}

/* 确保聊天页面占满屏幕 */
#app {
  height: 100vh;
  height: 100dvh;
}

/* 顶部与底部区域（主题适配） */
#mainHeader { background: var(--surface); border-color: var(--border); color: var(--text); }
#mainHeader.auto-hide { transition: transform .4s ease, height .35s ease, padding .35s ease, border .35s ease; overflow: hidden; }
#mainHeader.auto-hide.hidden { transform: translateY(-100%); height: 0 !important; padding-top: 0 !important; padding-bottom: 0 !important; border-bottom-width: 0 !important; }
#composer { background: var(--surface); border-color: var(--border); }

/* 输入区控件与附件按钮（深浅色适配） */
#textInput { background: var(--surface); color: var(--text); border-color: var(--border); caret-color: var(--text); }
#textInput::placeholder { color: var(--muted); }
#fileBtn { background: var(--surface); border-color: var(--border); color: var(--text); }
#fileBtn:hover { background: rgba(148,163,184,0.12); }
#fsEditBtn { background: var(--surface); border-color: var(--border); color: var(--text); }
#fsEditBtn:hover { background: rgba(148,163,184,0.12); }
#settingsBtn { background: var(--surface); border-color: var(--border); color: var(--text); }
#settingsBtn:hover { background: rgba(148,163,184,0.12); }
#themeToggleBtn { background: var(--surface); border-color: var(--border); color: var(--text); }
#themeToggleBtn:hover { background: rgba(148,163,184,0.12); }

/* 表单控件（设置页等） */
input[type="text"], input[type="password"], input[type="search"], input:not([type]), select, textarea {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
input::placeholder, textarea::placeholder { color: var(--muted); }

/* SweetAlert2 深浅色主题适配 */
.swal2-popup { background: var(--surface-modal) !important; color: var(--text) !important; border: 1px solid var(--border) !important; }
.swal2-title, .swal2-html-container { color: var(--text) !important; }
.swal2-actions .swal2-styled.swal2-confirm { background: var(--theme-500) !important; border: none !important; }
.swal2-actions .swal2-styled.swal2-cancel { background: var(--surface) !important; color: var(--text) !important; border: 1px solid var(--border) !important; }
.swal2-icon { box-shadow: none !important; }
.swal2-popup.swal2-toast { background: var(--surface) !important; color: var(--text) !important; border: 1px solid var(--border) !important; }

/* 聊天气泡（主题化） */
.bubble { position: relative; border-radius: 0.25rem; padding: 0.5rem 0.75rem; max-width: 100%; }
.bubble-mine { color: var(--text); background: var(--bubble-mine-bg); border: 1px solid var(--bubble-mine-border); }
.bubble-other { background: var(--bubble-other-bg); color: var(--text); border: 1px solid var(--bubble-other-border); }
.bubble-shadow { box-shadow: 0 2px 6px rgba(15, 23, 42, 0.12); }
.bubble-tail-right::after,
.bubble-tail-left::after { content: ""; position: absolute; width: 12px; height: 12px; background: inherit; transform: rotate(45deg); border-radius: 3px; }
.bubble-tail-right::after { right: -4px; bottom: 12px; }
.bubble-tail-left::after { left: -4px; bottom: 12px; }
.bubble a { text-decoration: underline; word-break: break-word; }
.bubble img, .bubble video { border-radius: 0.25rem; }

/* 移动端防溢出与自适应 */
.bubble, .md-body { word-break: break-word; overflow-wrap: anywhere; }
.md-body img, .md-body video { max-width: 100%; height: auto; }
.md-body pre { max-width: 100%; overflow-x: auto; }
.md-body table { display: block; max-width: 100%; overflow-x: auto; }

/* Markdown 渲染样式（简化版） */
.md-body { font-size: 0.95rem; line-height: 1.6; }
.md-body p { margin: 0.25rem 0; }
.md-body h1, .md-body h2, .md-body h3 { font-weight: 600; margin: 0.5rem 0 0.25rem; }
.md-body h1 { font-size: 1.25rem; }
.md-body h2 { font-size: 1.125rem; }
.md-body h3 { font-size: 1rem; }
.md-body ul, .md-body ol { margin: 0.25rem 0 0.25rem 1.25rem; }
.md-body li { margin: 0.125rem 0; }
.md-body blockquote { border-left: 3px solid #cbd5e1; padding-left: 0.75rem; color: #475569; margin: 0.25rem 0; }
.md-body code { background: var(--code-bg); color: var(--code-fg); padding: 0.1rem 0.25rem; border-radius: 0.25rem; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 0.85em; }
.md-body pre { background: var(--pre-bg); color: var(--pre-fg); padding: 0.75rem; border-radius: 0.25rem; overflow: auto; }
.md-body hr { border: 0; border-top: 1px solid #e5e7eb; margin: 0.5rem 0; }
.md-body table { width: 100%; border-collapse: collapse; margin: 0.5rem 0; }
.md-body th, .md-body td { border: 1px solid #e5e7eb; padding: 0.25rem 0.5rem; }
.md-body a { color: var(--link); }

/* 锚点消息高亮效果 */
@keyframes msgPulse {
  0% { box-shadow: 0 0 0 10px rgba(37,99,235,0.35), 0 6px 16px rgba(37,99,235,0.3); }
  50% { box-shadow: 0 0 0 4px rgba(37,99,235,0.2), 0 2px 10px rgba(37,99,235,0.2); }
  100% { box-shadow: 0 0 0 0 rgba(37,99,235,0), 0 2px 6px rgba(15,23,42,0.12); }
}
.msg-highlight .bubble {
  border-color: rgba(37,99,235,0.7) !important;
  animation: msgPulse 1.3s ease-out 2;
}

/* 气泡外层包装宽度（无需重建 Tailwind，可随时调整） */
.bubble-wrap { max-width: 92%; }
@media (min-width: 640px) {
  .bubble-wrap { max-width: 85%; }
}

/* 设置页面 Section 遵循主题色 */
section[id^="tab-"] { background: var(--surface); color: var(--text); border: 1px solid var(--border); }

#fs-editor { background: var(--surface); color: var(--text); }
#fs-editor header { background: var(--surface); border-color: var(--border); }
#fs-editor #fsInput { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
#fs-editor #fsPreview { background: var(--surface); color: var(--text); border: 1px solid var(--border); }

/* 取消自定义模态样式：改用 SweetAlert2 */

/* 全局统一文字颜色映射，保证不同页面一致；深浅色由变量控制 */
:root .text-slate-800, :root .text-slate-900 { color: var(--text) !important; }
:root .text-slate-700, :root .text-slate-600, :root .text-slate-500, :root .text-slate-400 { color: var(--muted) !important; }
