:root {
  --bg: #eef3ef;
  --surface: #ffffff;
  --surface-soft: #f7faf8;
  --surface-strong: #ffffff;
  --ink: #1f2d29;
  --muted: #64736d;
  --line: #d8e4dd;
  --soft-line: #e8efe9;
  --sage: #2f735c;
  --sage-deep: #245b49;
  --green: #2f735c;
  --blue: #3c6f96;
  --amber: #a66f2a;
  --red: #a85047;
  --shadow: 0 18px 42px rgba(31, 45, 41, 0.09);
  color-scheme: light;
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

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

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(47, 115, 92, 0.28);
  outline-offset: 2px;
}

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: 100vh;
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--sage-deep);
  color: #fff;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.role-picker,
.filter-stack label,
.editor-fields label,
.search-field,
.floating-brush-toolbar label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--ink);
}

input,
select {
  min-height: 38px;
  padding: 0 10px;
}

.primary-action,
.secondary-action,
.nav-item,
.command-bar button,
.icon-button,
.mobile-bar button,
.linked-card button,
.brush-tools button,
.brush-actions button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
}

.primary-action,
.secondary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: var(--sage-deep);
  color: #fff;
  border-color: var(--sage-deep);
  font-weight: 800;
}

.secondary-action {
  width: auto;
  min-height: 36px;
  padding: 0 12px;
}

.nav-list {
  display: grid;
  gap: 7px;
}

.nav-item {
  padding: 0 12px;
  text-align: left;
}

.nav-item.is-active {
  border-color: #bfd8cc;
  background: #e5f1eb;
  color: var(--sage-deep);
  font-weight: 800;
}

.role-summary.compact {
  margin-top: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.role-summary h2,
.role-template-panel h2,
.quick-panel h2,
.module-card h2 {
  margin: 0;
  font-size: 19px;
}

.role-summary p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.65;
}

.mini-stats,
.template-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.mini-stats span,
.pill,
.mini-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border: 1px solid #c8dbd1;
  border-radius: 999px;
  background: #eef7f2;
  color: var(--sage-deep);
  font-size: 12px;
  font-weight: 800;
}

.main-area {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 520px);
  gap: 18px;
  align-items: stretch;
  margin-bottom: 18px;
}

.topbar-copy,
.topbar-tools,
.note-column,
.editor-column,
.context-column > section,
.module-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 10px 28px rgba(31, 45, 41, 0.04);
}

.topbar-copy {
  padding: 18px;
}

.topbar-tools {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.sync-status {
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid #c8dbd1;
  border-radius: 8px;
  background: #eef7f2;
  color: var(--sage-deep);
  font-size: 13px;
  font-weight: 800;
}

.sync-status[data-tone="syncing"] {
  border-color: #c8d6e3;
  background: #f0f6fb;
  color: var(--blue);
}

.sync-status[data-tone="error"] {
  border-color: #e1b8b2;
  background: #fff3ef;
  color: var(--red);
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--sage-deep);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: 30px;
  line-height: 1.18;
}

h3 {
  margin-bottom: 8px;
  font-size: 16px;
}

.topbar-copy p:last-child {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.7;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.status-strip div {
  min-height: 74px;
  padding: 12px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.status-strip strong,
.status-strip small {
  display: block;
}

.status-strip strong {
  font-size: 23px;
}

.status-strip small {
  margin-top: 6px;
  color: var(--muted);
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(270px, 330px) minmax(420px, 1fr) minmax(260px, 330px);
  gap: 16px;
  min-height: min(760px, calc(100vh - 178px));
}

.note-column,
.editor-column,
.context-column {
  min-height: 0;
}

.note-column {
  display: flex;
  overflow: hidden;
  flex-direction: column;
}

.filter-stack {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--soft-line);
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.filter-row button {
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid #c9ddd2;
  border-radius: 999px;
  background: #edf7f1;
  color: var(--sage-deep);
  font-size: 12px;
  font-weight: 800;
}

.filter-row button.is-active {
  background: var(--sage-deep);
  color: #fff;
}

.note-list {
  display: grid;
  gap: 8px;
  min-height: 0;
  padding: 12px;
  overflow: auto;
}

.note-card {
  display: grid;
  gap: 8px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: #fff;
  text-align: left;
}

.note-card.is-selected {
  border-color: var(--sage);
  box-shadow: inset 4px 0 0 var(--sage);
}

.note-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.note-card strong {
  overflow-wrap: anywhere;
}

.note-card p {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  line-height: 1.5;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.note-card footer,
.linked-card footer {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.editor-column {
  display: grid;
  grid-template-rows: auto auto auto minmax(260px, 1fr);
  overflow: hidden;
}

.editor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  border-bottom: 1px solid var(--soft-line);
}

.editor-meta {
  max-width: 280px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  text-align: right;
}

.editor-fields {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) minmax(130px, 0.8fr) 120px 120px;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--soft-line);
  background: #fbfdfb;
}

.editor-fields .wide-field {
  grid-column: 1 / -1;
}

.command-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--soft-line);
  background: #f8fbf9;
}

.command-bar button {
  padding: 0 10px;
  color: var(--sage-deep);
  font-weight: 800;
}

.command-bar .danger,
.linked-card .danger {
  border-color: #dfb4ad;
  background: #fff3ef;
  color: var(--red);
}

.command-bar button.is-active {
  border-color: var(--sage);
  background: #dff0e8;
}

