:root {
  --bg: #ffffff;
  --app-bg: #fafafa;
  --surface: #ffffff;
  --surface-muted: #f6f6f7;
  --ink: #111111;
  --ink-2: #2b2b2b;
  --muted: #6b7280;
  --muted-2: #9ca3af;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --accent: #111111;
  --focus: #2563eb;
  --creator-red: #ff2442;
  --warning: #b7791f;
  --danger: #c2410c;
  --ok: #15803d;
  --radius: 8px;
  --shadow-soft: 0 14px 40px rgba(17, 17, 17, 0.06);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  height: 100vh;
  height: 100svh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #f7f7f8;
}

.login-screen.is-hidden {
  display: none;
}

/* 登录状态控制：未登录时隐藏应用主体，已登录时隐藏登录页 */
body.auth-required:not(.auth-logged-in) .app-shell,
body.auth-required:not(.auth-logged-in) .role-gate {
  display: none;
}
body.auth-logged-in .login-screen {
  display: none;
}
body.auth-booting .role-gate,
body.auth-booting .app-shell {
  visibility: hidden;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.login-panel .brand-mark {
  width: 44px;
  height: 44px;
}

.login-panel h1 {
  font-size: 28px;
}

.login-panel p {
  color: var(--muted);
  line-height: 1.6;
}

.login-panel label {
  display: grid;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-2);
}

.login-panel input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.login-error {
  min-height: 20px;
  color: var(--danger);
  font-size: 13px;
}

.login-switch {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

.login-switch a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}

.login-switch a:hover {
  text-decoration: underline;
}

.role-gate {
  position: fixed;
  left: 50%;
  top: 10px;
  z-index: 30;
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
}

.role-link {
  min-width: 92px;
  padding: 7px 10px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  text-decoration: none;
}

.role-link.is-active {
  background: #111;
  color: #fff;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 2.2vw, 34px);
  line-height: 1.08;
  letter-spacing: 0;
}

h2 {
  font-size: 16px;
  line-height: 1.35;
}

h3 {
  font-size: 14px;
  line-height: 1.35;
}

.app-shell {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  height: 100vh;
  height: 100svh;
  min-height: 0;
  overflow: hidden;
  background: var(--app-bg);
  transition: grid-template-columns 160ms ease;
}

.is-hidden {
  display: none !important;
}

body.sidebar-collapsed .app-shell {
  grid-template-columns: 64px minmax(0, 1fr);
}

.sidebar {
  height: 100vh;
  height: 100svh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 18px 12px;
  overflow: auto;
  background: #fff;
  border-right: 1px solid var(--line);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
}

.brand-copy {
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 7px;
  background: #111;
  color: #fff;
  font-size: 12px;
  font-weight: 760;
}

.brand-name {
  color: var(--ink);
  font-weight: 720;
}

.brand-subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.sidebar-toggle {
  margin-left: auto;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}

.nav-list {
  display: grid;
  gap: 2px;
}

.nav-item {
  border: 0;
  border-radius: 6px;
  min-height: 34px;
  padding: 0 10px;
  background: transparent;
  color: #4b5563;
  text-align: left;
  font-size: 13px;
  transition: background 140ms ease, color 140ms ease;
}

.nav-item::before {
  content: attr(data-short);
  display: none;
}

.nav-item:hover {
  background: var(--surface-muted);
  color: var(--ink);
}

.nav-item.is-active {
  background: #111;
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 8px;
}

body.sidebar-collapsed .sidebar {
  padding: 18px 10px;
}

body.sidebar-collapsed .brand-copy,
body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .sidebar-footer {
  display: none;
}

body.sidebar-collapsed .brand-block {
  justify-content: center;
  padding: 0;
}

body.sidebar-collapsed .sidebar-toggle {
  position: absolute;
  left: 48px;
  top: 20px;
  z-index: 3;
}

body.sidebar-collapsed .nav-item {
  display: grid;
  place-items: center;
  padding: 0;
  text-align: center;
}

body.sidebar-collapsed .nav-item::before {
  display: block;
}

.workspace {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  height: 100vh;
  height: 100svh;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.topbar p,
.section-heading p {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.45;
  font-size: 13px;
}

.topbar-actions,
.section-heading.with-action,
.portal-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button,
.danger-button {
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  min-height: 34px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
}

.primary-button {
  border-color: #111;
  background: #111;
  color: #fff;
}

.secondary-button {
  background: #fff;
}

.ghost-button {
  background: #fff;
  color: #374151;
}

.ghost-button.danger {
  color: var(--danger);
}

.primary-button:disabled,
.secondary-button:disabled,
.ghost-button:disabled,
.icon-button:disabled,
.danger-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.danger-button {
  border-color: #fed7aa;
  background: #fff7ed;
  color: var(--danger);
}

.danger-button:hover {
  border-color: var(--danger);
}

.icon-button {
  width: 34px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.sync-pill {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ok);
  font-size: 12px;
}

.sync-pill.is-dirty {
  color: var(--warning);
}

.runtime-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.runtime-pill.is-ok {
  color: var(--ok);
  border-color: #bbf7d0;
  background: #f0fdf4;
}

.runtime-pill.is-warn,
.runtime-pill.is-loading {
  color: var(--warning);
  border-color: #f3d19e;
  background: #fffbeb;
}

.runtime-pill.is-danger {
  color: var(--danger);
  border-color: #fed7aa;
  background: #fff7ed;
}

.view {
  display: none;
  min-height: 0;
  overflow: hidden;
  padding: 16px;
  animation: viewIn 180ms ease both;
}

.view.is-active {
  display: grid;
}

@keyframes viewIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 16px;
}

.section-heading {
  flex: 0 0 auto;
  margin-bottom: 14px;
}

.section-heading.with-action {
  justify-content: space-between;
}

.panel-actions {
  display: flex;
  align-items: end;
  gap: 8px;
  flex: 0 0 auto;
}

.compact-filter {
  width: 132px;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.compact-filter select {
  min-height: 34px;
  padding: 6px 30px 6px 10px;
}

.compact-button {
  min-height: 34px;
  padding: 7px 10px;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.badge.warn {
  color: var(--warning);
  border-color: #f3d19e;
  background: #fffbeb;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 8px;
  background: rgba(17, 17, 17, 0.9);
  color: #fff;
  font-size: 13px;
  opacity: 0;
  transition: opacity 200ms ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
}