/* MCP-Image 管理界面。
   中性灰 + 一个主色；颜色、圆角、间距、动效时长都写成变量；深色模式跟随系统。 */

:root {
  color-scheme: light dark;
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --text: #18181b;
  --text-2: #52525b;
  --text-3: #8b8b94;
  --accent: #2f5fdd;
  --accent-hover: #264fbf;
  --accent-soft: #e9effd;
  --on-accent: #ffffff;
  --ok: #17803d;
  --ok-soft: #e6f4ea;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --danger: #c0271f;
  --danger-hover: #a21f18;
  --danger-soft: #fdebea;
  --info: #2f5fdd;
  --info-soft: #e9effd;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.06);
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --fast: 120ms;
  --slow: 220ms;
  --sidebar: 216px;
  --rail: 56px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0d10;
    --surface: #16161a;
    --surface-2: #1e1e23;
    --border: #2a2a31;
    --border-strong: #3a3a43;
    --text: #ededef;
    --text-2: #a9a9b3;
    --text-3: #7c7c87;
    --accent: #7c9cf5;
    --accent-hover: #93adf7;
    --accent-soft: #1c2748;
    --on-accent: #0d0d10;
    --ok: #5fc27e;
    --ok-soft: #132a1c;
    --warn: #e2a84a;
    --warn-soft: #30230d;
    --danger: #f0776f;
    --danger-hover: #f48e87;
    --danger-soft: #331715;
    --info: #7c9cf5;
    --info-soft: #1c2748;
    --shadow: 0 0 0 1px var(--border-strong);
  }
}

/* —— reset —— */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
[hidden] { display: none !important; }

/* —— 布局 —— */
.boot { min-height: 100dvh; }
.shell {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  height: 100dvh;
}
.sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  padding: var(--s-4) var(--s-2);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-1) var(--s-3) var(--s-4); font-weight: 600; white-space: nowrap; }
.brand-mark { width: 24px; height: 24px; border-radius: var(--r-sm); background: var(--accent); color: var(--on-accent); display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.nav-item {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 8px var(--s-3);
  border: 0; border-radius: var(--r-md);
  background: none; color: var(--text-2); text-align: left; white-space: nowrap;
  transition: background var(--fast), color var(--fast);
}
.nav-item svg { width: 18px; height: 18px; flex: none; }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.nav-item:active { transform: scale(0.98); }
.sidebar-foot { margin-top: auto; padding: var(--s-3); color: var(--text-3); font-size: 12px; white-space: nowrap; }
.main { display: flex; flex-direction: column; min-width: 0; height: 100dvh; }
.topbar {
  display: flex; align-items: center; gap: var(--s-3);
  min-height: 52px; padding: 0 var(--s-5);
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 16px; font-weight: 600; }
.topbar .spacer { flex: 1; }
.who { color: var(--text-2); max-width: 30ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn.menu-btn { display: none; }
.content { flex: 1; overflow-y: auto; padding: var(--s-5); padding-bottom: calc(var(--s-6) + env(safe-area-inset-bottom)); }
.stack { display: flex; flex-direction: column; gap: var(--s-5); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); }
.grow { flex: 1; min-width: 0; }
.backdrop { display: none; }

/* —— 卡片与指标 —— */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); }
.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); padding: var(--s-4) var(--s-4) 0; }
.card-head h2 { font-size: 14px; font-weight: 600; }
.card-body { padding: var(--s-4); }
.hint { color: var(--text-3); font-size: 12px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--s-3); }
.tile { padding: var(--s-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); min-width: 0; }
.tile .label { color: var(--text-2); font-size: 12px; }
.tile .value { margin-top: var(--s-1); font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.tile .sub { color: var(--text-3); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meter { height: 4px; margin-top: var(--s-2); background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.meter > span { display: block; height: 100%; width: 0; background: var(--accent); transition: width var(--slow); }
.meter.hot > span { background: var(--warn); }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--s-2) var(--s-4); }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* —— 徽标与提示条 —— */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--surface-2); color: var(--text-2); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.notice { display: flex; gap: var(--s-3); padding: var(--s-3) var(--s-4); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); }
.notice.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.notice.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.notice.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.notice ul { margin: var(--s-1) 0 0; padding-left: 1.2em; }
.notice strong { font-weight: 600; }
.notice > .btn { align-self: center; flex: none; }

