:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --panel-strong: #f8fafc;
  --text: #172033;
  --muted: #697386;
  --line: #d9dee8;
  --accent: #2f6fed;
  --accent-strong: #1f56c5;
  --success: #00a676;
  --danger: #d92d20;
  --warning: #b7791f;
  --shadow: 0 12px 40px rgba(23, 32, 51, 0.12);
  color-scheme: light;
}

body[data-theme="dark"] {
  --bg: #10131a;
  --panel: #171b24;
  --panel-strong: #1f2530;
  --text: #eef2f8;
  --muted: #a2adbe;
  --line: #2d3544;
  --accent: #6ea0ff;
  --accent-strong: #9bbcff;
  --success: #33c58b;
  --danger: #ff6b5f;
  --warning: #f0b45d;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
  overflow: hidden;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
textarea:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.is-hidden {
  display: none !important;
}

.auth-shell {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    linear-gradient(135deg, rgba(47, 111, 237, 0.12), transparent 36%),
    linear-gradient(315deg, rgba(0, 166, 118, 0.12), transparent 42%),
    var(--bg);
}

.auth-panel {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 32px;
}

.brand-mark,
.brand-pill {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--text);
  color: var(--panel);
  font-weight: 800;
}

.brand-pill {
  width: 34px;
  height: 34px;
  font-size: 13px;
}

.auth-panel h1 {
  margin: 18px 0 8px;
  font-size: 28px;
  line-height: 1.2;
}

.auth-panel p {
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.65;
}

.auth-tabs,
.segmented {
  display: inline-flex;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}

.auth-tab,
.segmented button {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  padding: 8px 14px;
}

.auth-tab.is-active,
.segmented button.is-active {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1px 5px rgba(23, 32, 51, 0.12);
}

.auth-form {
  display: grid;
  gap: 15px;
  margin-top: 20px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 10px 11px;
  outline: 0;
}

textarea {
  resize: vertical;
  min-height: 78px;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.15);
}

.primary-btn,
.secondary-btn,
.tool-btn,
.icon-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  min-height: 36px;
}

.primary-btn {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  padding: 11px 14px;
}

.secondary-btn,
.tool-btn {
  padding: 8px 12px;
}

.secondary-btn {
  background: var(--panel-strong);
}

.tool-btn.danger {
  color: var(--danger);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  font-weight: 800;
}

.app-shell {
  height: 100%;
  display: grid;
  grid-template-rows: 58px 1fr;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 10px 14px;
}

.topbar-left,
.topbar-actions,
.canvas-toolbar {
  display: flex;
  align-items: center;
  gap: 9px;
}

.topbar-left {
  min-width: 0;
  flex: 1;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.map-title-input {
  max-width: 360px;
  min-width: 160px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 18px;
  font-weight: 750;
  padding: 7px 8px;
}

.save-state,
.muted {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 260px minmax(380px, 1fr) 318px;
}

.dashboard-view,
.admin-view {
  min-height: 0;
  overflow: auto;
  padding: 24px;
}

.dashboard-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin: 0 auto 18px;
  max-width: 1180px;
}

.dashboard-head h1 {
  margin: 0 0 8px;
  font-size: 28px;
  line-height: 1.2;
}

.dashboard-head p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.dashboard-tools {
  max-width: 1180px;
  margin: 0 auto 16px;
}

.dashboard-tools .compact-input {
  max-width: 360px;
}

.map-card-grid {
  max-width: 1180px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.map-card,
.dashboard-empty,
.admin-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(23, 32, 51, 0.08);
}

.map-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  min-height: 210px;
}

.map-card-top,
.map-card-actions,
.map-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.map-card h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.35;
}

.map-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
  min-height: 48px;
}

.map-card-meta {
  justify-content: flex-start;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.dashboard-empty {
  grid-column: 1 / -1;
  padding: 32px;
  text-align: center;
}

.dashboard-empty h2 {
  margin: 0 0 8px;
}

.dashboard-empty p {
  margin: 0;
  color: var(--muted);
}

.admin-layout {
  max-width: 1180px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(360px, 1fr) 360px;
  gap: 16px;
}

.admin-card {
  padding: 16px;
}

.user-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 250px);
  overflow: auto;
}

.user-row {
  width: 100%;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--text);
  padding: 10px;
  text-align: left;
}

