/* Zlash UI — design tokens + components. Light & dark. */
:root {
  --bg: #f6f6f7;
  --surface: #ffffff;
  --surface-2: #f9f9fa;
  --hover: #f3f3f5;
  --border: #e6e6e9;
  --border-strong: #d6d6db;
  --text: #17171c;
  --text-2: #4a4a55;
  --muted: #74747f;
  --faint: #a3a3ad;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef0ff;
  --primary-text: #4338ca;
  --success: #15803d;
  --success-dot: #22c55e;
  --success-soft: #ecfdf3;
  --warning: #b45309;
  --warning-dot: #f59e0b;
  --warning-soft: #fffaeb;
  --danger: #dc2626;
  --danger-soft: #fef3f2;
  --radius: 12px;
  --radius-md: 8px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-lg: 0 24px 48px -12px rgba(16, 24, 40, 0.18);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar: 232px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0f13;
    --surface: #16171d;
    --surface-2: #1b1c23;
    --hover: #20212a;
    --border: #272832;
    --border-strong: #353744;
    --text: #ececf1;
    --text-2: #c2c2cc;
    --muted: #8d8d99;
    --faint: #5f5f6b;
    --primary: #7c7cf8;
    --primary-hover: #8f8ffa;
    --primary-soft: #1f1f3d;
    --primary-text: #a5a5ff;
    --success: #4ade80;
    --success-soft: #10241a;
    --warning: #fbbf24;
    --warning-soft: #2a2110;
    --danger: #f87171;
    --danger-soft: #2a1515;
    --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary-text); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
svg.i { flex: none; display: inline-block; vertical-align: middle; }

/* ---------------------------------------------------------------- layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar); flex: none; background: var(--surface); border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 14px 10px; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; padding: 4px 10px 10px; letter-spacing: .2px; }
.brand img { width: 26px; height: 26px; }
.nav { flex: 1; overflow-y: auto; }
.nav-group { margin-top: 16px; }
.nav-label { font-size: 11.5px; color: var(--faint); padding: 0 10px 4px; font-weight: 500; }
.nav a {
  display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 10px; border-radius: var(--radius-md);
  color: var(--text-2); font-size: 13.5px; margin-bottom: 1px;
}
.nav a:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary-text); font-weight: 550; }
.nav a .count { margin-left: auto; font-size: 11.5px; color: var(--muted); }
.sidebar-foot { border-top: 1px solid var(--border); padding: 10px 4px 0; display: flex; align-items: center; gap: 6px; }
.sidebar-foot .gw { flex: 1; min-width: 0; font-size: 12.5px; color: var(--text-2); display: flex; align-items: center; gap: 8px; padding-left: 6px; }
.sidebar-foot .gw:hover { text-decoration: none; color: var(--text); }
.topbar { display: none; }
.main { flex: 1; min-width: 0; }
.page { max-width: 1160px; margin: 0 auto; padding: 28px 32px 80px; }
.scrim { display: none; }

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-header h1 { font-size: 21px; font-weight: 650; margin: 0; letter-spacing: .1px; }
.page-header .desc { color: var(--muted); margin: 4px 0 0; font-size: 13.5px; max-width: 720px; }
.page-header .actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }

/* ---------------------------------------------------------------- building blocks */
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); align-items: start; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.xs { font-size: 11.5px; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ok-text { color: var(--success); }
.warn-text { color: var(--warning); }
.danger-text { color: var(--danger); }
.sep { height: 1px; background: var(--border); margin: 16px 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--border); min-height: 54px; }
.card-title { font-weight: 600; font-size: 14.5px; margin: 0; display: flex; align-items: center; gap: 8px; }
.card-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; font-weight: 400; }
.card-body { padding: 16px 18px; }
.card-foot { padding: 11px 18px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12.5px; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 14px; }
.toolbar + .toolbar { border-top: 1px solid var(--border); }

.stat { padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; min-height: 98px; color: inherit; }
.stat .label { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 24px; font-weight: 650; letter-spacing: -.3px; line-height: 1.25; display: flex; align-items: center; gap: 8px; }
.stat .value.sm { font-size: 17px; }
.stat .hint { font-size: 12px; color: var(--muted); }
a.stat:hover { text-decoration: none; border-color: var(--border-strong); }

