/* nanocode 平台：登录页和主界面共用的样式。颜色都是 :root 上的变量，深色模式只换变量。 */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --sidebar: #fbfbfc;
  --line: #e4e7ec;
  --line-strong: #d0d5dd;
  --text: #101828;
  --text-2: #475467;
  --text-3: #8a94a6;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-text: #3730a3;
  --ok: #12b76a;
  --warn: #f79009;
  --danger: #d92d20;
  --danger-soft: #fef3f2;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, .08), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 20px 48px rgba(16, 24, 40, .18);
  --radius: 10px;
  --radius-sm: 7px;
  --font: "Inter", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0f14; --surface: #141820; --surface-2: #1a1f29; --sidebar: #11151c;
    --line: #242a35; --line-strong: #323a48; --text: #eef1f6; --text-2: #b4bccb; --text-3: #7c8698;
    --accent: #7c74ff; --accent-hover: #918aff; --accent-soft: #1f1d3d; --accent-text: #c4c0ff;
    --danger-soft: #2b1614; --shadow-lg: 0 20px 48px rgba(0, 0, 0, .5); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c0f14; --surface: #141820; --surface-2: #1a1f29; --sidebar: #11151c;
  --line: #242a35; --line-strong: #323a48; --text: #eef1f6; --text-2: #b4bccb; --text-3: #7c8698;
  --accent: #7c74ff; --accent-hover: #918aff; --accent-soft: #1f1d3d; --accent-text: #c4c0ff;
  --danger-soft: #2b1614; --shadow-lg: 0 20px 48px rgba(0, 0, 0, .5); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.muted { color: var(--text-3); }
.mono { font-family: var(--mono); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------------------------------------------------------------- 基础控件 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text); font-weight: 500; cursor: pointer; white-space: nowrap;
  box-shadow: var(--shadow-sm); transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.block { width: 100%; }
.btn.lg { height: 42px; font-size: 15px; }
.icon-btn { width: 34px; padding: 0; }
.btn svg, .icon { width: 16px; height: 16px; flex: none; }
:is(.btn, input, select, textarea, .session, .chip):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 500; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--text-3); }
.input, select.input, textarea.input {
  width: 100%; height: 38px; padding: 0 12px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
  background: var(--surface); box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; min-height: 64px; padding: 9px 12px; resize: vertical; }
select.input { appearance: none; padding-right: 34px; cursor: pointer;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a94a6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center / 16px; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 99px;
  font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--line);
  white-space: nowrap;
}
.badge.accent { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); flex: none; }
.dot.running { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 18%, transparent); }
.dot.starting { background: var(--warn); }
.dot.failed { background: var(--danger); }

.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-weight: 600; font-size: 13px; color: #fff; background: var(--accent);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; letter-spacing: -.01em; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #6366f1, #8b5cf6 55%, #ec4899); font: 700 15px var(--mono);
  box-shadow: 0 4px 10px rgba(99, 102, 241, .35);
}

/* ---------------------------------------------------------------- 登录页 */
.login-page { min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--accent) 14%, transparent), transparent),
              radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, #ec4899 10%, transparent), transparent), var(--bg); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 32px 28px 26px; box-shadow: var(--shadow-lg); }
.login-card h1 { margin: 22px 0 4px; font-size: 22px; letter-spacing: -.02em; }
.login-card .sub { margin: 0 0 22px; color: var(--text-2); }
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin: -4px 0 18px; }
.chip { display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 12px 0 4px; border-radius: 99px;
  border: 1px solid var(--line-strong); background: var(--surface); cursor: pointer; font-size: 13px; }
.chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.chip .avatar { width: 22px; height: 22px; font-size: 11px; }
.note { margin-top: 18px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2);
  border: 1px solid var(--line); color: var(--text-2); font-size: 12.5px; }
.form-error { color: var(--danger); font-size: 13px; min-height: 18px; margin: -6px 0 10px; }

