:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f7f9fb;
  --ink: #1f2630;
  --muted: #697383;
  --line: #e4e8ee;
  --line-strong: #cfd7e2;
  --accent: #256f68;
  --accent-ink: #ffffff;
  --accent-soft: #e7f4f1;
  --warm: #9d5d26;
  --danger: #b42318;
  --shadow: 0 16px 36px rgba(28, 39, 53, 0.12);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--ink);
}

[hidden] {
  display: none !important;
}

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

button {
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, opacity 140ms ease;
}

.boot-screen,
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.boot-screen {
  align-content: center;
  gap: 14px;
  color: var(--muted);
}

.pulse {
  width: 40px;
  height: 40px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

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

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

.login-brand {
  margin-bottom: 28px;
}

.brand-mark {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #ffffff;
  font-weight: 800;
  letter-spacing: 0;
}

.login-brand h1,
.brand h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
}

.login-brand p,
.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 13px;
}

.field input,
.search-box input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  outline: none;
}

.field input {
  padding: 0 12px;
}

.field input:focus,
.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(40, 124, 121, 0.16);
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 700;
  white-space: nowrap;
}

.icon-button {
  width: 36px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-color: var(--line-strong);
  background: var(--panel);
  color: var(--ink);
  font-size: 19px;
  line-height: 1;
}

.compact-button {
  min-height: 36px;
  padding: 0 12px;
}

.action-button {
  width: auto;
}

.primary-button {
  width: 100%;
  background: var(--accent);
  color: var(--accent-ink);
}

.wide-button {
  width: 100%;
  margin-bottom: 12px;
}

.secondary-button {
  background: #f8fafc;
  border-color: var(--line-strong);
  color: var(--ink);
}

.danger-button {
  background: #fff5f2;
  border-color: #ffc9bd;
  color: var(--danger);
}

.primary-button:disabled,
.secondary-button:disabled,
.danger-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.error-text {
  min-height: 20px;
  margin: 0 0 14px;
  color: var(--danger);
  font-size: 13px;
}

.demo-warning {
  margin: 14px 0 0;
  color: var(--warm);
  font-size: 13px;
}

.totp-setup {
  display: grid;
  justify-items: center;
  gap: 10px;
  margin: 10px 0 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  text-align: center;
}

.totp-setup p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.totp-setup img {
  width: min(220px, 100%);
  height: auto;
  border: 8px solid #ffffff;
  border-radius: 8px;
  background: #ffffff;
}

.manual-secret {
  width: 100%;
  overflow-wrap: anywhere;
}

.manual-secret span {
  color: var(--ink);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-weight: 800;
}

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

.sidebar {
  position: relative;
  width: 340px;
  min-width: 260px;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.sidebar.collapsed {
  display: none;
}

.sidebar-resize {
  position: absolute;
  top: 0;
  right: -4px;
  z-index: 5;
  width: 8px;
  height: 100%;
  cursor: col-resize;
}

.sidebar-resize:hover {
  background: rgba(40, 124, 121, 0.12);
}

.brand-copy {
  flex: 1;
  min-width: 0;
}

.brand-copy h1,
.brand-copy p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace-row,
.sidebar-toolbar {
  display: flex;
  align-items: end;
  gap: 8px;
}

.workspace-field {
  display: grid;
  flex: 1;
  min-width: 0;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.workspace-field select {
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--ink);
  outline: none;
}

.workspace-field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(40, 124, 121, 0.16);
}

.sidebar-toolbar .compact-button {
  width: 100%;
  flex: 1;
}

.sidebar-expand {
  position: sticky;
  top: 14px;
  align-self: flex-start;
  z-index: 2;
  margin: 14px 0 0 12px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(36, 47, 61, 0.1);
}