/* ---------------------------------------------------------------- controls */
.btn, button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 12px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); border-radius: var(--radius-md);
  font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover:not(:disabled), button:hover:not(:disabled) { background: var(--hover); text-decoration: none; }
button:disabled, .btn.disabled { opacity: .5; cursor: not-allowed; }
.btn.primary, button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled), button.primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn.ghost, button.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover:not(:disabled), button.ghost:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.btn.danger, button.danger { color: var(--danger); }
.btn.danger:hover:not(:disabled), button.danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }
.btn.sm, button.sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn.icon, button.icon { width: 32px; padding: 0; }
.btn.icon.sm, button.icon.sm { width: 28px; }
button.link { height: auto; padding: 0; border: none; background: none; color: var(--primary-text); font-weight: 500; }
button.link:hover:not(:disabled) { background: none; text-decoration: underline; }

input[type=text], input[type=password], input[type=number], input[type=url], input[type=date], select, textarea {
  width: 100%; height: 34px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  border-radius: var(--radius-md); padding: 0 10px; font: inherit; font-size: 13.5px; transition: border-color .12s, box-shadow .12s;
}
textarea { height: auto; padding: 8px 10px; font-family: var(--mono); font-size: 12.5px; line-height: 1.6; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input::placeholder, textarea::placeholder { color: var(--faint); }
.input-icon { position: relative; }
.input-icon > .i { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.input-icon input { padding-left: 32px; }
input.w-sm, select.w-sm, .w-sm { width: 170px; }
input.w-md, select.w-md, .w-md { width: 220px; }
input.w-lg, select.w-lg, .w-lg { width: 280px; }

.field { display: block; margin-bottom: 16px; }
.field > .label, .field-label { display: block; font-size: 13px; font-weight: 550; margin-bottom: 6px; color: var(--text); }
.field-label .opt { color: var(--faint); font-weight: 400; margin-left: 4px; }
.help { display: block; color: var(--muted); font-size: 12px; margin-top: 5px; line-height: 1.5; }
.help.error { color: var(--danger); }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.fields.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 13.5px; }
.check input { margin: 0; width: 15px; height: 15px; }
input[type=checkbox], input[type=radio] { accent-color: var(--primary); }

.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13.5px; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 34px; height: 20px; border-radius: 999px; background: var(--border-strong); position: relative; transition: background .15s; flex: none; }
.switch .track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .15s; }
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(14px); }

.segmented { display: inline-flex; background: var(--hover); border-radius: var(--radius-md); padding: 3px; gap: 2px; }
.segmented button { height: 28px; border: none; background: transparent; color: var(--text-2); padding: 0 12px; border-radius: 6px; }
.segmented button:hover:not(:disabled) { background: transparent; color: var(--text); }
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(16,24,40,.12); }

.choice { display: grid; gap: 10px; }
.choice.two { grid-template-columns: 1fr 1fr; }
.choice label { border: 1px solid var(--border-strong); border-radius: var(--radius-md); padding: 12px 14px; cursor: pointer; display: flex; gap: 10px; align-items: flex-start; }
.choice label.on { border-color: var(--primary); background: var(--primary-soft); }
.choice label input { margin-top: 3px; }
.choice .t { font-weight: 600; font-size: 13.5px; }
.choice .d { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

/* ---------------------------------------------------------------- data display */
.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 500;
  background: var(--hover); color: var(--text-2); white-space: nowrap; }