.user-row strong,
.user-row small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-row small {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.avatar-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
}

.sidebar,
.inspector {
  min-height: 0;
  overflow: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.inspector {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.sidebar-section {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.section-head h2 {
  margin: 0;
  font-size: 14px;
  line-height: 1.3;
}

.compact-input,
.canvas-search {
  min-height: 36px;
  padding: 8px 10px;
}

.mindmap-list,
.mini-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.map-item,
.mini-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  padding: 10px;
}

.map-item {
  cursor: pointer;
}

.map-item.is-active {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.map-item-title {
  color: var(--text);
  font-weight: 700;
  margin-bottom: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.map-item-meta,
.mini-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.role-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  background: rgba(47, 111, 237, 0.12);
  color: var(--accent-strong);
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
}

.invite-form,
.comment-form,
.node-form {
  display: grid;
  gap: 10px;
}

.canvas-column {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 52px 1fr;
}

.canvas-toolbar {
  min-width: 0;
  overflow-x: auto;
  padding: 8px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.canvas-search {
  width: min(260px, 30vw);
}

.canvas-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px),
    var(--bg);
  background-size: 36px 36px;
}

.mindmap-svg,
.three-stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.three-stage canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.empty-state,
.loading-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 5;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

.empty-state h2 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 20px;
}

.empty-state p {
  margin: 0;
}

.loading-overlay {
  background: rgba(255, 255, 255, 0.62);
  backdrop-filter: blur(2px);
  pointer-events: auto;
}

body[data-theme="dark"] .loading-overlay {
  background: rgba(16, 19, 26, 0.62);
}

.node-form span,
.comment-form span {
  font-size: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: 86px 1fr;
  gap: 10px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-row input {
  width: auto;
}

.comment-form textarea {
  min-height: 70px;
}

.mini-item strong {
  display: block;
  color: var(--text);
  font-size: 13px;
  margin-bottom: 4px;
}

.history-list .mini-item {
  font-size: 12px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  display: grid;
  gap: 8px;
}

.toast-message {
  max-width: min(420px, calc(100vw - 36px));
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 11px 13px;
  font-size: 13px;
}

.toast-message.error {
  border-left-color: var(--danger);
}

.toast-message.success {
  border-left-color: var(--success);
}

.mindmap-link {
  fill: none;
  stroke: rgba(105, 115, 134, 0.38);
  stroke-width: 2.2;
}

.mindmap-node {
  cursor: grab;
}

.mindmap-node.is-dragging {
  cursor: grabbing;
}

.mindmap-node rect {
  fill: var(--panel);
  stroke: var(--line);
  stroke-width: 1.2;
  filter: drop-shadow(0 6px 12px rgba(23, 32, 51, 0.12));
}

.mindmap-node.is-selected rect {
  stroke: var(--accent);
  stroke-width: 2.4;
}

.mindmap-node.is-match rect {
  stroke: var(--warning);
  stroke-width: 2;
}

.node-title {
  fill: var(--text);
  font-size: 14px;
  font-weight: 720;
  pointer-events: none;
}

.node-sub {
  fill: var(--muted);
  font-size: 11px;
  pointer-events: none;
}

.collapse-dot {
  cursor: pointer;
}

.collapse-dot circle {
  fill: var(--panel);
  stroke: var(--accent);
}

.collapse-dot text {
  fill: var(--accent);
  font-weight: 800;
  font-size: 12px;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

@media (max-width: 1080px) {
  body {
    overflow: auto;
  }

  .app-shell {
    min-height: 100vh;
    height: auto;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto 70vh auto;
  }

  .sidebar,
  .inspector {
    border: 0;
    border-bottom: 1px solid var(--line);
    max-height: none;
  }

  .canvas-column {
    min-height: 70vh;
  }

  .map-title-input {
    max-width: 100%;
  }

  .admin-layout {
    grid-template-columns: 1fr;
  }

  .dashboard-head {
    flex-direction: column;
  }
}

@media (max-width: 620px) {
  .auth-panel {
    padding: 22px;
  }

  .topbar-actions,
  .canvas-toolbar {
    width: 100%;
  }

  .canvas-search {
    min-width: 180px;
    flex: 1;
  }

  .tool-btn {
    padding: 7px 9px;
  }
}
