:root {
  color-scheme: light;
  --surface: #f7f7fa;
  --panel: #ffffff;
  --panel-subtle: #f1f0f4;
  --ink: #252130;
  --muted: #6f697b;
  --subtle: #827b8d;
  --line: #e5e2ea;
  --primary: #7c3aed;
  --primary-dark: #6d28d9;
  --primary-deep: #3b0764;
  --primary-soft: #f5f3ff;
  --info: #0369a1;
  --info-soft: #f0f9ff;
  --success: #047857;
  --success-soft: #ecfdf5;
  --warning: #92400e;
  --warning-soft: #fffbeb;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --shadow-sm: 0 1px 2px rgba(37, 33, 48, 0.05);
  --shadow-md: 0 16px 40px rgba(37, 33, 48, 0.14);
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --radius: 0.5rem;
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--surface);
  color: var(--ink);
  font-family: Tahoma, "Leelawadee UI", system-ui, sans-serif;
  font-size: 1rem;
  line-height: 1.55;
  font-kerning: normal;
}

button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
svg { width: 1.1rem; height: 1.1rem; stroke-width: 1.6; }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.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;
}

.skip-link {
  position: fixed;
  left: 1rem;
  top: -5rem;
  z-index: 90;
  border-radius: var(--radius);
  background: var(--panel);
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow-md);
}
.skip-link:focus { top: 1rem; }

.brand-mark {
  display: inline-flex;
  width: 2.5rem;
  height: 2.5rem;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}