.badge.primary { background: var(--primary-soft); color: var(--primary-text); }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.outline { background: transparent; border: 1px solid var(--border-strong); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; background: var(--faint); }
.dot.success { background: var(--success-dot); box-shadow: 0 0 0 3px var(--success-soft); }
.dot.warning { background: var(--warning-dot); box-shadow: 0 0 0 3px var(--warning-soft); }
.dot.danger { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

.chip { display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 8px; border-radius: 6px; font-size: 12px; background: var(--surface-2);
  border: 1px solid var(--border); color: var(--text-2); max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.group { color: var(--primary-text); border-color: transparent; background: var(--primary-soft); }
.chip.chain { color: var(--success); border-color: transparent; background: var(--success-soft); }
.chip.builtin { border-style: dashed; }
.chip.missing { color: var(--danger); border-color: transparent; background: var(--danger-soft); }
.chip.on { color: var(--primary-text); border-color: var(--primary); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }

.progress { height: 6px; border-radius: 999px; background: var(--hover); overflow: hidden; min-width: 80px; }
.progress > div { height: 100%; background: var(--primary); border-radius: 999px; }
.progress > div.warn { background: var(--warning-dot); }
.progress > div.full { background: var(--danger); }

table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 550; color: var(--muted); padding: 9px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: var(--surface-2); }
.table td.actions { text-align: right; white-space: nowrap; width: 1%; }
.table td.actions > * + * { margin-left: 2px; }
.table td.check-col, .table th.check-col { width: 40px; padding-right: 0; }
.table .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.table tr.off td > * { opacity: .55; }
.card > .table-wrap:first-child .table th:first-child, .card > .table:first-child th:first-child { border-top-left-radius: var(--radius); }
.card > .table-wrap:first-child .table th:last-child, .card > .table:first-child th:last-child { border-top-right-radius: var(--radius); }
.table-wrap { overflow-x: auto; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty > .i { color: var(--faint); margin-bottom: 12px; }
.empty .t { color: var(--text); font-weight: 600; margin-bottom: 4px; }
.empty .d { font-size: 13px; max-width: 440px; margin: 0 auto 16px; }

.callout { display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: var(--radius-md); font-size: 13px; }
.callout > .i { margin-top: 1px; }
.callout.info { background: var(--primary-soft); color: var(--primary-text); }
.callout.warning { background: var(--warning-soft); color: var(--warning); }
.callout.danger { background: var(--danger-soft); color: var(--danger); }
.callout.neutral { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.callout ul { margin: 6px 0 0; padding-left: 18px; }
.callout li + li { margin-top: 2px; }

.tabs { display: flex; gap: 22px; border-bottom: 1px solid var(--border); padding: 0 18px; overflow-x: auto; }
.tabs button { height: 42px; border: none; background: none; border-radius: 0; padding: 0; color: var(--muted); font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button:hover:not(:disabled) { background: none; color: var(--text); }
.tabs button.on { color: var(--text); border-bottom-color: var(--primary); }

pre.code { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 14px; overflow: auto; max-height: 68vh; margin: 0;
  white-space: pre; font-size: 12.5px; line-height: 1.6; }

.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: none; }
.list-row .title { font-weight: 550; }
.list-row .sub { color: var(--muted); font-size: 12.5px; }
.client-icon { width: 34px; height: 34px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12.5px; color: #fff; flex: none; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px; flex: none;
  background: var(--primary-soft); color: var(--primary-text); }

.flow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12.5px; }
.flow .hop { padding: 3px 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); }
.flow .hop.front { border-color: transparent; color: var(--primary-text); background: var(--primary-soft); }
.flow .hop.exit { border-color: transparent; color: var(--success); background: var(--success-soft); }
.flow .arrow { color: var(--faint); }

.picker { border: 1px solid var(--border); border-radius: var(--radius-md); max-height: 320px; overflow-y: auto; background: var(--surface); }
.picker .p { display: flex; align-items: center; gap: 10px; padding: 7px 10px; cursor: pointer; border-bottom: 1px solid var(--border); font-size: 13px; }
.picker .p:last-child { border-bottom: none; }
.picker .p:hover { background: var(--hover); }
.picker .p.on { background: var(--primary-soft); }
.picker .p.dim { opacity: .5; }
.picker .p .meta { margin-left: auto; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.member-list { border: 1px solid var(--border); border-radius: var(--radius-md); max-height: 340px; overflow-y: auto; }
.member-list .m { display: flex; align-items: center; gap: 8px; padding: 5px 6px 5px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
.member-list .m:last-child { border-bottom: none; }
.member-list .m .idx { width: 16px; color: var(--faint); font-size: 12px; text-align: right; flex: none; }
.member-list .empty { padding: 26px 12px; font-size: 13px; }

/* ---------------------------------------------------------------- overlays */
.overlay { position: fixed; inset: 0; background: rgba(15, 15, 20, 0.4); z-index: 60; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(24px); opacity: .6; } }
@keyframes pop { from { transform: translateY(6px) scale(.985); opacity: 0; } }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(var(--w, 640px), 100vw); background: var(--surface); z-index: 61; display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg); animation: slide .18s ease-out; border-left: 1px solid var(--border); }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 22px 14px; }
.drawer-head h2 { margin: 0; font-size: 17px; font-weight: 650; }
.drawer-head .sub { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.drawer > .tabs { padding: 0 22px; }
.drawer-head + .drawer-body { border-top: 1px solid var(--border); }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px 22px; }
.drawer-foot { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding: 12px 22px; border-top: 1px solid var(--border); background: var(--surface-2); }
.section + .section { margin-top: 24px; padding-top: 22px; border-top: 1px solid var(--border); }
.section-title { font-size: 13.5px; font-weight: 650; margin: 0 0 4px; display: flex; align-items: center; gap: 8px; }
.section-desc { color: var(--muted); font-size: 12.5px; margin: 0 0 14px; }