/* —— 按钮 —— */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 32px; padding: 0 var(--s-3);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--text); font-weight: 500; white-space: nowrap;
  transition: background var(--fast), border-color var(--fast), transform var(--fast), opacity var(--fast);
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: none; color: var(--text-2); }
.btn.small { min-height: 26px; padding: 0 var(--s-2); font-size: 12px; }
.btn.icon { width: 32px; padding: 0; }
.btn.busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.busy::after {
  content: ""; position: absolute; width: 14px; height: 14px;
  border: 2px solid var(--text-3); border-top-color: transparent; border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.btn.primary.busy::after, .btn.danger.busy::after { border-color: #fff; border-top-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (hover: hover) {
  .nav-item:hover { background: var(--surface-2); color: var(--text); }
  .nav-item[aria-current="page"]:hover { background: var(--accent-soft); color: var(--accent); }
  .btn:hover:not(:disabled) { background: var(--surface-2); }
  .btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
  .btn.danger:hover:not(:disabled) { background: var(--danger-hover); border-color: var(--danger-hover); }
  tbody tr:hover { background: var(--surface-2); }
}

/* —— 表单 —— */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--s-4); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label { font-weight: 500; }
.field .help { color: var(--text-3); font-size: 12px; }
.field .error { color: var(--danger); font-size: 12px; }
.input, .select {
  width: 100%; min-height: 34px; padding: 0 10px;
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--text);
  transition: border-color var(--fast), box-shadow var(--fast);
}
.input::placeholder { color: var(--text-3); }
.input:focus-visible, .select:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.invalid, .select.invalid { border-color: var(--danger); }
.input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
.input[type="number"]::-webkit-outer-spin-button, .input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }
.input:-webkit-autofill { -webkit-text-fill-color: var(--text); box-shadow: 0 0 0 100px var(--surface) inset; }
.select {
  appearance: none; -webkit-appearance: none; padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%238b8b94' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
.with-unit { display: flex; align-items: center; gap: var(--s-2); }
.with-unit .unit { color: var(--text-3); white-space: nowrap; }
.switch { position: relative; width: 36px; height: 20px; flex: none; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 10px; background: var(--border-strong); transition: background var(--fast); pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform var(--fast); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.toolbar .input { width: min(320px, 100%); }
.toolbar .select { width: auto; }
.segmented { display: inline-flex; padding: 2px; border-radius: var(--r-md); background: var(--surface-2); }
.segmented button { min-height: 28px; padding: 0 var(--s-3); border: 0; border-radius: var(--r-sm); background: none; color: var(--text-2); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 500; box-shadow: 0 0 0 1px var(--border); }

/* —— 表格：窄了就变成卡片 —— */
.table-wrap { container-type: inline-size; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px var(--s-3); text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-2); font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--surface); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background var(--fast); }
td.num, th.num { text-align: right; }
td .clip { display: block; max-width: 44ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td .two { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; white-space: normal; min-width: 24ch; max-width: 60ch; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.id { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; }
.id code { font-family: var(--mono); font-size: 12.5px; white-space: nowrap; }
.copy { width: 22px; height: 22px; padding: 0; border: 0; border-radius: var(--r-sm); background: none; color: var(--text-3); display: inline-grid; place-items: center; flex: none; }
.copy svg { width: 13px; height: 13px; }
.copy.done { color: var(--ok); }
.empty { padding: var(--s-6) var(--s-4); text-align: center; color: var(--text-3); }
.more { display: flex; justify-content: center; padding: var(--s-3); }
.stale { opacity: 0.55; transition: opacity var(--fast); }
@container (max-width: 720px) {
  table, tbody, tr, td { display: block; }
  thead { display: none; }
  tr { padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--border); }
  tbody tr:last-child { border-bottom: 0; }
  td { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-3); padding: 3px 0; border: 0; min-width: 0; white-space: normal; }
  td .two { min-width: 0; text-align: right; }
  td::before { content: attr(data-label); color: var(--text-3); font-size: 12px; flex: none; }
  td.num { text-align: left; }
  td > * { min-width: 0; }
  td.lead { font-weight: 600; }
  td.lead::before { content: none; }
  td:empty { display: none; }
}

