:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #f8fafb;
  --ink: #18212b;
  --muted: #647180;
  --line: #dce2e8;
  --line-strong: #c8d0d8;
  --accent: #d95d0b;
  --accent-hover: #bd4e06;
  --accent-soft: #fff1e8;
  --success: #16845b;
  --success-soft: #e7f7f0;
  --info: #2368a2;
  --info-soft: #eaf3fb;
  --danger: #c0392b;
  --danger-hover: #a72f23;
  --danger-soft: #fceceb;
  --warning: #9a6700;
  --warning-soft: #fff7d6;
  --shadow: 0 8px 28px rgba(20, 31, 44, 0.09);
  font-family: Inter, "Noto Sans SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }

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

body { background: var(--bg); font-size: 14px; line-height: 1.5; }

button, input, select, textarea { font: inherit; letter-spacing: 0; }

button, select, input[type="checkbox"], input[type="radio"] { cursor: pointer; }

button:disabled, select:disabled, input:disabled { cursor: not-allowed; opacity: .55; }

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 2px solid rgba(35, 104, 162, .55);
  outline-offset: 2px;
}

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.skip-link { position: fixed; left: 12px; top: -60px; z-index: 100; background: var(--ink); color: white; padding: 9px 14px; border-radius: 4px; }
.skip-link:focus { top: 12px; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(12px);
}