.modal-wrap { position: fixed; inset: 0; z-index: 61; display: flex; align-items: flex-start; justify-content: center; padding: 10vh 16px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: var(--w, 480px); box-shadow: var(--shadow-lg); animation: pop .16s ease-out; border: 1px solid var(--border); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 0; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 14px 20px 20px; }

.menu { position: relative; display: inline-block; }
.menu-pop { position: fixed; min-width: 172px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-lg); padding: 4px; z-index: 90; animation: pop .12s ease-out; text-align: left; }
.menu-pop button { width: 100%; justify-content: flex-start; border: none; background: none; height: 32px; padding: 0 10px; color: var(--text); font-weight: 450; gap: 8px; }
.menu-pop button:hover:not(:disabled) { background: var(--hover); }
.menu-pop button.danger { color: var(--danger); }
.menu-pop button.danger:hover:not(:disabled) { background: var(--danger-soft); }
.menu-pop .sep { margin: 4px 0; }

.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: min(420px, calc(100vw - 40px)); }
.toast { display: flex; gap: 10px; align-items: flex-start; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg);
  padding: 11px 14px; font-size: 13px; animation: pop .16s ease-out; }
.toast > .i { margin-top: 1px; color: var(--primary); }
.toast.ok > .i { color: var(--success); }
.toast.error > .i { color: var(--danger); }

.selection-bar { position: sticky; bottom: 16px; margin-top: 12px; display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 16px; background: var(--text); color: var(--bg);
  border-radius: 12px; box-shadow: var(--shadow-lg); z-index: 20; font-size: 13px; }
.selection-bar button { height: 30px; }
.selection-bar button.ghost { color: var(--bg); }
.selection-bar button.ghost:hover:not(:disabled) { background: rgba(127,127,127,.25); color: var(--bg); }