/* ---------------------------------------------------------------- 主界面布局 */
.app { display: grid; grid-template-columns: 280px minmax(0, 1fr); height: 100%; }
.sidebar { display: flex; flex-direction: column; min-height: 0; background: var(--sidebar); border-right: 1px solid var(--line); }
.sidebar-head { padding: 16px 16px 12px; display: flex; flex-direction: column; gap: 14px; }
.sessions { flex: 1; overflow-y: auto; padding: 4px 10px 10px; }
.sessions-title { padding: 10px 8px 6px; font-size: 11.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.session { display: flex; gap: 10px; align-items: flex-start; width: 100%; text-align: left; padding: 9px 10px; margin-bottom: 2px;
  border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent; cursor: pointer; }
.session:hover { background: var(--surface-2); }
.session.active { background: var(--surface); border-color: var(--line); box-shadow: var(--shadow-sm); }
.session .dot { margin-top: 7px; }
.session-body { min-width: 0; flex: 1; }
.session-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-meta { font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sessions-empty { padding: 20px 10px; text-align: center; color: var(--text-3); font-size: 13px; }

.sidebar-foot { border-top: 1px solid var(--line); padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 12px; }
.usage-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.meter { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), #8b5cf6); transition: width .3s; }
.meter.hot > i { background: linear-gradient(90deg, var(--warn), var(--danger)); }
.user-row { display: flex; align-items: center; gap: 10px; }
.user-row .who { min-width: 0; flex: 1; }
.user-row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-row .role { font-size: 12px; color: var(--text-3); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { height: 56px; flex: none; display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar .title { font-weight: 600; font-size: 15px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border: 1px solid transparent; border-radius: 6px; padding: 3px 6px; cursor: text; }
.topbar .title:hover { border-color: var(--line); }
.topbar .spacer { flex: 1; }
.model-picker { position: relative; display: flex; align-items: center; }
.model-picker select { appearance: none; height: 34px; padding: 0 32px 0 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface); font-weight: 500; max-width: 260px; cursor: pointer; box-shadow: var(--shadow-sm); }
.model-picker svg { position: absolute; right: 10px; pointer-events: none; color: var(--text-3); }
.workspace { flex: 1; min-height: 0; position: relative; background: var(--bg); }
.workspace iframe { width: 100%; height: 100%; border: 0; display: block; background: var(--bg); }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(2px); z-index: 2; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line-strong); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.overlay-box { display: flex; flex-direction: column; align-items: center; gap: 12px; color: var(--text-2); }
@keyframes spin { to { transform: rotate(360deg); } }

/* 空状态 / 欢迎页 */
.welcome { height: 100%; overflow-y: auto; display: grid; place-items: center; padding: 32px 16px; }
.welcome-card { width: 100%; max-width: 560px; }
.welcome h2 { font-size: 26px; letter-spacing: -.02em; margin: 0 0 6px; }
.welcome .lead { color: var(--text-2); margin: 0 0 24px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 20px; box-shadow: var(--shadow-sm); }
.facts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.tips { margin: 18px 0 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.tips li { display: flex; gap: 10px; color: var(--text-2); font-size: 13.5px; }
.tips .num { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 600; background: var(--accent-soft); color: var(--accent-text); }

/* ---------------------------------------------------------------- 弹窗 */
dialog { border: none; padding: 0; border-radius: 16px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
  width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
dialog.narrow { width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 12, 18, .45); backdrop-filter: blur(3px); }
.dialog-head { display: flex; align-items: center; gap: 10px; padding: 18px 20px 14px; border-bottom: 1px solid var(--line); }
.dialog-head h3 { margin: 0; font-size: 16px; flex: 1; }
.dialog-body { padding: 18px 20px; overflow-y: auto; max-height: calc(100vh - 190px); }
.dialog-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px 18px; border-top: 1px solid var(--line); }
.section-title { font-size: 13px; font-weight: 600; margin: 0 0 10px; color: var(--text-2); }
.cred { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; background: var(--surface-2); }
.cred-body { flex: 1; min-width: 0; }
.cred-name { font-weight: 600; }
.cred-meta { font-size: 12px; color: var(--text-3); margin: 2px 0 6px; overflow-wrap: anywhere; }
.cred-models { display: flex; flex-wrap: wrap; gap: 6px; }
.empty-box { padding: 18px; text-align: center; color: var(--text-3); border: 1px dashed var(--line-strong); border-radius: var(--radius); margin-bottom: 8px; font-size: 13px; }
.divider { height: 1px; background: var(--line); margin: 18px 0; }
.test-result { font-size: 13px; margin-top: -4px; min-height: 20px; }
.test-result.ok { color: var(--ok); }
.test-result.err { color: var(--danger); overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- 提示 */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: min(380px, calc(100vw - 32px)); }
.toast { padding: 11px 14px; border-radius: var(--radius); background: var(--text); color: var(--surface); box-shadow: var(--shadow-md);
  font-size: 13.5px; animation: toast-in .2s ease-out; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------------------------------------------------------------- 窄屏：侧栏变成抽屉 */
.menu-btn { display: none; }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 30; transform: translateX(-100%);
    transition: transform .2s ease; }
  .app.drawer-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .app.drawer-open::after { content: ""; position: fixed; inset: 0; background: rgba(10, 12, 18, .4); z-index: 20; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 0 10px; gap: 8px; }
  .model-picker select { max-width: 150px; }
  .hide-narrow { display: none !important; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