.brand { display: inline-flex; align-items: center; gap: 11px; color: var(--ink); text-decoration: none; min-width: 0; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 7px; color: white; background: #19242f; }
.brand-mark svg { width: 21px; height: 21px; }
.brand > span:last-child { display: flex; flex-direction: column; min-width: 0; }
.brand strong { font-size: 15px; line-height: 1.25; }
.brand small { color: var(--muted); font-size: 11px; }

.header-actions { display: flex; align-items: center; gap: 8px; }
.connection-state { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); margin-right: 3px; font-size: 12px; }
.connection-state i { width: 7px; height: 7px; border-radius: 50%; background: #9aa4ad; box-shadow: 0 0 0 3px #eef1f3; }
.connection-state.connected { color: var(--success); }
.connection-state.connected i { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }

.button, .icon-button {
  border: 1px solid transparent;
  border-radius: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 650;
  transition: background .15s, border-color .15s, color .15s, transform .1s;
}
.button { min-height: 38px; padding: 8px 14px; }
.button:active:not(:disabled), .icon-button:active:not(:disabled) { transform: translateY(1px); }
.button.primary { color: white; background: var(--accent); border-color: var(--accent); }
.button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.button.secondary { color: #354352; background: white; border-color: var(--line-strong); }
.button.secondary:hover:not(:disabled) { background: var(--surface-muted); border-color: #aeb8c1; }
.button.danger { color: white; background: var(--danger); border-color: var(--danger); }
.button.danger:hover:not(:disabled) { background: var(--danger-hover); }
.button.small { min-height: 34px; padding: 6px 11px; font-size: 12px; }
.icon-button { width: 36px; height: 36px; padding: 0; color: var(--muted); background: transparent; }
.icon-button:hover:not(:disabled) { color: var(--ink); background: #edf1f4; }

.app-shell { display: grid; grid-template-columns: 294px minmax(0, 1fr); min-height: calc(100vh - 66px); }

.zone-panel {
  position: sticky;
  top: 66px;
  height: calc(100vh - 66px);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 18px 16px 14px;
  overflow: hidden;
}

.panel-heading, .workspace-topbar, .section-intro, .selection-row, .form-footer, .modal-header, .modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow { color: var(--accent); font-size: 10px; line-height: 1.2; font-weight: 800; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
.panel-heading h2 { font-size: 19px; margin: 2px 0 0; }
.workspace-topbar h1 { margin: 3px 0 0; font-size: 24px; line-height: 1.25; }

.zone-tools { display: grid; gap: 8px; margin-top: 16px; }
.search-field { position: relative; display: block; }
.search-field svg { position: absolute; left: 10px; top: 50%; width: 16px; transform: translateY(-50%); color: #7a8794; pointer-events: none; }
.search-field input { padding-left: 34px; }

input[type="text"], input[type="search"], input[type="password"], input:not([type]), select, textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: white;
  color: var(--ink);
  padding: 9px 10px;
  min-height: 38px;
  transition: border-color .15s, box-shadow .15s;
}
input:hover, select:hover, textarea:hover { border-color: #aeb8c1; }
input:focus, select:focus, textarea:focus { border-color: var(--info); box-shadow: 0 0 0 3px rgba(35, 104, 162, .11); outline: none; }
textarea { resize: vertical; min-height: 92px; font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: 12px; line-height: 1.55; }

.selection-row { margin: 14px 1px 8px; font-size: 12px; color: var(--muted); }
.checkbox-label { display: inline-flex; align-items: center; gap: 8px; color: #455363; }
input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }

.zone-list { flex: 1; min-height: 120px; overflow-y: auto; margin: 0 -5px; padding: 2px 5px 10px; }
.zone-row { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; align-items: center; gap: 9px; min-height: 49px; padding: 7px 8px; border-radius: 5px; transition: background .12s; }
.zone-row:hover { background: #f3f6f8; }
.zone-row.selected { background: var(--accent-soft); }
.zone-row > span { min-width: 0; }
.zone-row strong, .zone-row small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.zone-row strong { font-size: 12px; color: #263341; }
.zone-row small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #9aa4ad; }
.status-dot.active { background: var(--success); }
.status-dot.pending { background: var(--warning); }
.status-dot.moved, .status-dot.initializing { background: var(--info); }

.selection-summary { border-top: 1px solid var(--line); padding: 13px 3px 0; display: flex; align-items: baseline; gap: 7px; color: var(--muted); }
.selection-summary strong { color: var(--accent); font-size: 22px; line-height: 1; }

.workspace { min-width: 0; padding: 26px clamp(20px, 3vw, 46px) 48px; }
.workspace-topbar { max-width: 1120px; margin: 0 auto 19px; }
.scope-chip { display: inline-flex; align-items: center; gap: 7px; max-width: 350px; color: #3c4a58; background: white; border: 1px solid var(--line); border-radius: 5px; padding: 7px 10px; font-size: 12px; }
.scope-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scope-chip svg { width: 15px; color: var(--info); flex: none; }

.tabs { max-width: 1120px; margin: 0 auto 18px; display: flex; gap: 3px; border-bottom: 1px solid var(--line-strong); }
.tab { position: relative; min-height: 44px; padding: 8px 14px; border: 0; background: transparent; color: var(--muted); display: inline-flex; align-items: center; gap: 7px; font-weight: 650; }
.tab::after { content: ""; position: absolute; height: 2px; left: 10px; right: 10px; bottom: -1px; background: transparent; }
.tab:hover { color: var(--ink); background: rgba(255,255,255,.55); }
.tab.active { color: var(--accent); }
.tab.active::after { background: var(--accent); }
.tab svg { width: 16px; }
.tab b { min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px; display: inline-grid; place-items: center; color: white; background: var(--danger); font-size: 9px; }

.tool-view { max-width: 1120px; margin: 0 auto; }
.section-intro { align-items: flex-start; margin: 5px 0 13px; }
.section-intro h2 { margin-bottom: 3px; font-size: 16px; }
.section-intro p { margin: 0; color: var(--muted); font-size: 12px; }
.section-intro code, .field code { color: #3a4550; background: #e9edf1; padding: 1px 4px; border-radius: 3px; font-size: .92em; }
.permission-badge { flex: none; padding: 4px 7px; border-radius: 4px; background: var(--info-soft); color: var(--info); font: 600 10px/1.3 "SFMono-Regular", Consolas, monospace; }

.operation-form { border: 1px solid var(--line); background: var(--surface); border-radius: 7px; box-shadow: 0 3px 12px rgba(20, 31, 44, .035); overflow: hidden; }
.operation-form fieldset { border: 0; padding: 18px 20px 0; margin: 0; }
.operation-form legend { padding: 0; margin-bottom: 9px; color: #4c5967; font-size: 11px; font-weight: 750; }
.segmented { display: inline-grid; grid-template-columns: repeat(4, minmax(76px, 1fr)); padding: 3px; border: 1px solid var(--line-strong); background: #eef2f4; border-radius: 6px; }
.segmented.narrow { grid-template-columns: repeat(2, minmax(110px, 1fr)); }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { min-height: 32px; display: grid; place-items: center; padding: 5px 11px; color: #526170; border-radius: 4px; font-size: 12px; font-weight: 650; }
.segmented input:checked + span { color: var(--ink); background: white; box-shadow: 0 1px 4px rgba(20, 31, 44, .12); }
.segmented input:focus-visible + span { outline: 2px solid rgba(35,104,162,.55); outline-offset: 1px; }

.form-grid { display: grid; gap: 17px 18px; padding: 20px; }
.form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field { display: flex; min-width: 0; flex-direction: column; gap: 6px; color: #3e4c5a; font-size: 12px; font-weight: 650; }
.field small, .toggle-field small { color: var(--muted); font-size: 10px; font-weight: 450; }
.expression-field { grid-column: 1 / -1; }
.toggle-field { grid-column: 1 / -1; min-height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 15px; border: 1px solid var(--line); background: var(--surface-muted); border-radius: 5px; padding: 9px 12px; }
.toggle-field span, .toggle-field strong, .toggle-field small { display: block; }
.toggle-field strong { font-size: 12px; }
.toggle-field input[role="switch"] { appearance: none; width: 36px; height: 20px; padding: 2px; border-radius: 10px; background: #a9b3bd; transition: background .15s; }
.toggle-field input[role="switch"]::before { content: ""; display: block; width: 16px; height: 16px; border-radius: 50%; background: white; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .15s; }
.toggle-field input[role="switch"]:checked { background: var(--success); }
.toggle-field input[role="switch"]:checked::before { transform: translateX(16px); }

.form-footer { min-height: 68px; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-muted); }
.form-note { margin: 0; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; }
.form-note svg { flex: none; width: 15px; color: var(--warning); }
.preview-button { min-width: 156px; }

.settings-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.setting-item { min-height: 62px; display: flex; align-items: flex-start; gap: 10px; padding: 11px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface-muted); transition: border-color .15s, background .15s; }
.setting-item:hover { border-color: var(--line-strong); background: white; }
.setting-item:has(input:checked) { border-color: #efb17e; background: var(--accent-soft); }
.setting-item input { margin-top: 2px; flex: none; }
.setting-item strong, .setting-item small { display: block; }
.setting-item strong { color: #344251; font-size: 12px; }
.setting-item small { color: var(--muted); font-size: 10px; margin-top: 2px; }

.empty-state { min-height: 270px; display: grid; align-content: center; justify-items: center; padding: 30px; color: var(--muted); text-align: center; }
.empty-state.compact { min-height: 180px; }
.empty-state svg { width: 28px; height: 28px; margin-bottom: 9px; color: #9aa6b1; }
.empty-state h3 { margin-bottom: 4px; color: #465462; font-size: 14px; }
.empty-state p { margin: 0; font-size: 11px; }

.activity-list { border: 1px solid var(--line); border-radius: 7px; background: white; overflow: hidden; }
.activity-row { display: grid; grid-template-columns: 100px minmax(0, 1fr) auto; gap: 16px; align-items: center; min-height: 66px; padding: 11px 15px; border-bottom: 1px solid var(--line); }
.activity-row:last-child { border-bottom: 0; }
.activity-time { color: var(--muted); font: 10px/1.4 "SFMono-Regular", Consolas, monospace; }
.activity-main { min-width: 0; }
.activity-main strong, .activity-main small { display: block; }
.activity-main strong { font-size: 12px; }
.activity-main small { color: var(--muted); font-size: 10px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.modal { width: min(560px, calc(100vw - 28px)); border: 0; border-radius: 7px; padding: 0; color: var(--ink); background: white; box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(20, 29, 39, .45); backdrop-filter: blur(2px); }
.modal > form { margin: 0; }
.modal-header { padding: 19px 20px 14px; border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 3px 0 0; font-size: 18px; }
.modal-actions { padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-muted); justify-content: flex-end; }
.connect-modal .field, .permission-help, .session-option { margin: 17px 20px 0; }
.auth-mode-control { margin: 17px 20px 0; display: grid; gap: 7px; color: #3e4c5a; font-size: 12px; font-weight: 650; }
.auth-mode-control .segmented { width: 100%; }
.credential-fields .field + .field { margin-top: 12px; }
.security-notice { margin: 17px 20px 0; display: flex; gap: 11px; padding: 11px; border: 1px solid #acd7c6; border-radius: 5px; color: #24664e; background: var(--success-soft); }
.security-notice svg { flex: none; margin-top: 2px; }
.security-notice p { margin: 0; }
.security-notice strong, .security-notice span { display: block; font-size: 11px; }
.security-notice span { margin-top: 2px; color: #4c7667; }
.secret-input { position: relative; display: block; }
.secret-input input { padding-right: 43px; font-family: "SFMono-Regular", Consolas, monospace; }
.secret-input .icon-button { position: absolute; right: 1px; top: 1px; }
.permission-help { margin-bottom: 18px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface-muted); padding: 9px 11px; color: var(--muted); font-size: 11px; }
.permission-help summary { color: #445260; cursor: pointer; font-weight: 650; }
.permission-help ul { margin: 8px 0 1px; padding-left: 19px; font-family: "SFMono-Regular", Consolas, monospace; }
.permission-help p { margin: 8px 0 1px; line-height: 1.55; }
.warning-help { border-color: #e7c78a; background: var(--warning-soft); }

.preview-modal { width: min(780px, calc(100vw - 28px)); }
.preview-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); border-bottom: 1px solid var(--line); }
.summary-stat { padding: 13px 14px; background: var(--surface-muted); }
.summary-stat strong, .summary-stat span { display: block; }
.summary-stat strong { font-size: 18px; }
.summary-stat span { margin-top: 2px; color: var(--muted); font-size: 10px; }
.summary-stat.ready strong { color: var(--success); }
.summary-stat.error strong { color: var(--danger); }
.preview-list { max-height: min(52vh, 500px); overflow-y: auto; }
.preview-row { border-bottom: 1px solid var(--line); }
.preview-row:last-child { border-bottom: 0; }
.preview-row-header { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; align-items: center; gap: 9px; min-height: 47px; padding: 9px 16px; }
.preview-row-header strong { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-row-header svg { width: 16px; }
.spinning { animation: spin .8s linear infinite; }
.preview-detail { margin: 0 16px 12px 43px; padding: 8px 10px; border-radius: 4px; background: #f3f6f8; color: #4e5d6b; font: 10px/1.55 "SFMono-Regular", Consolas, monospace; overflow-wrap: anywhere; }
.preview-detail > div + div { margin-top: 4px; }
.preview-detail .error-text { color: var(--danger); }
.status-pill { display: inline-flex; align-items: center; min-height: 22px; padding: 3px 7px; border-radius: 4px; font-size: 10px; font-weight: 700; }
.status-pill.ready, .status-pill.success { color: var(--success); background: var(--success-soft); }
.status-pill.noop { color: var(--info); background: var(--info-soft); }
.status-pill.error { color: var(--danger); background: var(--danger-soft); }
.status-pill.loading { color: var(--muted); background: #edf1f4; }
.danger-confirm { padding: 12px 20px; border-top: 1px solid #efc1bc; background: var(--danger-soft); }
.danger-confirm .checkbox-label { color: #71352e; font-size: 11px; }

.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 80; display: grid; gap: 8px; width: min(360px, calc(100vw - 28px)); }
.toast { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; gap: 9px; align-items: start; padding: 11px 12px; border: 1px solid var(--line-strong); border-left-width: 3px; border-radius: 5px; color: #34414f; background: white; box-shadow: var(--shadow); animation: toast-in .18s ease-out; }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.info { border-left-color: var(--info); }
.toast p { margin: 0; font-size: 11px; }
.toast .icon-button { width: 24px; height: 24px; margin: -4px; }

.skeleton { position: relative; overflow: hidden; background: #edf1f4; border-radius: 3px; color: transparent; }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgba(255,255,255,.75), transparent); animation: shimmer 1.25s infinite; }

[hidden] { display: none !important; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { transform: translateX(100%); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(7px); } }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 248px minmax(0, 1fr); }
  .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workspace { padding-inline: 20px; }
}

@media (max-width: 720px) {
  .app-header { height: 58px; padding: 0 12px; }
  .brand small, .connection-state { display: none; }
  .button { padding-inline: 11px; }
  .app-shell { display: block; }
  .zone-panel { position: relative; top: 0; height: auto; max-height: 330px; border-right: 0; border-bottom: 1px solid var(--line); padding: 14px 12px 10px; }
  .zone-list { min-height: 92px; max-height: 150px; }
  .selection-summary { display: none; }
  .workspace { padding: 18px 12px 38px; }
  .workspace-topbar { align-items: flex-end; margin-bottom: 13px; }
  .workspace-topbar h1 { font-size: 20px; }
  .scope-chip { max-width: 46%; }
  .tabs { overflow-x: auto; }
  .tab { flex: 0 0 auto; padding-inline: 10px; }
  .tab svg { display: none; }
  .section-intro { gap: 8px; }
  .permission-badge { display: none; }
  .form-grid.cols-2, .settings-grid { grid-template-columns: 1fr; }
  .segmented { display: grid; grid-template-columns: repeat(4, minmax(58px, 1fr)); width: 100%; }
  .segmented span { padding-inline: 5px; }
  .form-footer { align-items: stretch; flex-direction: column; }
  .form-note { align-items: flex-start; }
  .preview-button { width: 100%; }
  .preview-summary { grid-template-columns: repeat(2, 1fr); }
  .modal-actions .button { flex: 1; font-size: 12px; white-space: nowrap; }
  .activity-row { grid-template-columns: minmax(0, 1fr) auto; }
  .activity-time { display: none; }
}

@media (max-width: 420px) {
  .brand strong { font-size: 14px; }
  .header-actions .button span { display: none; }
  .workspace-topbar { display: block; }
  .scope-chip { max-width: none; margin-top: 10px; }
  .section-intro p { max-width: 46ch; }
  .operation-form fieldset, .form-grid, .form-footer { padding-left: 14px; padding-right: 14px; }
  .preview-row-header { padding-inline: 12px; }
  .preview-detail { margin-left: 39px; margin-right: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