/* —— 骨架屏 —— */
.skeleton { border-radius: var(--r-md); background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
.skeleton.line { height: 14px; margin: 10px 0; }
.skeleton.block { height: 84px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* —— 对话框 —— */
dialog { padding: 0; border: 0; border-radius: var(--r-lg); background: var(--surface); color: var(--text); box-shadow: var(--shadow); width: min(480px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); }
dialog::backdrop { background: rgba(0, 0, 0, 0.42); }
dialog[open] { animation: pop var(--slow) ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
.dialog-head { padding: var(--s-4) var(--s-5) 0; font-size: 15px; font-weight: 600; }
.dialog-body { padding: var(--s-3) var(--s-5) 0; color: var(--text-2); display: flex; flex-direction: column; gap: var(--s-3); overflow-y: auto; }
.dialog-foot { display: flex; justify-content: flex-end; gap: var(--s-2); padding: var(--s-4) var(--s-5) var(--s-5); }
.secret { display: flex; gap: var(--s-2); align-items: center; padding: var(--s-2) var(--s-3); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2); }
.secret code { flex: 1; min-width: 0; font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; color: var(--text); }
.steps { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.steps li { display: flex; gap: var(--s-2); align-items: baseline; }
.steps .mark { flex: none; width: 1.2em; font-weight: 700; }
.steps .mark.ok { color: var(--ok); }
.steps .mark.bad { color: var(--danger); }
.steps .detail { color: var(--text-3); font-size: 12px; overflow-wrap: anywhere; }

/* —— Toast —— */
.toasts { position: fixed; z-index: 50; right: var(--s-4); bottom: calc(var(--s-4) + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: var(--s-2); align-items: flex-end; pointer-events: none; }
.toast { pointer-events: auto; max-width: min(420px, calc(100vw - 32px)); padding: 10px var(--s-4); border-radius: var(--r-md); background: var(--text); color: var(--bg); box-shadow: var(--shadow); animation: rise var(--slow) ease-out; }
.toast.error { background: var(--danger); color: #fff; }
.toast.leaving { opacity: 0; transition: opacity var(--fast); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* —— 登录页 —— */
.login { min-height: 100dvh; display: grid; place-items: center; padding: var(--s-5); }
.login-card { width: min(380px, 100%); padding: var(--s-6); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); display: flex; flex-direction: column; gap: var(--s-4); }
.login-card h1 { font-size: 18px; font-weight: 600; }
.code-input { height: 48px; font-size: 24px; letter-spacing: 0.4em; text-align: center; font-family: var(--mono); }
.login-card .btn { min-height: 40px; }
.login-msg { min-height: 1.5em; font-size: 13px; color: var(--danger); }

/* —— 响应式：平板收成图标栏，手机进抽屉 —— */
@media (max-width: 1023px) {
  .shell { grid-template-columns: var(--rail) minmax(0, 1fr); }
  .nav-item span, .brand span, .sidebar-foot { display: none; }
  .nav-item { justify-content: center; padding: 10px 0; }
  .brand { justify-content: center; padding-left: 0; padding-right: 0; }
}
@media (max-width: 639px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; z-index: 40; inset: 0 auto 0 0; width: min(260px, 82vw); transform: translateX(-100%); transition: transform var(--slow); padding-top: calc(var(--s-4) + env(safe-area-inset-top)); }
  .shell.drawer .sidebar { transform: none; box-shadow: var(--shadow); }
  .shell.drawer .backdrop { display: block; position: fixed; z-index: 30; inset: 0; background: rgba(0, 0, 0, 0.42); border: 0; }
  .nav-item span, .brand span { display: inline; }
  .sidebar-foot { display: block; }
  .nav-item { justify-content: flex-start; padding: 10px var(--s-3); min-height: 44px; }
  .brand { justify-content: flex-start; padding: var(--s-1) var(--s-3) var(--s-4); }
  .btn.menu-btn { display: inline-flex; }
  .topbar { padding: 0 var(--s-3); min-height: 48px; padding-top: env(safe-area-inset-top); }
  .content { padding: var(--s-3); padding-bottom: calc(var(--s-6) + env(safe-area-inset-bottom)); }
  .stack { gap: var(--s-3); }
  .who { display: none; }
  .input, .select { font-size: 16px; min-height: 40px; }
  .btn { min-height: 38px; }
  .btn.small { min-height: 32px; }
  .toolbar .input { width: 100%; }
  dialog { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: var(--r-lg) var(--r-lg) 0 0; padding-bottom: env(safe-area-inset-bottom); }
  dialog[open] { animation: sheet var(--slow) ease-out; }
  .dialog-foot .btn { flex: 1; }
  .toasts { left: var(--s-3); right: var(--s-3); align-items: stretch; }
}
@keyframes sheet { from { transform: translateY(100%); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
  .btn:active:not(:disabled), .nav-item:active { transform: none; }
}