.drawing-board {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #fffefb;
}

.drawing-board.is-drawing {
  background:
    linear-gradient(rgba(47, 115, 92, 0.12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(47, 115, 92, 0.12) 1px, transparent 1px),
    #fffefb;
  background-size: 26px 26px;
  box-shadow: inset 0 0 0 2px rgba(47, 115, 92, 0.22);
}

.brush-mode-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 4;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(248, 252, 249, 0.94);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  pointer-events: none;
}

.drawing-board.is-drawing .brush-mode-badge {
  border-color: var(--sage);
  background: rgba(223, 240, 232, 0.94);
  color: var(--sage-deep);
}

#noteEditor {
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 46px 18px 18px;
  border: 0;
  resize: none;
  background: transparent;
  color: var(--ink);
  line-height: 1.8;
}

#handwritingCanvas {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  pointer-events: none;
  touch-action: none;
}

.drawing-board.is-drawing #handwritingCanvas {
  pointer-events: auto;
  cursor: crosshair;
}

.context-column {
  display: grid;
  gap: 16px;
  align-content: start;
}

.context-column > section,
.module-card {
  padding: 14px;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.role-template-panel p,
.ai-warning,
.ai-suggestion,
.export-bundle,
.linked-card p,
.empty-state {
  color: var(--muted);
  line-height: 1.65;
}

.ai-warning {
  margin-bottom: 10px;
  color: var(--red);
  font-weight: 800;
}

.view-panel {
  display: none !important;
}

.workspace-grid.view-panel.is-visible,
.relationship-grid.view-panel.is-visible {
  display: grid !important;
}

.module-view.view-panel.is-visible:not(.relationship-grid) {
  display: block !important;
}

.relationship-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.module-view {
  min-height: min(720px, calc(100vh - 178px));
}

.module-card {
  min-height: 520px;
}

.linked-list {
  display: grid;
  gap: 10px;
}

.linked-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: #fcfffd;
}

.linked-card button {
  padding: 0 10px;
  font-weight: 800;
}

.map-canvas {
  position: relative;
  min-height: 360px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(var(--soft-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--soft-line) 1px, transparent 1px),
    #fff;
  background-size: 34px 34px;
}

.map-node {
  position: absolute;
  display: grid;
  place-items: center;
  width: 136px;
  min-height: 58px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  text-align: center;
  font-size: 13px;
  font-weight: 800;
}

.map-node.core {
  width: 160px;
  min-height: 72px;
  background: var(--sage-deep);
  color: #fff;
}

.map-node.role {
  color: var(--sage-deep);
}

.map-node.blue {
  color: var(--blue);
}

.map-node.amber {
  color: var(--amber);
}

.map-node.green {
  color: var(--green);
}

.map-line {
  position: absolute;
  height: 2px;
  transform-origin: left center;
  background: #b8d6c6;
}

.export-bundle ul,
.ai-suggestion ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.settings-grid {
  display: grid;
  gap: 10px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  font-size: 18px;
}

.floating-brush-toolbar {
  position: fixed;
  right: 24px;
  bottom: 92px;
  z-index: 50;
  display: grid;
  width: min(292px, calc(100vw - 28px));
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 251, 0.98);
  box-shadow: 0 24px 60px rgba(34, 86, 67, 0.22);
}

.floating-brush-toolbar[hidden] {
  display: none;
}

.floating-brush-toolbar.is-visible {
  display: grid;
}

.brush-handle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  background: var(--sage-deep);
  color: #fff;
  cursor: move;
  user-select: none;
}

.brush-handle span {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  font-size: 12px;
}

.brush-tools {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.brush-tools button,
.brush-actions button {
  min-height: 34px;
  background: var(--surface-soft);
  color: var(--sage-deep);
  font-weight: 800;
}

.brush-tools button.is-active {
  border-color: var(--sage);
  background: #dff0e8;
}

.floating-brush-toolbar input,
.floating-brush-toolbar select {
  width: 100%;
  min-height: 36px;
}

.floating-brush-toolbar input[type="color"] {
  padding: 3px;
}

.floating-brush-toolbar input[type="range"] {
  padding: 0;
}

.brush-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mobile-bar {
  display: none;
}

@media (max-width: 1280px) {
  .app-shell,
  .connected-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-list {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .role-summary.compact {
    margin-top: 0;
  }
}

@media (max-width: 1080px) {
  .topbar,
  .workspace-grid,
  .relationship-grid {
    grid-template-columns: 1fr;
  }

  .workspace-grid {
    min-height: 0;
  }

  .editor-column {
    min-height: 660px;
  }

  .context-column {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 880px) {
  .app-shell,
  .connected-shell {
    padding-bottom: 74px;
  }

  .main-area,
  .sidebar {
    padding: 16px;
  }

  .nav-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .topbar-tools,
  .status-strip,
  .context-column,
  .editor-fields {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 24px;
  }

  .editor-head {
    display: grid;
  }

  .editor-meta {
    max-width: none;
    text-align: left;
  }

  .command-bar {
    max-height: 154px;
    overflow: auto;
  }

  .floating-brush-toolbar {
    right: 10px;
    bottom: 78px;
  }

  .mobile-bar {
    position: fixed;
    right: 12px;
    bottom: 12px;
    left: 12px;
    z-index: 10;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: var(--shadow);
  }

  .mobile-bar button {
    min-height: 42px;
    padding: 0 4px;
    font-size: 12px;
  }
}