.search-box {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.search-box input {
  padding: 0 12px;
  background: var(--panel-soft);
}

.sidebar-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.doc-list {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  gap: 16px;
  overflow: auto;
  padding-right: 4px;
}

.tree-list,
.tree-children {
  display: grid;
  gap: 3px;
}

.tree-children {
  margin-left: 16px;
  padding-left: 8px;
  border-left: 1px solid var(--line);
}

.tree-row {
  position: relative;
  width: 100%;
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  color: var(--ink);
}

.tree-row:hover,
.tree-row.active {
  background: var(--accent-soft);
  border-color: #b8dfdc;
}

.tree-arrow,
.tree-spacer {
  display: inline-grid;
  flex: 0 0 22px;
  width: 22px;
  height: 26px;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
  font-size: 15px;
}

.tree-icon {
  flex: 0 0 24px;
  color: var(--accent);
  font-size: 18px;
}

.tree-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.tree-actions {
  position: relative;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 3px;
  opacity: 0;
  pointer-events: none;
}

.tree-actions[hidden] {
  display: none;
}

.tree-add,
.tree-menu-toggle {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  min-height: 28px;
  font-size: 18px;
}

.tree-menu-toggle {
  font-size: 15px;
}

.tree-row:hover .tree-actions,
.tree-row:focus-within .tree-actions {
  opacity: 1;
  pointer-events: auto;
}

.tree-menu {
  position: absolute;
  right: 0;
  top: 32px;
  z-index: 8;
  display: grid;
  min-width: 128px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.tree-menu[hidden] {
  display: none;
}

.tree-menu button {
  min-height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  white-space: nowrap;
}

.tree-menu button:hover {
  background: var(--panel-soft);
}

.tree-empty {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(10px);
}

.topbar-title {
  min-width: 0;
}

.breadcrumbs {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
}

.topbar h2 {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 20px;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.topbar-actions .primary-button {
  width: auto;
}

.topbar-actions .secondary-button,
.topbar-actions .danger-button,
.topbar-actions .primary-button {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 13px;
}

.viewer {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0;
  background: #ffffff;
}

.share-manager-page {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 24px;
  background: #ffffff;
}

.share-manager-shell {
  display: grid;
  gap: 16px;
  max-width: 1120px;
  margin: 0 auto;
}

.share-manager-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.share-manager-header h2 {
  margin: 0;
  font-size: 24px;
}

.editor-shell {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 0;
  height: 100%;
}

.editor-top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 22px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.editor-title-input {
  flex: 1;
  min-width: 0;
  min-height: 42px;
  border: 0;
  border-radius: 0;
  outline: none;
  color: var(--ink);
  background: transparent;
  font-size: 28px;
  font-weight: 850;
}

.editor-status {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px 22px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

.editor-toolbar button,
.editor-toolbar select,
.editor-color {
  min-height: 32px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
}

.editor-toolbar button {
  padding: 0 10px;
  font-weight: 800;
}

.editor-toolbar select {
  padding: 0 8px;
}

.editor-color {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  color: var(--muted);
  font-size: 12px;
}

.editor-color input {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  background: transparent;
}

.rich-editor {
  width: 100%;
  min-height: calc(100vh - 160px);
  padding: 28px 40px 52px;
  border: 0;
  background: var(--panel);
  color: var(--ink);
  outline: none;
  font-size: 16px;
  line-height: 1.75;
}

.rich-editor:focus {
  box-shadow: inset 0 0 0 2px rgba(37, 111, 104, 0.18);
}

.rich-editor img {
  max-width: 100%;
  height: auto;
}

.empty-state,
.status-panel,
.unsupported-panel {
  max-width: 760px;
  margin: 8vh auto 0;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.empty-state h3,
.status-panel h3,
.unsupported-panel h3 {
  margin: 0 0 8px;
  font-size: 22px;
}

.empty-state p,
.status-panel p,
.unsupported-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.markdown-body,
.text-body,
.docx-body {
  max-width: none;
  min-height: 100%;
  margin: 0;
  padding: 34px 42px;
  border: 0;
  border-radius: 0;
  background: var(--panel);
  box-shadow: none;
  line-height: 1.78;
}

.markdown-body h1,
.docx-body h1 {
  margin-top: 0;
  font-size: 32px;
}

.markdown-body h2,
.docx-body h2 {
  margin-top: 34px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  font-size: 24px;
}

.markdown-body img,
.docx-body img {
  max-width: 100%;
}

.markdown-body pre,
.text-body pre {
  overflow: auto;
  padding: 14px;
  border-radius: 8px;
  background: #1f2933;
  color: #edf2f7;
}

.markdown-body code {
  padding: 2px 5px;
  border-radius: 5px;
  background: #eef2f7;
}

.markdown-body pre code {
  padding: 0;
  background: transparent;
}

.pdf-frame {
  width: 100%;
  height: calc(100vh - 150px);
  min-height: 620px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.sheet-view {
  display: grid;
  gap: 12px;
}

.sheet-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sheet-tab {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
}

.sheet-tab.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
}

.sheet-table-wrap {
  overflow: auto;
  max-height: calc(100vh - 210px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.sheet-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.sheet-table th,
.sheet-table td {
  min-width: 120px;
  max-width: 360px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  overflow-wrap: anywhere;
  vertical-align: top;
}

.sheet-table th {
  position: sticky;
  top: 0;
  background: var(--panel-soft);
  color: var(--muted);
  text-align: left;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0 24px;
}

.tag {
  padding: 4px 8px;
  border-radius: 8px;
  background: #fff3df;
  color: #80440e;
  font-size: 12px;
  font-weight: 700;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(19, 28, 38, 0.46);
}

.sync-panel {
  width: min(780px, 100%);
  max-height: min(760px, calc(100vh - 40px));
  overflow: auto;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.sync-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.sync-header h2 {
  margin: 0;
  font-size: 22px;
}

.sync-grid,
.sync-settings,
.sync-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  margin-bottom: 16px;
}

.sync-code-field {
  flex: 1 1 280px;
  margin-bottom: 0;
}

.sync-connect {
  width: auto;
}

.check-row {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
}

.check-row input {
  width: 18px;
  height: 18px;
}

.compact-field {
  width: 150px;
  margin-bottom: 0;
}

.sync-status {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin: 6px 0 16px;
}

.sync-status div {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.sync-status dt {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.sync-status dd {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.sync-log {
  min-height: 180px;
  max-height: 300px;
  overflow: auto;
  margin: 0;
  padding: 14px;
  border-radius: 8px;
  background: #17202a;
  color: #ecf2f8;
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.share-panel {
  width: min(840px, 100%);
}

.share-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.share-form .field,
.share-link-row {
  margin-bottom: 0;
}

.share-form select,
.share-form input,
.share-link-row input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  outline: none;
}

.share-list {
  display: grid;
  gap: 12px;
}

.share-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.share-item-main {
  min-width: 0;
}

.share-item h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.share-item p {
  margin: 3px 0;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.share-item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.share-mode .workspace-row,
.share-mode .sidebar-toolbar,
.share-mode #share-open,
.share-mode #share-manage-open,
.share-mode #sync-open,
.share-mode #copy-link,
.share-mode #download-current,
.share-mode #logout-button {
  display: none !important;
}

@media (max-width: 860px) {
  .app-shell {
    min-height: 100vh;
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    min-width: 0;
    max-width: none;
    max-height: 44vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sidebar-resize {
    display: none;
  }

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

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .share-manager-page {
    padding: 16px;
  }

  .share-manager-header,
  .share-item {
    align-items: flex-start;
    flex-direction: column;
  }

  .share-item-actions {
    justify-content: flex-start;
  }

  .viewer {
    padding: 0;
  }

  .markdown-body,
  .text-body,
  .docx-body {
    padding: 24px 18px;
  }

  .pdf-frame {
    height: 70vh;
    min-height: 460px;
  }

  .sync-status {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 560px) {
  .sync-status {
    grid-template-columns: 1fr;
  }

  .sync-actions button,
  .sync-settings button,
  .sync-connect {
    width: 100%;
  }
}