.brand-mark.large { width: 3.5rem; height: 3.5rem; font-size: 1.25rem; background: #fff; color: var(--primary-deep); }
.brand-name { margin: 0.75rem 0 0; font-weight: 700; }
.brand-name.light { color: #fff; }

.button,
.icon-button,
.icon-text-button {
  display: inline-flex;
  min-height: 2.75rem;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border-radius: 0.375rem;
  border: 1px solid transparent;
  font-size: 0.875rem;
  font-weight: 700;
  transition: background-color 180ms ease-out, border-color 180ms ease-out, color 180ms ease-out, transform 100ms ease-out;
}
.button { padding: 0.65rem 1rem; }
.button.small { min-height: 2.5rem; padding: 0.5rem 0.75rem; }
.button.primary { border-color: var(--primary); background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.button.primary:hover { border-color: var(--primary-dark); background: var(--primary-dark); }
.button.secondary { border-color: var(--line); background: var(--panel); color: var(--ink); }
.button.secondary:hover { border-color: #cfc8dd; background: var(--primary-soft); color: var(--primary-deep); }
.button.full { width: 100%; }
.button:active, .icon-button:active, .icon-text-button:active { transform: translateY(1px); }
.button:disabled, .icon-button:disabled { cursor: not-allowed; opacity: 0.45; }

.icon-button {
  width: 2.75rem;
  padding: 0;
  border-color: var(--line);
  background: var(--panel);
  color: var(--muted);
}
.icon-button:hover { border-color: #cfc8dd; background: var(--primary-soft); color: var(--primary-deep); }
.icon-button.soft { border-color: transparent; background: var(--primary-soft); color: var(--primary); }
.icon-button.danger:hover { border-color: #fecaca; background: var(--danger-soft); color: var(--danger); }
.icon-text-button { padding: 0.55rem 0.75rem; border-color: transparent; background: transparent; color: #e9d5ff; }
.icon-text-button:hover { background: rgba(255,255,255,0.1); color: #fff; }

.icon-shell {
  display: inline-flex;
  width: 2.75rem;
  height: 2.75rem;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border-radius: var(--radius);
  background: var(--primary-soft);
  color: var(--primary);
}

label { display: grid; gap: 0.4rem; color: var(--ink); font-size: 0.875rem; font-weight: 700; }
label small { color: var(--muted); font-weight: 400; }
input, select, textarea {
  width: 100%;
  min-height: 2.75rem;
  border: 1px solid var(--line);
  border-radius: 0.375rem;
  background: var(--panel);
  color: var(--ink);
  padding: 0.65rem 0.75rem;
  font-size: 1rem;
  font-weight: 400;
  transition: border-color 160ms ease-out, box-shadow 160ms ease-out;
}
textarea { min-height: 6rem; resize: vertical; line-height: 1.55; }
input::placeholder, textarea::placeholder { color: #777080; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px #ede9fe; outline: none; }

.check-row { display: flex; min-height: 2.75rem; align-items: center; gap: 0.65rem; font-weight: 600; }
.check-row input { width: 1.1rem; min-height: 1.1rem; accent-color: var(--primary); }

.notice { margin: 1rem 0; border: 1px solid var(--line); border-radius: var(--radius); padding: 0.75rem 0.9rem; font-size: 0.875rem; }
.notice.error { border-color: #fecaca; background: var(--danger-soft); color: #991b1b; }
.notice.warning { border-color: #fde68a; background: var(--warning-soft); color: var(--warning); }
.notice.success { border-color: #a7f3d0; background: var(--success-soft); color: var(--success); }

/* Login and installer */
.login-body { background: var(--primary-deep); }
.login-layout { display: grid; min-height: 100vh; grid-template-columns: minmax(0, 1.15fr) minmax(28rem, 0.85fr); }
.login-intro { display: flex; flex-direction: column; justify-content: center; padding: clamp(3rem, 8vw, 8rem); color: #f5f3ff; }
.login-intro h1 { max-width: 15ch; margin: 2rem 0 1rem; color: #fff; font-size: 2.5rem; line-height: 1.15; letter-spacing: 0; text-wrap: balance; }
.login-intro > p:last-of-type { max-width: 55ch; margin: 0; color: #ddd6fe; line-height: 1.7; }
.login-points { display: grid; gap: 0.8rem; margin-top: 2rem; }
.login-points span { display: flex; align-items: center; gap: 0.75rem; color: #ede9fe; }
.login-points svg { color: #7dd3fc; }
.login-panel { display: flex; align-items: center; justify-content: center; background: var(--surface); padding: 2rem; }
.login-panel-inner { width: min(100%, 27rem); }
.login-panel h2 { margin: 1.25rem 0 0.25rem; font-size: 1.5rem; }
.login-panel p { margin: 0; color: var(--muted); }
.login-form, .install-form { display: grid; gap: 1rem; margin-top: 1.5rem; }

.install-body { display: grid; place-items: center; padding: 2rem; background: var(--surface); }
.install-shell { width: min(100%, 34rem); border: 1px solid var(--line); border-radius: 0.75rem; background: var(--panel); padding: 2rem; box-shadow: var(--shadow-md); }
.install-shell h1 { margin: 1.5rem 0 0.5rem; font-size: 1.5rem; }
.install-shell code { font-family: Consolas, monospace; font-size: 0.85em; }

/* Main application */
.app-body { overflow: hidden; }
.topbar {
  display: flex;
  height: 4.5rem;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid #4c1d68;
  background: var(--primary-deep);
  color: #fff;
  padding: 0 1rem;
}
.topbar-brand { display: flex; min-width: 14rem; align-items: center; gap: 0.75rem; }
.topbar-brand strong, .topbar-brand small { display: block; }
.topbar-brand strong { font-size: 0.95rem; }
.topbar-brand small { color: #d8b4fe; font-size: 0.75rem; font-weight: 400; }
.topbar-actions { display: flex; align-items: center; gap: 0.5rem; }
.server-state { display: inline-flex; align-items: center; gap: 0.45rem; border: 1px solid rgba(167,243,208,0.24); border-radius: 0.375rem; background: rgba(4,120,87,0.25); padding: 0.45rem 0.65rem; color: #d1fae5; font-size: 0.75rem; font-weight: 700; }
.account-summary { display: flex; align-items: center; gap: 0.6rem; margin-left: 0.25rem; padding-left: 0.75rem; border-left: 1px solid rgba(255,255,255,0.18); }
.account-summary strong, .account-summary small { display: block; max-width: 10rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-summary strong { font-size: 0.8rem; }
.account-summary small { color: #d8b4fe; font-size: 0.7rem; }
.account-avatar { display: inline-flex; width: 2.25rem; height: 2.25rem; align-items: center; justify-content: center; border-radius: 50%; background: #fff; color: var(--primary-deep); font-weight: 700; }
.topbar .icon-button { border-color: rgba(255,255,255,0.14); background: rgba(255,255,255,0.06); color: #ede9fe; }
.topbar .icon-button:hover { background: rgba(255,255,255,0.12); color: #fff; }

.app-layout { display: grid; height: calc(100vh - 4.5rem); grid-template-columns: 16rem 19rem minmax(0, 1fr); }
.project-pane, .context-pane, .workspace-pane { min-width: 0; overflow-y: auto; }
.project-pane { display: flex; flex-direction: column; border-right: 1px solid var(--line); background: #fbfafc; padding: 1rem 0.75rem 0; }
.context-pane { border-right: 1px solid var(--line); background: var(--panel); }
.workspace-pane { padding: 1.5rem clamp(1rem, 3vw, 3rem) 4rem; }

.pane-heading { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0 0.25rem 0.85rem; }
.pane-heading.compact { padding: 0; }
.pane-heading h2, .step-list-heading h2 { margin: 0.15rem 0 0; font-size: 1rem; }
.section-label { color: var(--subtle); font-size: 0.75rem; font-weight: 700; }

.search-field { position: relative; display: block; margin-bottom: 0.75rem; }
.search-field svg { position: absolute; left: 0.75rem; top: 0.8rem; z-index: 1; color: var(--subtle); pointer-events: none; }
.search-field input { padding-left: 2.35rem; background: var(--panel); font-size: 0.875rem; }

.project-list, .role-list { display: grid; gap: 0.25rem; }
.project-list { flex: 1; align-content: start; overflow-y: auto; padding-bottom: 1rem; }
.list-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  min-height: 3.5rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  padding: 0.55rem 0.65rem;
  text-align: left;
}
.list-item:hover { background: var(--panel); color: var(--ink); }
.list-item.active { border-color: #ddd6fe; background: var(--primary-soft); color: var(--primary-deep); }
.list-item .list-color { width: 0.65rem; height: 2rem; border-radius: 0.2rem; background: var(--item-color, var(--primary)); }
.list-item strong, .list-item small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item strong { font-size: 0.875rem; }
.list-item small { margin-top: 0.1rem; color: var(--subtle); font-size: 0.72rem; font-weight: 400; }
.list-item > svg { width: 0.9rem; color: var(--subtle); }
.pane-footer { border-top: 1px solid var(--line); padding: 0.75rem 0.25rem; color: var(--subtle); font-size: 0.75rem; }

.project-context { padding: 1.25rem; border-bottom: 1px solid var(--line); }
.context-title-row { display: grid; grid-template-columns: auto minmax(0,1fr) auto; align-items: start; gap: 0.75rem; }
.project-color { width: 0.75rem; height: 2.75rem; border-radius: 0.25rem; background: var(--primary); }
.context-title-row h2 { margin: 0.15rem 0 0; overflow-wrap: anywhere; font-size: 1.05rem; }
.context-actions { display: flex; gap: 0.25rem; }
.context-actions .icon-button { width: 2.25rem; min-height: 2.25rem; }
.context-description { margin: 0.9rem 0 0; color: var(--muted); font-size: 0.875rem; line-height: 1.65; }
.project-tools { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }
.role-section { padding: 1.25rem; }
.role-list { margin-top: 0.75rem; }
.role-row { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: 0.25rem; }
.role-row .compact { opacity: 0; }
.role-row:hover .compact, .role-row:focus-within .compact { opacity: 1; }
.role-list .list-item .role-icon { display: inline-flex; width: 2.25rem; height: 2.25rem; align-items: center; justify-content: center; border-radius: var(--radius); background: color-mix(in srgb, var(--item-color) 12%, white); color: var(--item-color); }
.inline-empty { margin: 0; border: 1px dashed var(--line); border-radius: var(--radius); padding: 1rem; color: var(--subtle); font-size: 0.8rem; text-align: center; }

.workspace-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding-bottom: 1.25rem; border-bottom: 1px solid var(--line); }
.workspace-heading { display: flex; min-width: 0; align-items: flex-start; gap: 0.9rem; }
.role-badge { display: inline-flex; width: 3rem; height: 3rem; align-items: center; justify-content: center; flex: 0 0 auto; border-radius: var(--radius); background: var(--role-color, var(--primary)); color: #fff; }
.workspace-heading h1 { margin: 0.35rem 0 0; font-size: 1.5rem; line-height: 1.25; overflow-wrap: anywhere; }
.workspace-heading p { max-width: 65ch; margin: 0.35rem 0 0; color: var(--muted); font-size: 0.875rem; line-height: 1.65; }
.breadcrumb { display: flex; align-items: center; gap: 0.3rem; color: var(--subtle); font-size: 0.75rem; font-weight: 700; }
.breadcrumb svg { width: 0.8rem; height: 0.8rem; }
.workspace-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.5rem; }

.journey-toolbar { display: flex; align-items: end; gap: 0.75rem; margin-top: 1.25rem; }
.journey-select-label { flex: 1; max-width: 42rem; }
.journey-select-label select { font-weight: 700; }
.reference-notice { display: flex; align-items: flex-start; gap: 0.7rem; margin-top: 1rem; border: 1px solid #bae6fd; border-radius: var(--radius); background: var(--info-soft); padding: 0.75rem 0.9rem; color: #075985; font-size: 0.875rem; }
.reference-notice svg { flex: 0 0 auto; margin-top: 0.15rem; }

.step-workspace { margin-top: 2rem; }
.step-list-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 0.75rem; }
.step-count { border-radius: 0.375rem; background: var(--panel-subtle); padding: 0.35rem 0.6rem; color: var(--muted); font-size: 0.75rem; font-weight: 700; }
.step-list { display: grid; gap: 0; margin: 0; padding: 0; list-style: none; }
.step-item-wrap { position: relative; padding-bottom: 1.75rem; }
.step-item-wrap:not(:last-child)::after { content: ''; position: absolute; left: 1.7rem; bottom: 0; width: 1px; height: 1.75rem; background: color-mix(in srgb, var(--role-color, var(--primary)) 35%, white); }
.step-card {
  display: grid;
  grid-template-columns: auto auto minmax(0,1fr) auto;
  align-items: start;
  gap: 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
  transition: border-color 180ms ease-out, box-shadow 180ms ease-out, opacity 180ms ease-out;
}
.step-card:hover { border-color: #d8d1e2; box-shadow: 0 6px 18px rgba(37,33,48,0.07); }
.step-item-wrap.dragging .step-card { opacity: 0.4; }
.step-item-wrap.drop-before .step-card { box-shadow: 0 -3px 0 var(--role-color, var(--primary)); }
.step-item-wrap.drop-after .step-card { box-shadow: 0 3px 0 var(--role-color, var(--primary)); }
.drag-handle { display: inline-flex; width: 2.75rem; height: 2.75rem; align-items: center; justify-content: center; border: 0; border-radius: var(--radius); background: var(--panel-subtle); color: var(--subtle); cursor: grab; }
.drag-handle:active { cursor: grabbing; }
.step-number { display: inline-flex; min-width: 1.75rem; height: 1.75rem; align-items: center; justify-content: center; border-radius: 0.375rem; background: var(--role-color, var(--primary)); color: #fff; font-size: 0.75rem; font-weight: 700; }
.step-title-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.55rem; }
.step-title-row h3 { margin: 0; font-size: 1rem; line-height: 1.35; overflow-wrap: anywhere; }
.owner-pill { display: inline-flex; align-items: center; gap: 0.3rem; border: 1px solid color-mix(in srgb, var(--role-color, var(--primary)) 25%, white); border-radius: 0.35rem; background: color-mix(in srgb, var(--role-color, var(--primary)) 8%, white); padding: 0.2rem 0.45rem; color: color-mix(in srgb, var(--role-color, var(--primary)) 75%, #111); font-size: 0.72rem; font-weight: 700; }
.owner-pill svg { width: 0.8rem; height: 0.8rem; }
.step-card p { margin: 0.55rem 0 0; color: var(--muted); font-size: 0.875rem; line-height: 1.65; }
.step-actions { display: flex; gap: 0.15rem; }
.step-actions .icon-button { width: 2.25rem; min-height: 2.25rem; border-color: transparent; box-shadow: none; }

.empty-state { min-height: 18rem; border: 1px dashed #cec8d5; border-radius: var(--radius); background: var(--panel); padding: 3rem 1rem; text-align: center; }
.empty-state .icon-shell { margin: 0 auto; }
.empty-state h2 { margin: 1rem 0 0; font-size: 1.1rem; }
.empty-state p { margin: 0.35rem auto 1.25rem; color: var(--muted); }
.mobile-context-selects { display: none; }

/* Dialogs */
.modal { width: min(calc(100% - 2rem), 34rem); max-height: calc(100vh - 2rem); margin: auto; border: 1px solid var(--line); border-radius: 0.75rem; background: var(--panel); color: var(--ink); padding: 0; box-shadow: var(--shadow-md); }
.modal.wide { width: min(calc(100% - 2rem), 58rem); }
.modal::backdrop { background: rgba(25, 18, 34, 0.56); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; border-bottom: 1px solid var(--line); padding: 1.25rem; }
.modal-title-group { display: flex; align-items: flex-start; gap: 0.75rem; }
.modal-title-group h2 { margin: 0; font-size: 1.15rem; }
.modal-title-group p { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.8rem; }
.modal-body { display: grid; gap: 1rem; padding: 1.25rem; overflow-y: auto; }
.modal-footer { display: flex; justify-content: flex-end; gap: 0.5rem; border-top: 1px solid var(--line); padding: 1rem 1.25rem; }
.modal-toolbar { border-bottom: 1px solid var(--line); padding: 0.75rem 1.25rem; }
.color-field { border: 0; margin: 0; padding: 0; }
.color-field legend { margin-bottom: 0.5rem; font-size: 0.875rem; font-weight: 700; }
.color-options { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.color-choice { display: inline-flex; min-width: 4.75rem; min-height: 2.75rem; align-items: center; gap: 0.5rem; border: 1px solid var(--line); border-radius: 0.375rem; padding: 0.5rem 0.65rem; font-size: 0.8rem; font-weight: 700; cursor: pointer; }
.color-choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-deep); }
.color-choice input { position: absolute; opacity: 0; pointer-events: none; }
.color-swatch { width: 0.9rem; height: 0.9rem; border-radius: 0.2rem; background: var(--swatch); }

.user-list, .audit-list { max-height: min(65vh, 38rem); overflow: auto; }
.user-row, .audit-row { display: grid; align-items: center; gap: 0.75rem; border-bottom: 1px solid var(--line); padding: 0.85rem 1.25rem; }
.user-row { grid-template-columns: auto minmax(0,1fr) auto auto auto; }
.user-row:last-child, .audit-row:last-child { border-bottom: 0; }
.user-avatar { display: inline-flex; width: 2.4rem; height: 2.4rem; align-items: center; justify-content: center; border-radius: var(--radius); background: var(--primary-soft); color: var(--primary-deep); font-size: 0.8rem; font-weight: 800; }
.user-copy strong, .user-copy span { display: block; }
.user-copy span { margin-top: 0.1rem; color: var(--muted); font-size: 0.78rem; }
.access-pill { border-radius: 0.35rem; background: var(--panel-subtle); padding: 0.3rem 0.55rem; color: var(--muted); font-size: 0.75rem; font-weight: 700; }
.access-pill.admin { background: var(--primary-soft); color: var(--primary-deep); }
.access-pill.editor { background: var(--info-soft); color: var(--info); }
.status-pill { border-radius: 0.35rem; padding: 0.3rem 0.55rem; font-size: 0.75rem; font-weight: 700; }
.status-pill.active { background: var(--success-soft); color: var(--success); }
.status-pill.inactive { background: var(--danger-soft); color: var(--danger); }
.row-actions { display: flex; gap: 0.2rem; }
.audit-row { grid-template-columns: auto minmax(0,1fr) auto; }
.audit-mark { display: inline-flex; width: 2rem; height: 2rem; align-items: center; justify-content: center; border-radius: var(--radius); background: var(--panel-subtle); color: var(--muted); }
.audit-row div strong, .audit-row div span { display: block; }
.audit-row div span { margin-top: 0.15rem; color: var(--muted); font-size: 0.78rem; }
.audit-row strong { font-size: 0.875rem; }
.audit-row p { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.78rem; }
.audit-row time { color: var(--subtle); font-size: 0.75rem; white-space: nowrap; }

.toast { position: fixed; right: 1rem; bottom: 1rem; z-index: 80; display: flex; max-width: min(24rem, calc(100% - 2rem)); align-items: center; gap: 0.65rem; border: 1px solid #a7f3d0; border-radius: var(--radius); background: var(--success-soft); color: var(--success); padding: 0.8rem 1rem; box-shadow: var(--shadow-md); font-size: 0.875rem; font-weight: 700; }
.toast.error { border-color: #fecaca; background: var(--danger-soft); color: var(--danger); }
.loading-overlay { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; background: rgba(247,247,250,0.7); }
.loading-overlay > div { display: flex; align-items: center; gap: 0.75rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 0.85rem 1rem; box-shadow: var(--shadow-md); }
.loading-overlay p { margin: 0; font-size: 0.875rem; font-weight: 700; }
.spinner { width: 1.1rem; height: 1.1rem; border: 2px solid #ddd6fe; border-top-color: var(--primary); border-radius: 50%; animation: spin 650ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

[hidden] { display: none !important; }

@media (max-width: 1100px) {
  .app-layout { grid-template-columns: 15rem minmax(0,1fr); }
  .context-pane { display: none; }
  .mobile-context-selects { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin-bottom: 1rem; }
}

@media (max-width: 760px) {
  .app-body { overflow: auto; }
  .topbar { height: auto; min-height: 4.5rem; align-items: flex-start; padding: 0.75rem; }
  .topbar-brand small, .server-state span, .icon-text-button span, .account-summary > span:last-child { display: none; }
  .topbar-brand { min-width: 0; }
  .topbar-actions { gap: 0.25rem; }
  .server-state, .icon-text-button { width: 2.75rem; min-height: 2.75rem; justify-content: center; padding: 0; }
  .account-summary { margin-left: 0; padding-left: 0; border-left: 0; }
  .app-layout { display: block; height: auto; }
  .project-pane { display: none; }
  .workspace-pane { min-height: calc(100vh - 4.5rem); overflow: visible; padding: 1rem 0.85rem 4rem; }
  .mobile-context-selects { grid-template-columns: 1fr; }
  .workspace-header { display: grid; }
  .workspace-actions { justify-content: flex-start; }
  .journey-toolbar { align-items: stretch; flex-wrap: wrap; }
  .journey-select-label { flex-basis: 100%; max-width: none; }
  .step-card { grid-template-columns: auto auto minmax(0,1fr); }
  .step-actions { grid-column: 3; justify-content: flex-end; }
  .step-item-wrap:not(:last-child)::after { left: 1.7rem; }
  .user-row { grid-template-columns: auto minmax(0,1fr) auto; }
  .user-row .access-pill { grid-column: 2; justify-self: start; }
  .user-row .status-pill { grid-column: 2; justify-self: start; }
  .user-row .row-actions { grid-column: 3; grid-row: 1 / span 3; }
  .audit-row { grid-template-columns: 1fr; }
  .login-layout { display: block; }
  .login-intro { min-height: 20rem; padding: 2rem 1.25rem; }
  .login-intro h1 { margin-top: 1.5rem; font-size: 2rem; }
  .login-points { display: none; }
  .login-panel { min-height: calc(100vh - 20rem); padding: 2rem 1.25rem; }
}

@media (max-width: 430px) {
  .topbar-brand strong { font-size: 0.8rem; }
  .topbar .brand-mark { width: 2.25rem; height: 2.25rem; }
  .account-avatar { width: 2.1rem; height: 2.1rem; }
  .workspace-heading { align-items: flex-start; }
  .role-badge { width: 2.75rem; height: 2.75rem; }
  .workspace-heading h1 { font-size: 1.25rem; }
  .workspace-actions .button { flex: 1; }
  .reference-notice { font-size: 0.8rem; }
  .step-card { padding: 0.75rem; gap: 0.65rem; }
  .drag-handle { width: 2.5rem; height: 2.5rem; }
  .step-title-row { align-items: flex-start; }
  .modal { width: calc(100% - 1rem); max-height: calc(100vh - 1rem); }
  .modal-footer .button { flex: 1; }
}

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

.projects-selection-field {
  display: grid;
  gap: 0.5rem;
}
.projects-selection-field > span {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--ink);
}
.projects-selection-field > span small {
  font-weight: 400;
  color: var(--muted);
}
.project-checkboxes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
  gap: 0.5rem;
  border: 1px solid var(--line);
  border-radius: 0.375rem;
  background: var(--panel);
  padding: 0.75rem;
  max-height: 10rem;
  overflow-y: auto;
}
.project-checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}
.project-checkbox-row input {
  width: 1.1rem;
  min-height: 1.1rem;
  accent-color: var(--primary);
  margin: 0;
  cursor: pointer;
}

@media print {
  .topbar, .project-pane, .context-pane, .workspace-actions, .journey-toolbar .button, .journey-toolbar .icon-button, .reference-notice, .step-actions, .drag-handle { display: none !important; }
  .app-body { overflow: visible; background: #fff; }
  .app-layout { display: block; height: auto; }
  .workspace-pane { overflow: visible; padding: 0; }
  .step-card { break-inside: avoid; box-shadow: none; }
}

/* Tabs for switching views */
.workspace-tabs {
  display: flex;
  background: var(--surface);
  padding: 4px;
  border-radius: 6px;
  border: 1px solid var(--line);
  margin-left: auto;
  margin-right: 1.5rem;
}
.tab-button {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.8rem;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 150ms ease-out;
}
.tab-button svg {
  width: 0.95rem;
  height: 0.95rem;
}
.tab-button.active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.tab-button:not(.active):hover {
  color: var(--ink);
}

/* Diagram View */
.diagram-wrapper {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  min-height: 25rem;
  display: block;
  position: relative;
  cursor: grab;
  user-select: none;
}
.diagram-wrapper:active {
  cursor: grabbing;
}
pre.mermaid {
  background: transparent;
  border: 0;
  padding: 0;
  margin: 0;
  font-family: inherit;
  font-size: 0.9rem;
  width: 100%;
  text-align: center;
}
pre.mermaid svg {
  width: 100% !important;
  max-width: 100% !important;
  height: auto !important;
}

/* Branch Editor inside the Dialog */
.step-branches-section {
  display: flex;
  flex-direction: column;
  margin-top: 1rem;
  gap: 0.5rem;
}
.branches-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.branches-header > span {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--ink);
}
.branches-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.branch-row {
  display: grid;
  grid-template-columns: 2.5fr 3.5fr auto;
  gap: 0.5rem;
  align-items: center;
}
.branch-row input {
  min-height: 2.25rem !important;
  font-size: 0.85rem;
  padding: 0.2rem 0.5rem;
}
.branch-row select {
  min-height: 2.25rem !important;
  font-size: 0.85rem;
}
.branch-row .button.danger {
  padding: 0;
  width: 2.25rem;
  height: 2.25rem;
  min-height: 2.25rem !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Jump links in step card */
.step-branch-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.65rem;
  border-top: 1px dashed var(--line);
  padding-top: 0.65rem;
  grid-column: 3;
}
.branch-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 120ms ease-out;
}
.branch-pill:hover {
  border-color: var(--role-color, var(--primary));
  background: var(--panel-subtle);
  color: var(--role-color, var(--primary));
}
.branch-pill svg {
  width: 0.85rem;
  height: 0.85rem;
}

/* Responsive adjustment for tabs */
@media (max-width: 768px) {
  .step-list-heading {
    flex-wrap: wrap;
    gap: 0.75rem;
  }
  .workspace-tabs {
    margin-left: 0;
    margin-right: 0;
    width: 100%;
  }
  .tab-button {
    flex: 1;
    justify-content: center;
  }
  .step-branch-pills {
    grid-column: 1 / span 3;
  }
}

