/* ------------------------------------------------------------------ 主题 */
:root {
  /* 必须声明：不声明的话浏览器会把 button / input / textarea 强制按浅色渲染，
     连它们内部的 prefers-color-scheme 也跟着算成 light，
     结果就是深色页面上冒出一颗白色按钮。 */
  color-scheme: light dark;

  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --border-strong: #c8cdd4;
  --text: #1c2024;
  --text-dim: #616a75;
  --text-faint: #8b939d;
  --accent: #1f6feb;
  --accent-hover: #1a5fd0;
  --accent-soft: #e8f0fe;
  --danger: #c0362c;
  --danger-soft: #fdeceb;
  --ok: #1a7f4b;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 14px rgba(16, 24, 40, .06);
  --radius: 10px;
  --mono: "Cascadia Mono", "JetBrains Mono", Consolas, "SF Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei",
          "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --surface: #1e2127;
    --surface-2: #262a32;
    --border: #333841;
    --border-strong: #454b56;
    --text: #e6e8eb;
    --text-dim: #a2aab5;
    --text-faint: #7b838e;
    --accent: #4c8dff;
    --accent-hover: #6ba0ff;
    --accent-soft: #1d2a44;
    --danger: #ff7b6e;
    --danger-soft: #3a2220;
    --ok: #4ecf8b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------------------------------------- 顶栏与选项卡 */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark, .login-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  flex: 0 0 auto;
}

.brand-name {
  font-weight: 650;
  letter-spacing: .2px;
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px;
}

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-weight: 550;
  padding: 6px 18px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s;
}

.tab:hover { color: var(--text); }

.tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(16, 24, 40, .1);
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-chip {
  color: var(--text-dim);
  font-size: 13px;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inline-form { margin: 0; display: inline; }

/* ------------------------------------------------------------------ 面板 */
.panel {
  display: none;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
  padding: 0 20px;
}

.panel.is-active { display: flex; }

.empty-state {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--text-dim);
}

/* ------------------------------------------------------------------ 对话区 */
.thread {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 0 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
}

.intro {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 16px 18px;
  color: var(--text-dim);
  background: var(--surface);
}

.intro h2 {
  margin: 0 0 6px;
  font-size: 15px;
  color: var(--text);
}

.intro p { margin: 0; }

.example {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  overflow: hidden;
}

.example-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 10px 5px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-faint);
}

.example pre {
  margin: 0;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-dim);
  white-space: pre;
  overflow-x: auto;
}

.intro-meta {
  margin-top: 12px !important;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.intro-meta strong { color: var(--text); }

/* 消息气泡 */
.msg {
  display: flex;
  flex-direction: column;
  max-width: 92%;
}

.msg-user { align-self: flex-end; align-items: flex-end; }
.msg-bot  { align-self: flex-start; align-items: flex-start; }

.msg-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 4px;
  padding: 0 2px;
}

.msg-body {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
  max-width: 100%;
}

.msg-user .msg-body {
  background: var(--accent-soft);
  border-color: transparent;
}

.msg-error .msg-body {
  background: var(--danger-soft);
  border-color: var(--danger);
}

.msg pre {
  margin: 0;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre;
  tab-size: 8;
  overflow-x: auto;
  color: var(--text);
}

.msg-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 12px;
  color: var(--text-faint);
}

.msg-pending .msg-body {
  color: var(--text-dim);
}

.dots::after {
  content: "";
  animation: dots 1.2s steps(4, end) infinite;
}

@keyframes dots {
  0%   { content: ""; }
  25%  { content: "."; }
  50%  { content: ".."; }
  75%  { content: "..."; }
}

/* ------------------------------------------------------------------ 输入区 */
.composer {
  flex: 0 0 auto;
  margin: 8px 0 20px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.composer textarea {
  display: block;
  width: 100%;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  padding: 12px 14px;
  min-height: 92px;
  max-height: 45vh;
  overflow-y: auto;
  tab-size: 8;
}

.composer textarea::placeholder {
  color: var(--text-faint);
  font-family: var(--sans);
}

.composer-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px 8px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

.composer-hint {
  font-size: 12px;
  color: var(--text-faint);
}

.composer-status {
  font-size: 12px;
  color: var(--text-dim);
  margin-left: auto;
  text-align: right;
}

.composer-bar .btn-primary { margin-left: 0; }
.composer-status:empty + .btn-primary { margin-left: auto; }

/* ------------------------------------------------------------------ 按钮 */
.btn {
  appearance: none;
  font: inherit;
  font-weight: 550;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 7px 16px;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, opacity .15s;
  white-space: nowrap;
}

.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-dim);
}
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--text-faint); }