.qr { display: flex; justify-content: center; }
.qr img { width: 240px; height: 240px; background: #fff; padding: 10px; border-radius: 10px; border: 1px solid var(--border); }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login { width: 100%; max-width: 380px; padding: 28px; }
.login .brand { padding: 0 0 4px; font-size: 20px; }

details.disclosure > summary { cursor: pointer; color: var(--text-2); font-size: 13px; font-weight: 500; list-style: none; display: inline-flex; align-items: center; gap: 4px; user-select: none; }
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary .i { transition: transform .15s; }
details.disclosure[open] > summary .i { transform: rotate(90deg); }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1080px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main, .grid-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); z-index: 70; }
  .sidebar.open { transform: none; }
  .scrim.open { display: block; position: fixed; inset: 0; background: rgba(15,15,20,.35); z-index: 65; }
  .topbar { display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 30; background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px 10px; }
  .topbar .brand { padding: 0; font-size: 15px; }
  .page { padding: 18px 14px 80px; }
  .page-header { flex-direction: column; }
  .page-header .actions { justify-content: flex-start; }
  .grid-2, .fields, .fields.three, .choice.two { grid-template-columns: minmax(0, 1fr); }
  .stat { min-height: 0; }
  .stat .value { font-size: 20px; }
  input.w-sm, select.w-sm, .w-sm, input.w-md, select.w-md, .w-md, input.w-lg, select.w-lg, .w-lg { width: 100%; }
  .table.responsive thead { display: none; }
  .table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
  .table.responsive tr { padding: 10px 14px; border-bottom: 1px solid var(--border); }
  .table.responsive tr:last-child { border-bottom: none; }
  .table.responsive td { border: none; padding: 3px 0; }
  .table.responsive td.actions { text-align: left; width: auto; padding-top: 8px; }
  .table.responsive td.check-col { display: none; }
  .table.responsive td[data-label] { display: flex; gap: 10px; align-items: baseline; }
  .table.responsive td[data-label]::before { content: attr(data-label); flex: none; width: 44px; color: var(--faint); font-size: 12px; }
  .list-row { flex-wrap: wrap; }
  .list-row > .grow { flex: 1 1 calc(100% - 60px); min-width: 0; }
  .drawer-body, .drawer-head, .drawer-foot { padding-left: 16px; padding-right: 16px; }
  .drawer > .tabs { padding: 0 16px; }
}

.copy-field { display: flex; gap: 6px; min-width: 0; align-items: center; }
.copy-field input { flex: 1; min-width: 0; font-family: var(--mono); font-size: 12px; color: var(--text-2); background: var(--surface-2); }
.copy-field > button, .copy-field > .btn { flex: none; }
.field > .label .opt { color: var(--faint); font-weight: 400; margin-left: 4px; font-size: 12px; }

/* ---------------------------------------------------------------- AI assistant */
.chat { display: flex; flex-direction: column; gap: 10px; padding: 18px; min-height: 280px; max-height: 58vh; overflow-y: auto; background: var(--surface-2); }
.chat-empty { margin: auto; max-width: 560px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--text-2); padding: 20px 0; }
.chat-suggest { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; width: 100%; }
.chat-suggest button { justify-content: flex-start; text-align: left; height: auto; padding: 8px 12px; white-space: normal; line-height: 1.5; }
.bubble { max-width: 82%; padding: 10px 14px; border-radius: 12px; white-space: pre-wrap; line-height: 1.6; font-size: 13.5px; word-break: break-word; }
.bubble.user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.bubble.ai { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-step { align-self: flex-start; display: flex; gap: 10px; align-items: flex-start; padding: 8px 12px; border-radius: 10px; background: var(--surface); border: 1px dashed var(--border-strong); max-width: 82%; }
.chat-step .xs { margin-top: 2px; line-height: 1.5; }
.chat-step-icon { width: 18px; height: 18px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; flex: none; margin-top: 1px; background: var(--success-soft, #e7f7ee); color: var(--success, #16a34a); }
.chat-step.fail .chat-step-icon { background: var(--danger-soft); color: var(--danger); }
.chat-note { align-self: flex-start; display: inline-flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.chat-input { padding: 14px 18px; border-top: 1px solid var(--border); }
.chat-input textarea { resize: vertical; min-height: 56px; }
.spinner { width: 12px; height: 12px; border: 2px solid var(--border-strong); border-top-color: var(--primary); border-radius: 50%; display: inline-block; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.tool-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.tool-item { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; flex-wrap: wrap; }
@media (max-width: 760px) { .bubble, .chat-step { max-width: 100%; } }

/* ---------------------------------------------------------------- license gate */
.gate { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--bg); }
.gate-card { width: 100%; max-width: 440px; padding: 30px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); text-align: center; }
.gate-card .brand { padding: 0 0 4px; font-size: 20px; }
.gate-card h2 { font-size: 18px; margin: 10px 0 6px; }
.gate-card textarea, .gate-card .disclosure, .gate-card .callout { text-align: left; }
.gate-card textarea { font-size: 12px; resize: vertical; }

/* online update (settings → 授权与关于) */
.update-box { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.update-notes { white-space: pre-wrap; font-family: inherit; font-size: 12.5px; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 10px 12px; margin: 10px 0 0; max-height: 220px; overflow: auto; }
