:root {
  --bg: #f5f7fa;
  --bar-bg: #ffffff;
  --bar-border: #eeeeee;
  --text: #1b1b1f;
  --text-dim: #6c6c7a;
  --btn-bg: #ffffff;
  --btn-hover: #f4f7fa;
  --btn-active: #e9eef5;
  --accent: #0989E2;
  --accent-text: #ffffff;
  --panel-bg: #ffffff;
  --panel-border: #eeeeee;
  --panel-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
  --ok: #197f45;
  --pending: #b8860b;
  --radius: 8px;
}

html[data-theme="dark"] {
  --bg: #121216;
  --bar-bg: #1e1e24;
  --bar-border: #313036;
  --text: #e6e6ea;
  --text-dim: #9a9aa5;
  --btn-bg: #26262c;
  --btn-hover: #313038;
  --btn-active: #3a3a43;
  --accent: #35a7d6;
  --accent-text: #ffffff;
  --panel-bg: #232329;
  --panel-border: #3a3a45;
  --panel-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  --ok: #5ec98a;
  --pending: #d9b04c;
}

/* 覆盖 Excalidraw 内部品牌色（默认紫 #6965db）：统一为站点品牌蓝。
   用 !important 压过运行时注入的样式表；暗色由 html[data-theme] 分支接管 */