.btn-link {
  background: transparent;
  border: 0;
  color: var(--accent);
  padding: 0 2px;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.btn-sm { padding: 3px 10px; font-size: 12px; }
.btn-block { width: 100%; padding: 10px; }

/* ------------------------------------------------------------------ 登录页 */
.login-body {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
}

.login-brand {
  text-align: center;
  margin-bottom: 24px;
}

.login-mark {
  width: 44px;
  height: 44px;
  font-size: 22px;
  border-radius: 12px;
  margin: 0 auto 12px;
}

.login-brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
}

.login-sub {
  margin: 4px 0 0;
  color: var(--text-faint);
  font-size: 13px;
}

.login-form { display: grid; gap: 14px; }

.field { display: block; }

.field-label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 5px;
}

.field input {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 9px 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.alert {
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  margin-bottom: 16px;
}

/* -------------------------------------------------------- 管理页（用户/文件） */
.admin-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 0 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scrollbar-width: thin;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.card-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
}

.card-head-actions { display: flex; gap: 6px; align-items: center; }

.filter-input {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 4px 10px;
  width: 170px;
  outline: none;
}

.filter-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  vertical-align: 1px;
}

.muted { color: var(--text-faint); }

.req { color: var(--danger); margin-left: 2px; }

/* 新增账号表单 */
.grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px 16px;
  padding: 16px;
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.form-status {
  font-size: 13px;
  color: var(--text-dim);
  margin: 0;
  min-height: 1.2em;
}
.form-status.is-error { color: var(--danger); }
.form-status.is-ok { color: var(--ok); }

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  padding-top: 6px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.check input { margin: 0; accent-color: var(--accent); cursor: pointer; }
.check-sm { font-size: 12.5px; margin-right: 10px; }

/* 表格 */
.table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th,
.data-table td {
  padding: 9px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  white-space: nowrap;
}

.data-table th {
  font-weight: 600;
  color: var(--text-dim);
  background: var(--surface);
  position: sticky;
  top: 0;
}

.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: var(--surface-2); }

.data-table code {
  font-family: var(--mono);
  font-size: 12.5px;
}

.col-num { text-align: right; }
.col-actions { text-align: right; }
.col-actions .btn { margin-left: 10px; }

.btn-danger { color: var(--danger); }

/* ------------------------------------------------------------ 文件浏览器 */
.crumbs {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  min-width: 0;
  font-size: 13px;
}

.crumb {
  appearance: none;
  border: 0;
  background: transparent;
  font: inherit;
  color: var(--accent);
  padding: 2px 4px;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
}

.crumb:hover { background: var(--accent-soft); }

.crumb-current {
  color: var(--text);
  font-weight: 600;
  cursor: default;
}

.crumb-current:hover { background: transparent; }

.crumb-sep { color: var(--text-faint); }

/* 可点击进入的行（文件夹 / 返回上一层） */
.row-link { cursor: pointer; }
.row-link:hover { background: var(--accent-soft); }
.row-link .folder-name { font-weight: 550; }
.row-up td { color: var(--text-dim); }

.icon {
  display: inline-block;
  width: 1.5em;
  margin-right: 2px;
  text-align: center;
  font-size: 13px;
}

.readonly-note {
  margin: 14px 16px 0;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 12.5px;
}

.upload-line { padding: 10px 16px 0; }
.upload-line:empty { padding: 0; }

/* 上传区 */
.dropzone {
  margin: 16px;
  padding: 22px 16px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.dropzone:hover,
.dropzone:focus-visible { border-color: var(--accent); }

.dropzone.is-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone.is-busy { opacity: .6; pointer-events: none; }

.dropzone-main { margin: 0 0 6px; font-weight: 550; }
.dropzone-sub { margin: 0; font-size: 12.5px; color: var(--text-faint); }

.result-box {
  margin: 0 16px 16px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-dim);
}

/* ------------------------------------------------------------------ 弹窗 */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(16, 20, 26, .55);
  backdrop-filter: blur(2px);
}

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

.modal {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
  padding: 22px 24px;
}

.modal h3 {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 650;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* ------------------------------------------------------------------ 窄屏 */
@media (max-width: 720px) {
  .topbar {
    height: auto;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 14px;
  }
  .tabs { order: 3; width: 100%; }
  .tab { flex: 1; text-align: center; padding: 7px 10px; }
  .topbar-right { gap: 8px; }
  .panel { padding: 0 14px; }
  .msg { max-width: 100%; }
  .grid-form { grid-template-columns: 1fr; }
  .data-table th, .data-table td { padding: 8px 12px; }
  .dropzone { margin: 12px; }
  .card-head { flex-wrap: wrap; }
  .card-head-actions { width: 100%; flex-wrap: wrap; }
  /* 筛选框独占一行，剩下的按钮排在下面，免得都挤成一条 */
  .filter-input { flex: 1 1 100%; width: auto; }
}