.excalidraw {
  --color-primary: #0989E2 !important;
  --color-primary-darker: #2f5a8c !important;
  --color-primary-darkest: #254a73 !important;
  --color-primary-light: rgba(9,137,226, 0.3) !important;
  --color-primary-light-darker: rgba(9,137,226, 0.45) !important;
  --color-brand-hover: #2f5a8c !important;
  --color-brand-active: #254a73 !important;
  --color-selection: rgba(9,137,226, 0.35) !important;
  --color-promo: #0989E2 !important;
}
html[data-theme="dark"] .excalidraw {
  --color-primary: #35a7d6 !important;
  --color-primary-darker: #2b89ad !important;
  --color-primary-darkest: #236e8c !important;
  --color-primary-light: rgba(53, 167, 214, 0.3) !important;
  --color-primary-light-darker: rgba(53, 167, 214, 0.45) !important;
  --color-brand-hover: #2b89ad !important;
  --color-brand-active: #236e8c !important;
  --color-selection: rgba(53, 167, 214, 0.4) !important;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ---------- 顶部工具栏 ---------- */
.app-bar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 12px;
  height: 48px;
  padding: 0 12px;
  background: var(--bar-bg);
  border-bottom: 1px solid var(--bar-border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand__logo {
  display: block;
  width: 24px;
  height: 24px;
  object-fit: contain;
  border-radius: 6px;
}

.brand__name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
}

/* 返回「更多工具」快捷入口 */
.brand__back {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 4px;
  height: 26px;
  margin-left: 4px;
  padding: 0 10px;
  color: var(--text-dim);
  background: var(--btn-bg);
  border: 1px solid var(--bar-border);
  border-radius: 13px;
  font-size: 12px;
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.brand__back:hover {
  color: var(--accent);
  background: var(--btn-hover);
  border-color: var(--accent);
}

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

.doc {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin-left: 4px;
}

.doc__name {
  width: 160px;
  max-width: 30vw;
  padding: 4px 8px;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font: inherit;
  outline: none;
}

.doc__name:hover {
  background: var(--btn-hover);
}

.doc__name:focus {
  background: var(--btn-bg);
  border-color: var(--accent);
}

.doc__state {
  flex: 0 0 auto;
  color: var(--text-dim);
  font-size: 12px;
  white-space: nowrap;
}

.doc__state[data-state="dirty"] {
  color: var(--pending);
}

.doc__state[data-state="saved"] {
  color: var(--ok);
}

.actions {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.actions__sep {
  width: 1px;
  height: 22px;
  margin: 0 4px;
  background: var(--bar-border);
}

.btn,
.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 32px;
  padding: 0 10px;
  color: var(--text);
  background: var(--btn-bg);
  border: 1px solid var(--bar-border);
  border-radius: var(--radius);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.btn:hover,
.icon-btn:hover {
  background: var(--btn-hover);
}

.btn:active,
.icon-btn:active {
  background: var(--btn-active);
}

.btn--primary {
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
}

.btn--primary:hover {
  filter: brightness(1.05);
  background: var(--accent);
}

.btn--caret svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.icon-btn {
  justify-content: center;
  width: 32px;
  padding: 0;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn svg .solid {
  fill: currentColor;
  stroke: none;
}

/* ---------- 下拉菜单 ---------- */
.dropdown {
  position: relative;
}

.dropdown__panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  min-width: 200px;
  padding: 6px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--panel-shadow);
}

.dropdown__panel[hidden] {
  display: none;
}

.dropdown__item {
  display: block;
  width: 100%;
  padding: 7px 10px;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 6px;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.dropdown__item:hover {
  background: var(--btn-hover);
}

.dropdown__sep {
  height: 1px;
  margin: 5px 4px;
  background: var(--bar-border);
}

/* ---------- 画布 ---------- */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.stage__canvas {
  position: absolute;
  inset: 0;
}

.stage__canvas .excalidraw {
  border-radius: 0;
}

.stage__canvas :focus {
  outline: none;
}

/* ---------- 主体：画布 + 侧边栏 ---------- */
.body {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex: 0 0 296px;
  flex-direction: column;
  width: 296px;
  background: var(--bar-bg);
  border-right: 1px solid var(--bar-border);
  transition: margin-left 0.18s ease;
}

.app.is-collapsed .sidebar {
  margin-left: -296px;
}

.sidebar__tools {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 4px;
}

.search {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}

.search__icon {
  position: absolute;
  top: 50%;
  left: 9px;
  width: 14px;
  height: 14px;
  fill: none;
  stroke: var(--text-dim);
  stroke-width: 2;
  stroke-linecap: round;
  transform: translateY(-50%);
  pointer-events: none;
}

.search__input {
  width: 100%;
  height: 32px;
  padding: 0 10px 0 28px;
  color: var(--text);
  background: var(--btn-bg);
  border: 1px solid var(--bar-border);
  border-radius: var(--radius);
  font: inherit;
  outline: none;
}

.search__input:focus {
  border-color: var(--accent);
}

.search__input::-webkit-search-cancel-button {
  cursor: pointer;
}

.sidebar__label {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  padding: 4px 12px 6px;
  color: var(--text-dim);
  font-size: 12px;
}

.badge {
  min-width: 18px;
  padding: 1px 6px;
  color: var(--accent);
  background: var(--btn-active);
  border-radius: 999px;
  font-size: 11px;
  text-align: center;
}

.sidebar__list {
  flex: 1 1 auto;
  padding: 0 12px 8px;
  overflow-y: auto;
}

.hist-empty {
  margin: 18px 0;
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
}

.hist-item {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-bottom: 4px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.hist-item:hover {
  background: var(--btn-hover);
  border-color: var(--bar-border);
}

.hist-item.is-active {
  background: var(--btn-active);
  border-color: var(--accent);
}

.hist-item__open {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  padding: 8px 6px 8px 10px;
  color: inherit;
  background: transparent;
  border: 0;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.hist-item__name {
  display: block;
  overflow: hidden;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.hist-item__meta {
  display: block;
  margin-top: 2px;
  color: var(--text-dim);
  font-size: 11px;
}

.hist-item__del {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  color: var(--text-dim);
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.hist-item__del svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.hist-item__del:hover {
  color: #e03131;
  background: rgba(224, 49, 49, 0.12);
}

.sidebar__foot {
  flex: 0 0 auto;
  padding: 10px 12px;
  border-top: 1px solid var(--bar-border);
  color: var(--text-dim);
  font-size: 11px;
  line-height: 1.7;
}

.sidebar__foot p {
  margin: 0;
}

.sidebar__copy a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dashed var(--bar-border);
}

.sidebar__copy a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}


/* ---------- 底部状态栏 ---------- */
.status-bar {
  position: relative;
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 28px;
  padding: 0 12px;
  color: var(--text-dim);
  background: var(--bar-bg);
  border-top: 1px solid var(--bar-border);
  font-size: 12px;
  overflow: hidden;
  white-space: nowrap;
}

.status-bar__left {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
}

/* 备案信息较长，这里不再绝对居中，改由弹性布局分配空间，避免与左右两侧文字重叠 */
.status-bar__center {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
}

.status-bar__center a {
  color: var(--accent);
  text-decoration: none;
}

.status-bar__center a:hover {
  text-decoration: underline;
}

/* 备案信息：内容来自后台“网站版权信息”，可能自带内联样式（如 color:#FFF），这里统一跟随状态栏配色，保证深浅色主题下均可见 */
.status-bar__icp {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 后台“移动端版权信息”里带有 <br/>，状态栏是单行，这里忽略换行 */
.status-bar__icp br {
  display: none;
}

.status-bar__icp,
.status-bar__icp a {
  color: var(--text-dim) !important;
  text-decoration: none !important;
}

.status-bar__icp a:hover {
  color: var(--accent) !important;
  text-decoration: underline !important;
}

.status-bar__right {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 窄屏优先保证备案信息完整可见，右侧快捷键提示隐藏（快捷键弹窗里同样可以看到） */
@media (max-width: 1500px) {
  .status-bar__right {
    display: none;
  }
}

.dot {
  width: 3px;
  height: 3px;
  background: var(--text-dim);
  border-radius: 50%;
}

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal[hidden] {
  display: none;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

.modal__dialog {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(880px, 92vw);
  max-height: 86vh;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: var(--panel-shadow);
  overflow: hidden;
}

.modal__dialog--slim {
  width: min(560px, 92vw);
}

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--bar-border);
}

.modal__title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.modal__tabs {
  display: flex;
  gap: 4px;
  padding: 10px 16px 0;
}

.tab {
  padding: 6px 12px;
  color: var(--text-dim);
  background: transparent;
  border: 0;
  border-radius: 6px 6px 0 0;
  font: inherit;
  cursor: pointer;
}

.tab:hover {
  background: var(--btn-hover);
}

.tab.is-active {
  color: var(--text);
  background: var(--btn-active);
  font-weight: 600;
}

.modal__body {
  flex: 1 1 auto;
  padding: 14px 16px;
  overflow: auto;
}

.modal__foot {
  padding: 10px 16px;
  color: var(--text-dim);
  background: var(--bar-bg);
  border-top: 1px solid var(--bar-border);
  font-size: 12px;
}

.lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.lib-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 10px;
  color: var(--text);
  background: var(--btn-bg);
  border: 1px solid var(--bar-border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.12s ease, transform 0.12s ease;
}

.lib-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.lib-card__preview {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 96px;
  overflow: hidden;
}

.lib-card__preview svg {
  max-width: 100%;
  max-height: 96px;
}

.lib-card__preview .empty {
  color: var(--text-dim);
  font-size: 12px;
}

.lib-card__name {
  font-size: 13px;
  text-align: center;
}

.shortcut-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.shortcut-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--bar-border);
}

.shortcut-list li:last-child {
  border-bottom: 0;
}

.shortcut-list span {
  margin-left: auto;
  color: var(--text-dim);
  text-align: right;
}

kbd {
  min-width: 22px;
  padding: 2px 6px;
  color: var(--text);
  background: var(--btn-bg);
  border: 1px solid var(--bar-border);
  border-bottom-width: 2px;
  border-radius: 5px;
  font-family: inherit;
  font-size: 12px;
  text-align: center;
}

/* ---------- 提示条 ---------- */
.toast-wrap {
  position: fixed;
  bottom: 46px;
  left: 50%;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  padding: 8px 14px;
  color: var(--text);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  box-shadow: var(--panel-shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.is-in {
  opacity: 1;
  transform: translateY(0);
}

.toast[data-kind="error"] {
  border-color: #e03131;
  color: #e03131;
}

@media (max-width: 860px) {
  .brand__name,
  .status-bar__right {
    display: none;
  }

  .doc__name {
    width: 110px;
  }
}

@media (max-width: 720px) {
  .status-bar__left {
    display: none;
  }

  /* 窄屏只保留返回图标，避免挤压文件名输入框 */
  .brand__back-text {
    display: none;
  }

  .sidebar {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 40;
    box-shadow: var(--panel-shadow);
  }
}

