:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-soft: #f1f3f5;
  --text: #1f2328;
  --muted: #59636e;
  --border: #d1d9e0;
  --accent: #0969da;
  --accent-strong: #0550ae;
  --accent-soft: #ddf4ff;
  --preview-accent: #e11d48;
  --preview-accent-strong: #be123c;
  --preview-accent-soft: #ffe4e6;
  --json-preview-bg: var(--surface);
  --json-key: #be123c;
  --json-string: #047857;
  --json-number: #7c3aed;
  --json-boolean: #0369a1;
  --json-null: #59636e;
  --json-punctuation: #59636e;
  --json-summary: #59636e;
  --json-guide: #d1d9e0;
  --json-toggle-hover-bg: var(--accent-soft);
  --json-toggle-hover-color: var(--accent-strong);
  --warn: #ea580c;
  --danger: #b91c1c;
  --code-bg: #f1f3f5;
  --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
  --radius: 8px;
  --document-font: "Courier New", "宋体", SimSun, NSimSun, "新宋体",
    STSong, monospace;
  font-family: var(--document-font);
}

:root[data-theme="dark"] {
  color-scheme: light;
  --bg: #0d1117;
  --surface: #161b22;
  --surface-soft: #22272e;
  --text: #e6edf3;
  --muted: #9198a1;
  --border: #30363d;
  --accent: #4493f8;
  --accent-strong: #79b8ff;
  --accent-soft: #0c2d6b;
  --preview-accent: #fb7185;
  --preview-accent-strong: #fda4af;
  --preview-accent-soft: #881337;
  --json-preview-bg: #111820;
  --json-key: #ffb4c0;
  --json-string: #7ee787;
  --json-number: #d2a8ff;
  --json-boolean: #79c0ff;
  --json-null: #9aa4b2;
  --json-punctuation: #b1bac4;
  --json-summary: #9aa4b2;
  --json-guide: #3f536b;
  --json-toggle-hover-bg: rgba(68, 147, 248, 0.18);
  --json-toggle-hover-color: #a5d6ff;
  --warn: #fb923c;
  --danger: #f87171;
  --code-bg: #161b22;
  --shadow: 0 16px 32px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

#fileInput,
#fileUploadInput {
  color-scheme: only light;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

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

button {
  cursor: pointer;
}

button:disabled:not(.is-busy) {
  cursor: not-allowed;
  opacity: 0.5;
}

.app-shell {
  height: 100%;
  min-height: 100%;
  display: grid;
  grid-template-rows: 1fr auto;
  overflow: hidden;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.segmented {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.segment,
.tool-button,
.text-button,
.icon-button,
.primary-button {
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text);
  background: transparent;
}

.segment {
  min-width: 54px;
  height: 30px;
  padding: 0 10px;
}

.segment.is-active {
  background: var(--surface);
  border-color: var(--border);
  color: var(--accent-strong);
  box-shadow: 0 1px 4px rgba(9, 105, 218, 0.18);
}

.segment:disabled {
  cursor: not-allowed;
  color: var(--muted);
  opacity: 0.55;
}

.tool-button,
.icon-button {
  min-height: 36px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-color: var(--border);
  background: var(--surface);
  white-space: nowrap;
}

.icon-button {
  width: 32px;
  min-height: 32px;
  padding: 0;
  border-color: var(--border);
  background: var(--surface);
}

.tool-button svg,
.icon-button svg,
.text-button svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

.text-format-button span,
.color-button span {
  display: inline-grid;
  place-items: center;
  min-width: 17px;
  height: 17px;
  font-family: var(--document-font);
  font-size: 1.05rem;
  line-height: 1;
}

.bold-button span {
  font-weight: 900;
}

.strike-button span {
  font-weight: 800;
  text-decoration: line-through;
  text-decoration-color: currentColor;
  text-decoration-thickness: 0.12em;
}

.text-button {
  min-height: 30px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  color: var(--accent-strong);
  white-space: nowrap;
}

.text-button.danger {
  color: var(--danger);
}

.primary-button {
  min-height: 34px;
  padding: 0 12px;
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

.segment:hover,
.tool-button:hover,
.text-button:hover,
.icon-button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.text-button:active,
.icon-button:active,
.tool-button:active,
.primary-button:active {
  transform: translateY(1px);
}

.text-button.is-busy,
.icon-button.is-busy {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
  opacity: 1;
}

.icon-button.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.pdf-download-button {
  position: relative;
  border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
  color: var(--danger);
}

.pdf-download-button:hover,
.pdf-download-button.is-busy {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
  color: var(--danger);
}

.pdf-download-button::after {
  content: "PDF";
  position: absolute;
  right: 2px;
  bottom: 2px;
  min-width: 14px;
  height: 8px;
  display: grid;
  place-items: center;
  border-radius: 2px;
  background: var(--danger);
  color: #ffffff;
  font-size: 5px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
}

.icon-button.is-busy svg {
  animation: spin 0.8s linear infinite;
}

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

.primary-button:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.workspace {
  height: 100%;
  display: grid;
  grid-template-columns: var(--file-panel-width, 260px) 14px minmax(0, 1fr);
  gap: 0;
  padding: 16px;
  min-height: 0;
  align-items: stretch;
  overflow: hidden;
}

.app-shell[data-file-panel="collapsed"] .workspace {
  grid-template-columns: 44px minmax(0, 1fr);
}

.document-workspace {
  display: grid;
  grid-template-columns: var(
    --initial-document-columns,
    minmax(240px, 0.5fr) 14px minmax(240px, 0.5fr)
  );
  gap: 0;
  min-width: 0;
  min-height: 0;
}

.panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.editor-panel {
  grid-template-rows: auto auto minmax(0, 1fr);
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.preview-panel {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.file-panel {
  height: 100%;
  align-self: stretch;
  grid-template-rows: auto auto 1fr auto;
  background: var(--surface);
}

.file-panel > .panel-bar {
  grid-row: 1;
}

.file-tools {
  grid-row: 2;
}

.file-list {
  grid-row: 3;
}

.file-bottom-tools {
  grid-row: 4;
}

.file-panel .panel-actions {
  gap: 5px;
  flex-wrap: nowrap;
}

.file-panel .icon-button {
  width: 30px;
  min-height: 30px;
}

.mobile-new-draft-button {
  display: none;
}

.app-shell[data-file-panel="collapsed"] .file-panel {
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  min-height: 0;
}

.app-shell[data-file-panel="collapsed"] .file-panel .panel-bar {
  height: auto;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 8px 5px;
}

.app-shell[data-file-panel="collapsed"] .file-panel .panel-bar h2,
.app-shell[data-file-panel="collapsed"] .file-tools,
.app-shell[data-file-panel="collapsed"] .file-list,
.app-shell[data-file-panel="collapsed"] .file-panel .panel-actions > :not([data-action="toggle-file-panel"]) {
  display: none;
}

.app-shell[data-file-panel="collapsed"] .file-panel .panel-actions {
  justify-content: center;
}

.app-shell[data-file-panel="collapsed"] .file-bottom-tools {
  grid-row: 3;
  min-height: 0;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  padding: 8px 5px;
  border-top: 0;
  background: transparent;
}

.app-shell[data-file-panel="collapsed"] .file-bottom-tools .icon-button {
  width: 28px;
  min-height: 28px;
}

.file-panel-resizer {
  min-width: 14px;
  min-height: 0;
  display: grid;
  place-items: center;
  cursor: col-resize;
  touch-action: none;
  position: relative;
  outline: 0;
}

.app-shell[data-file-panel="collapsed"] .file-panel-resizer {
  display: none;
}

.file-panel-resizer::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  background: var(--border);
  transform: translateX(-50%);
}

.file-panel-resizer-handle {
  width: 4px;
  height: 42px;
  border-radius: 999px;
  background: var(--border);
  position: relative;
  z-index: 1;
}

.file-panel-resizer:hover .file-panel-resizer-handle,
.file-panel-resizer:focus-visible .file-panel-resizer-handle,
.file-panel-resizer.is-dragging .file-panel-resizer-handle {
  background: var(--accent);
}

.file-panel-resizer:focus-visible {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.file-tools {
  display: grid;
  gap: 4px;
  padding: 6px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.file-tools[hidden] {
  display: none;
}

.file-search {
  min-width: 0;
  min-height: 28px;
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 8px;
  background: var(--bg);
  color: var(--muted);
}

.file-search svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
}

.file-search input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
}

.file-tool-row {
  min-width: 0;
  display: grid;
  grid-template-columns: auto;
  align-items: center;
  gap: 6px;
}

.file-select-all {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.file-select-all input {
  width: 14px;
  height: 14px;
  margin: 0;
}

.file-tools .text-button {
  justify-self: end;
  min-height: 24px;
  padding: 0 6px;
  border-radius: 5px;
  font-size: 0.74rem;
  gap: 4px;
}

.file-tools .text-button svg {
  width: 13px;
  height: 13px;
}

.file-search-summary {
  min-height: 14px;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.2;
}

.file-bottom-tools {
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-top: 1px solid var(--border);
  background: var(--surface-soft);
}

.file-bottom-tools .icon-button {
  width: 26px;
  min-height: 26px;
}

.file-bottom-tools .icon-button svg {
  width: 15px;
  height: 15px;
}

.current-file-name {
  display: none;
}

.file-list {
  min-height: 0;
  overflow: auto;
  padding: 6px;
  background: var(--surface);
}

.directory-panel {
  min-height: 100%;
  user-select: none;
}

.directory-tree {
  display: grid;
}

.search-results-panel {
  display: grid;
  align-content: start;
  gap: 10px;
}

.search-result-heading {
  padding: 2px 4px 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.search-result-heading span {
  font-weight: 500;
}

.search-result-list {
  display: grid;
  gap: 2px;
}

.search-result-item {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: start;
  gap: 7px;
  border: 0;
  border-radius: 6px;
  padding: 6px 7px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.search-result-item:hover {
  background: var(--accent-soft);
}

.search-result-item svg {
  width: 15px;
  height: 15px;
  margin-top: 2px;
  color: var(--accent-strong);
}

.search-result-text {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.search-result-title,
.search-result-snippet {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-title {
  white-space: nowrap;
  font-size: 0.84rem;
  font-weight: 700;
}

.search-result-snippet {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

mark,
.search-highlight {
  border-radius: 3px;
  padding: 0 2px;
  background: #fde68a;
  color: #111827;
}

.tree-node {
  min-width: 0;
}

.tree-row {
  min-width: 0;
  height: 30px;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  padding-left: calc(var(--tree-depth, 0) * 16px);
  border-radius: 6px;
}

.tree-row:hover,
.tree-node.is-active > .tree-row,
.tree-node.is-selected > .tree-row {
  background: var(--accent-soft);
}

.tree-node.is-active > .tree-row,
.tree-node.is-selected > .tree-row {
  box-shadow: inset 0 0 0 1px var(--accent);
}

.tree-node.is-dragging > .tree-row {
  opacity: 0.55;
}

.tree-node.is-drop-target > .tree-row {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.tree-node.is-sort-before > .tree-row,
.tree-node.is-sort-after > .tree-row {
  position: relative;
}

.tree-node.is-sort-before > .tree-row::before,
.tree-node.is-sort-after > .tree-row::after {
  content: "";
  position: absolute;
  left: calc(var(--tree-depth, 0) * 16px + 24px);
  right: 6px;
  height: 2px;
  border-radius: 999px;
  background: var(--accent);
}

.tree-node.is-sort-before > .tree-row::before {
  top: 0;
}

.tree-node.is-sort-after > .tree-row::after {
  bottom: 0;
}

.tree-toggle,
.tree-label {
  border: 0;
  background: transparent;
  color: var(--text);
}

.tree-toggle {
  width: 22px;
  height: 30px;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--muted);
}

.tree-toggle:disabled {
  opacity: 0.5;
}

.tree-toggle svg {
  width: 14px;
  height: 14px;
}

.tree-open-indicator {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #22c55e;
  box-shadow: 0 0 0 2px color-mix(in srgb, #22c55e 18%, transparent);
}

.tree-label {
  width: 100%;
  min-width: 0;
  height: 30px;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  padding: 0 7px 0 1px;
  text-align: left;
}

.tree-label svg {
  width: 15px;
  height: 15px;
}

.tree-folder > .tree-row .tree-label svg {
  color: var(--warn);
}

.tree-file > .tree-row .tree-label svg {
  color: var(--accent-strong);
}

.tree-label span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.84rem;
  font-weight: 600;
}

.tree-menu-button {
  display: none;
  border: 0;
  background: transparent;
  color: var(--muted);
}

.tree-menu-button svg {
  width: 17px;
  height: 17px;
}

.file-empty {
  display: grid;
  gap: 6px;
  padding: 12px 10px;
  color: var(--muted);
  font-size: 0.88rem;
}

.file-empty strong,
.directory-message strong {
  color: var(--text);
}

.directory-message {
  display: grid;
  gap: 6px;
  padding: 12px 10px;
  color: var(--muted);
  font-size: 0.84rem;
}

.context-menu {
  position: fixed;
  z-index: 40;
  min-width: 174px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.context-menu-item {
  width: 100%;
  min-height: 30px;
  display: grid;
  grid-template-columns: 17px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: 6px;
  padding: 0 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.context-menu-item:hover {
  background: var(--accent-soft);
}

.context-menu-item.danger {
  color: var(--danger);
}

.context-menu-item svg {
  width: 15px;
  height: 15px;
}

.context-menu-separator {
  height: 1px;
  margin: 5px;
  background: var(--border);
}

.login-form {
  display: grid;
  gap: 12px;
  margin: 10px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}

.login-heading {
  display: grid;
  gap: 3px;
  margin-bottom: 2px;
}

.login-heading strong {
  color: var(--text);
  font-size: 1rem;
}

.login-heading span {
  color: var(--muted);
  font-size: 0.82rem;
}

.login-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

.login-form input {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 9px;
  background: var(--surface);
  color: var(--text);
}

.login-submit-button {
  width: 100%;
}

.password-input-wrap {
  position: relative;
  display: block;
  width: 100%;
}

.password-input-wrap input {
  padding-right: 42px;
}

.password-visibility-button {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  width: 32px;
  height: 30px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.password-visibility-button:hover,
.password-visibility-button.is-visible {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.password-visibility-button svg {
  width: 16px;
  height: 16px;
}

.form-message {
  margin: 0;
  color: var(--danger);
  font-size: 0.82rem;
}

.modal {
  width: min(440px, calc(100vw - 28px));
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  background: transparent;
  color: var(--text);
}

.modal::backdrop {
  background: rgba(17, 24, 39, 0.45);
}

.modal-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 22px 70px rgba(17, 24, 39, 0.28);
}

.modal-header,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1rem;
}

.modal-description {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.9rem;
}

.ai-settings-modal {
  width: min(700px, calc(100vw - 28px));
}

.user-management-modal {
  width: min(620px, calc(100vw - 28px));
}

.upload-modal {
  width: min(460px, calc(100vw - 28px));
  color-scheme: only light;
}

.ai-settings-card {
  max-height: calc(100vh - 40px);
  overflow: auto;
}

.user-management-card {
  max-height: calc(100vh - 40px);
  overflow: auto;
}

.upload-card {
  color: #1f2328;
  background: #ffffff;
  border-color: #d1d9e0;
}

.upload-card .modal-header h2 {
  color: #1f2328;
}

.upload-card .icon-button,
.upload-card .text-button {
  color: #1f2328;
  background: #ffffff;
  border-color: #d1d9e0;
}

.upload-card .text-button {
  color: #0550ae;
}

.upload-card .primary-button {
  color: #ffffff;
  background: #0969da;
  border-color: #0969da;
}

.upload-card .ai-status {
  color: #59636e;
}

.upload-drop-zone {
  min-height: 158px;
  display: grid;
  place-items: center;
  gap: 10px;
  padding: 24px 18px;
  border: 1px dashed #8c959f;
  border-radius: 8px;
  background: #f6f8fa;
  color: #1f2328;
  text-align: center;
  outline: 0;
}

.upload-drop-zone svg {
  width: 28px;
  height: 28px;
  color: #0969da;
}

.upload-drop-zone.is-dragging,
.upload-drop-zone:focus-visible {
  border-color: #0969da;
  background: #ddf4ff;
  box-shadow: 0 0 0 3px rgba(9, 105, 218, 0.14);
}

.upload-drop-text {
  display: grid;
  gap: 4px;
}

.upload-drop-text strong {
  font-size: 0.96rem;
}

.upload-drop-text span {
  color: #59636e;
  font-size: 0.84rem;
}

.upload-actions {
  align-items: center;
}

.ai-layout {
  display: grid;
  gap: 16px;
}

.user-management-layout {
  display: grid;
  gap: 12px;
}

.ai-section {
  display: grid;
  gap: 9px;
}

.user-section {
  display: grid;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.user-section:first-child {
  padding-top: 0;
  border-top: 0;
}

.ai-section-title {
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 700;
}

.user-section-title {
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 700;
}

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

.user-create-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
}

.user-password-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
}

.user-section-actions {
  display: flex;
  justify-content: flex-end;
}

.user-list {
  display: grid;
  gap: 6px;
}

.user-row {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-soft);
}

.user-avatar {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 800;
}

.user-info {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.user-info strong,
.user-info span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-info strong {
  font-size: 0.9rem;
}

.user-info span,
.user-empty {
  color: var(--muted);
  font-size: 0.8rem;
}

.modal-field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.84rem;
}

.modal-field input,
.modal-field select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 10px;
  background: var(--surface);
  color: var(--text);
}

.modal-field .password-input-wrap input {
  padding-right: 42px;
}

.modal-field input:focus,
.modal-field select:focus,
.ai-textarea:focus {
  border-color: var(--accent);
  outline: 2px solid var(--accent-soft);
}

.ai-textarea {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  background: var(--surface-soft);
  color: var(--text);
  font-family: var(--document-font);
  line-height: 1.55;
}

.ai-prompt-text {
  min-height: 150px;
}

.ai-status {
  flex: 1 1 220px;
  min-width: min(100%, 220px);
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.ai-actions {
  align-items: center;
  flex-wrap: wrap;
}

.user-actions {
  align-items: center;
  flex-wrap: wrap;
}

.ai-actions .ai-status {
  margin-right: auto;
}

.user-actions .ai-status {
  margin-right: auto;
}

.modal-actions {
  justify-content: flex-end;
}

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

.danger-button:hover {
  background: var(--danger);
  border-color: var(--danger);
  filter: brightness(0.95);
}

.splitter {
  min-height: 0;
  display: grid;
  place-items: center;
  cursor: col-resize;
  touch-action: none;
  position: relative;
  outline: 0;
}

.splitter::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  background: var(--border);
  transform: translateX(-50%);
}

.splitter-handle {
  width: 4px;
  height: 46px;
  border-radius: 999px;
  background: var(--border);
  position: relative;
  z-index: 1;
}

.splitter:hover .splitter-handle,
.splitter:focus-visible .splitter-handle,
.splitter.is-dragging .splitter-handle {
  background: var(--accent);
}

.splitter:focus-visible {
  box-shadow: inset 0 0 0 2px var(--accent);
}

html.is-resizing,
html.is-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}

html.is-resizing-file-panel,
html.is-resizing-file-panel * {
  cursor: col-resize !important;
  user-select: none !important;
}

.panel-bar {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-soft);
}

.panel-bar h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.panel-bar .panel-actions {
  gap: 4px;
}

.editor-panel .panel-bar,
.preview-panel .panel-bar {
  min-height: 44px;
}

.panel-bar .segmented {
  min-height: 28px;
  padding: 2px;
}

.panel-bar .segment {
  min-width: 42px;
  height: 22px;
  padding: 0 7px;
  font-size: 0.76rem;
  line-height: 1;
}

.panel-bar .icon-button {
  width: 28px;
  min-height: 28px;
}

.panel-bar .icon-button svg {
  width: 15px;
  height: 15px;
}

.panel-bar .text-button {
  min-height: 24px;
  padding: 0 6px;
  border-radius: 5px;
  font-size: 0.76rem;
}

.editor-panel .panel-actions,
.preview-panel .panel-actions {
  flex: 1;
  min-width: 0;
}

.editor-view-modes,
.preview-panel .preview-view-modes {
  margin-right: 0;
}

.editor-panel .panel-actions {
  justify-content: flex-end;
}

.editor-download-button {
  display: none;
}

.app-shell[data-view="editor"] .editor-download-button,
.app-shell[data-document-mode="text"] .editor-download-button,
.app-shell[data-document-mode="mindmap"] .editor-download-button {
  display: inline-flex;
}

.document-mode-toggle {
  flex: 0 0 auto;
}

.document-mode-toggle .segment svg,
.document-mode-toggle .segment i {
  display: none;
}

.toolbar-menu {
  position: relative;
  flex: 0 0 auto;
}

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

.toolbar-menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 35;
  min-width: 132px;
  display: grid;
  gap: 2px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.toolbar-menu-item {
  width: 100%;
  min-height: 30px;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 14px;
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: 6px;
  padding: 0 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.toolbar-menu-item > span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toolbar-menu-item:hover,
.toolbar-menu-item.is-active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.toolbar-menu-item.is-active::after {
  content: "";
  width: 6px;
  height: 10px;
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
}

.font-size-sample {
  font-size: 0.86rem;
  font-weight: 800;
  line-height: 1;
}

.font-size-sample.is-small {
  font-size: 0.76rem;
}

.font-size-sample.is-medium {
  font-size: 0.95rem;
}

.font-size-sample.is-large {
  font-size: 1.06rem;
}

.font-size-sample.is-xl {
  font-size: 1.2rem;
}

.font-size-sample.is-xxl {
  font-size: 1.32rem;
}

.line-height-sample {
  width: 18px;
  height: 16px;
  display: grid;
  align-content: center;
  gap: 3px;
}

.line-height-sample::before,
.line-height-sample::after {
  content: "";
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.line-height-sample.is-tight {
  gap: 1px;
}

.line-height-sample.is-loose {
  gap: 5px;
}

.line-height-sample.is-wide {
  gap: 7px;
}

.panel-action-spacer {
  flex: 1 1 auto;
  min-width: 8px;
}

.color-button {
  color: var(--danger);
}

.color-button span {
  font-weight: 800;
}

.color-button:hover {
  border-color: var(--danger);
  background: rgba(220, 38, 38, 0.08);
}

.ai-draft-bar {
  grid-row: 2;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--accent-soft);
}

.ai-draft-bar[hidden] {
  display: none;
}

.ai-draft-source {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 700;
}

.ai-draft-source svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
}

.ai-draft-source span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-draft-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

#markdownInput {
  grid-row: 3;
  width: 100%;
  height: 100%;
  min-height: 0;
  resize: none;
  border: 0;
  outline: 0;
  padding: 18px;
  background: var(--surface);
  color: var(--text);
  line-height: 1.65;
  font-family: var(--document-font);
  font-size: 0.95rem;
  tab-size: 2;
  overflow: auto;
}

#markdownInput::placeholder {
  color: var(--muted);
}

#markdownInput[hidden] {
  display: none;
}

.rich-editor {
  grid-row: 3;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: auto;
  padding: 18px;
  outline: 0;
  background: var(--surface);
  color: var(--text);
  font-family: var(--document-font);
  font-size: 0.95rem;
  line-height: 1.65;
}

.rich-editor[hidden] {
  display: none;
}

.rich-editor:focus {
  outline: 0;
  box-shadow: none;
}

.rich-editor p,
.rich-editor div {
  margin: 0 0 0.8em;
}

.rich-editor ul,
.rich-editor ol {
  margin: 0 0 0.8em;
  padding-left: 1.6em;
}

.rich-editor li {
  margin: 0.18em 0;
  list-style: none !important;
}

.rich-editor ol,
.rich-editor ul,
.rich-editor ol[data-custom-ordered-list],
.rich-editor ul[data-custom-bullet-list] {
  list-style: none !important;
  list-style-type: none !important;
  padding-left: 2.2em;
}

.rich-editor li::marker {
  content: "" !important;
}

.rich-editor li[data-list-label] {
  position: relative;
}

.rich-editor li[data-list-label]::before {
  content: attr(data-list-label);
  position: absolute;
  right: calc(100% + 0.45em);
  min-width: 1.6em;
  text-align: right;
  display: inline-block !important;
}

.rich-editor strong,
.rich-editor b,
.markdown-preview strong,
.markdown-preview b {
  font-weight: 900;
  text-shadow: 0.018em 0 currentColor;
}

.rich-editor s,
.rich-editor strike,
.rich-editor del,
.rich-editor span[style*="line-through"],
.markdown-preview s,
.markdown-preview strike,
.markdown-preview del,
.markdown-preview span[style*="line-through"] {
  text-decoration-line: line-through;
  text-decoration-color: currentColor;
  text-decoration-thickness: 0.08em;
}

.markdown-preview {
  min-width: 0;
  overflow: auto;
  padding: 20px 24px 64px;
  line-height: 1.5;
  background: var(--surface);
}

.plain-text-preview-host {
  padding: 18px;
}

.plain-text-preview {
  margin: 0;
  white-space: normal;
  word-break: break-word;
  color: var(--text);
  font-family: var(--document-font);
  font-size: 0.95rem;
  line-height: 1.65;
}

.markdown-preview [data-rich-root] {
  margin: 0;
  white-space: normal;
  word-break: break-word;
  color: var(--text);
  font-family: var(--document-font);
}

.plain-text-preview p,
.plain-text-preview div,
.markdown-preview [data-rich-root] p,
.markdown-preview [data-rich-root] div {
  margin: 0 0 0.8em;
}

.plain-text-preview ul,
.plain-text-preview ol,
.markdown-preview [data-rich-root] ul,
.markdown-preview [data-rich-root] ol {
  margin: 0 0 0.8em;
  padding-left: 1.6em;
}

.markdown-preview [data-rich-root] li {
  margin: 0.18em 0;
}

.json-preview-host {
  padding: 18px 20px 28px;
  background: var(--json-preview-bg);
}

.json-preview {
  min-height: 100%;
  margin: 0;
  padding: 0;
  color: var(--text);
  font-family: var(--document-font);
  font-size: 0.95rem;
  line-height: 1.65;
}

.json-preview-empty,
.json-preview-error {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.json-preview-error strong {
  color: var(--danger);
}

.json-error-snippet {
  margin: 4px 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  overflow-x: auto;
}

.json-error-snippet code {
  padding: 0;
  background: transparent;
  color: inherit;
  font-family: var(--document-font);
  white-space: pre;
}

.json-error-locate {
  justify-self: start;
}

.json-line {
  min-width: max-content;
  white-space: pre;
}

.json-node,
.json-node-children {
  min-width: max-content;
}

.json-node-children {
  position: relative;
}

.json-node-children::before {
  content: "";
  position: absolute;
  top: 0.1em;
  bottom: 0.85em;
  left: calc(var(--json-guide-left, 0ch) + 0.64em);
  border-left: 1px dashed var(--json-guide);
  opacity: 1;
  pointer-events: none;
}

.json-toggle {
  width: 1.28em;
  height: 1.28em;
  margin: 0 0.25em 0 0;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  vertical-align: -0.18em;
  cursor: pointer;
}

.json-toggle:hover {
  background: var(--json-toggle-hover-bg);
  color: var(--json-toggle-hover-color);
}

.json-toggle:focus-visible {
  outline: 2px solid var(--json-toggle-hover-color);
  outline-offset: 1px;
}

.json-toggle svg {
  width: 1em;
  height: 1em;
  stroke-width: 2.4;
}

.json-toggle-spacer {
  width: 1.53em;
  display: inline-block;
}

.json-collapsed-summary {
  color: var(--json-summary);
  font-style: italic;
}

.json-inline-close {
  margin-left: 0.2em;
}

.json-key {
  color: var(--json-key);
  font-weight: 700;
}

.json-punctuation {
  color: var(--json-punctuation);
}

.json-comma {
  margin-left: 1px;
}

.json-string {
  color: var(--json-string);
}

.json-number {
  color: var(--json-number);
}

.json-boolean {
  color: var(--json-boolean);
  font-weight: 700;
}

.json-null {
  color: var(--json-null);
  font-style: italic;
}

.text-red {
  color: var(--danger);
  font-weight: 700;
}

.markdown-preview > :first-child {
  margin-top: 0;
}

.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3,
.markdown-preview h4,
.markdown-preview h5,
.markdown-preview h6 {
  color: var(--text);
  line-height: 1.5;
  margin: 1.4em 0 0.55em;
}

.markdown-preview h1 {
  font-size: 1.85rem;
  border-bottom: 1px solid var(--preview-accent-soft);
  padding-bottom: 0.32em;
}

.markdown-preview h2 {
  font-size: 1.45rem;
}

.markdown-preview h3 {
  font-size: 1.18rem;
}

.markdown-preview p,
.markdown-preview ul,
.markdown-preview ol,
.markdown-preview blockquote,
.markdown-preview pre,
.markdown-preview table {
  margin: 0 0 1em;
}

.markdown-preview ul,
.markdown-preview ol {
  padding-left: 1.6em;
}

.markdown-preview ol[data-custom-ordered-list],
.markdown-preview ul[data-custom-bullet-list] {
  list-style: none;
  padding-left: 2.2em;
}

.markdown-preview ol[data-custom-ordered-list] > li,
.markdown-preview ul[data-custom-bullet-list] > li {
  position: relative;
}

.markdown-preview ol[data-custom-ordered-list] > li::before,
.markdown-preview ul[data-custom-bullet-list] > li::before {
  content: attr(data-list-label);
  position: absolute;
  right: calc(100% + 0.45em);
  min-width: 1.6em;
  text-align: right;
}

.markdown-preview li {
  margin: 0.25em 0;
}

.markdown-preview li > p {
  margin: 0.25em 0;
}

.markdown-preview a {
  color: var(--preview-accent-strong);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
}

.markdown-preview code {
  padding: 0.14em 0.34em;
  border-radius: 5px;
  background: var(--preview-accent-soft);
  color: var(--preview-accent-strong);
  font-size: 0.92em;
  font-family: var(--document-font);
}

.markdown-preview pre {
  overflow: auto;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: #0f0f10;
  border: 1px solid #1f1f22;
  line-height: 1.5;
}

.markdown-preview pre code {
  display: block;
  padding: 0;
  background: transparent;
  color: #e5e7eb;
}

.markdown-preview blockquote {
  padding: 4px 0 4px 16px;
  border-left: 4px solid var(--preview-accent);
  color: var(--muted);
}

.markdown-preview table {
  width: 100%;
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
}

.markdown-preview th,
.markdown-preview td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
}

.markdown-preview th {
  background: var(--surface-soft);
}

.markdown-preview img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

.markdown-preview hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

.statusbar {
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.84rem;
}

.statusbar-meta {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
}

.statusbar-meta span,
.filing-link {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filing-link {
  flex: 0 0 auto;
  color: inherit;
  text-decoration: none;
}

.filing-link:hover {
  color: var(--accent-strong);
  text-decoration: underline;
}

.preview-view-modes {
  min-height: 28px;
  padding: 2px;
}

.preview-view-modes .segment {
  min-width: 42px;
  height: 22px;
  padding: 0 7px;
  font-size: 0.76rem;
}

.editor-view-modes {
  display: none;
}

html[data-initial-view="preview"] .document-workspace {
  grid-template-columns: minmax(0, 1fr);
}

html[data-initial-view="preview"] .editor-panel,
html[data-initial-view="editor"] .preview-panel,
html[data-initial-view="preview"] .splitter,
html[data-initial-view="editor"] .splitter {
  display: none;
}

html[data-initial-view="editor"] .document-workspace {
  grid-template-columns: minmax(0, 1fr);
}

html[data-initial-view]:not([data-initial-view="split"]) .editor-panel,
html[data-initial-view]:not([data-initial-view="split"]) .preview-panel {
  border-radius: var(--radius);
}

.app-shell[data-view="preview"] .document-workspace {
  grid-template-columns: minmax(0, 1fr);
}

.app-shell[data-view="preview"] .editor-panel,
.app-shell[data-view="editor"] .preview-panel,
.app-shell[data-view="preview"] .splitter,
.app-shell[data-view="editor"] .splitter {
  display: none;
}

.app-shell[data-view="editor"] .document-workspace {
  grid-template-columns: minmax(0, 1fr);
}

.app-shell[data-view="editor"] .editor-view-modes {
  display: inline-flex;
}

.app-shell[data-document-mode="text"] .preview-view-modes,
.app-shell[data-document-mode="mindmap"] .preview-view-modes {
  display: none !important;
}

.app-shell:not([data-view="split"]) .editor-panel,
.app-shell:not([data-view="split"]) .preview-panel {
  border-radius: var(--radius);
}

@media (max-width: 860px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr);
    padding: 12px;
    gap: 12px;
  }

  .app-shell[data-file-panel="collapsed"] .workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .file-panel-resizer {
    display: none;
  }

  .document-workspace {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  .splitter {
    display: none;
  }

  .editor-panel,
  .preview-panel {
    border-radius: var(--radius);
  }

  .panel {
    min-height: 46vh;
  }

  .file-panel {
    min-height: 240px;
  }

  .markdown-preview {
    padding: 16px 16px 48px;
  }

  .ai-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .statusbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }
}

@media (max-width: 520px) {
  .tool-button span {
    display: none;
  }

  .tool-button {
    width: 38px;
    padding: 0;
  }

  .segment {
    min-width: 48px;
    padding: 0 8px;
  }
}

@media (max-width: 700px) {
  html,
  body,
  .app-shell {
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
  }

  .app-shell {
    position: relative;
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .workspace,
  .app-shell[data-file-panel="collapsed"] .workspace {
    height: 100%;
    min-height: 0;
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    padding: 6px;
    overflow: hidden;
  }

  .file-panel-resizer,
  .splitter {
    display: none;
  }

  .document-workspace,
  html[data-initial-view="split"] .document-workspace,
  .app-shell[data-view="split"] .document-workspace {
    height: 100%;
    min-height: 0;
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  html[data-initial-view="split"] .preview-panel,
  html[data-initial-view="split"] .splitter,
  .app-shell[data-view="split"] .preview-panel,
  .app-shell[data-view="split"] .splitter {
    display: none;
  }

  .panel,
  .editor-panel,
  .preview-panel {
    height: 100%;
    min-height: 0;
    border-radius: var(--radius);
  }

  .editor-panel,
  .preview-panel {
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  .preview-panel {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .editor-panel .panel-bar,
  .preview-panel .panel-bar {
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
    gap: 7px;
    padding: 8px 6px 7px;
  }

  .editor-panel .panel-bar h2,
  .preview-panel .panel-bar h2 {
    min-width: 0;
    min-height: 42px;
    display: flex;
    align-items: center;
    padding-left: 52px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.88rem;
  }

  .current-file-name {
    display: inline;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--muted);
    font-weight: 500;
  }

  .editor-panel .panel-actions,
  .preview-panel .panel-actions {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    flex: none;
    align-items: center;
    justify-content: stretch;
    overflow: visible;
    padding-bottom: 0;
  }

  .editor-panel .panel-actions {
    display: grid;
    grid-template-columns: repeat(13, 28px);
    grid-template-areas:
      "mode mode mode mode mode mode view view view view . . ."
      "font bold strike color line bullet number ai save new import download pdf";
    justify-content: start;
    gap: 6px;
  }

  .preview-panel .panel-actions {
    display: grid;
    grid-template-columns: repeat(11, 28px);
    grid-template-areas: "view view view view view view copy new download pdf .";
    justify-content: start;
    gap: 6px;
  }

  .panel-action-spacer {
    display: none;
  }

  .document-mode-toggle {
    grid-area: mode;
  }

  .editor-view-modes,
  .preview-panel .preview-view-modes {
    grid-area: view;
  }

  [data-view-mode="split"] {
    display: none !important;
  }

  .panel-bar .segmented {
    width: 100%;
    min-width: 0;
    min-height: 30px;
    display: flex;
    padding: 2px;
  }

  .panel-bar .segment {
    min-width: 0;
    height: 26px;
    flex: 1 1 0;
    padding: 0 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.72rem;
  }

  .editor-panel .panel-actions > .icon-button,
  .editor-panel .panel-actions > .toolbar-menu,
  .preview-panel .panel-actions > .icon-button {
    width: 28px;
    min-width: 28px;
    max-width: 28px;
    justify-self: start;
  }

  .editor-panel .panel-actions > .icon-button,
  .preview-panel .panel-actions > .icon-button,
  .editor-panel .toolbar-menu-trigger {
    width: 28px;
    min-height: 30px;
  }

  .panel-bar .icon-button svg {
    width: 16px;
    height: 16px;
  }

  .text-format-button span,
  .color-button span {
    min-width: 16px;
    height: 16px;
    font-size: 1rem;
  }

  .editor-panel [data-rich-menu="fontSize"] {
    grid-area: font;
  }

  .bold-button {
    grid-area: bold;
  }

  .strike-button {
    grid-area: strike;
  }

  .color-button {
    grid-area: color;
  }

  .editor-panel [data-rich-menu="lineHeight"] {
    grid-area: line;
  }

  .editor-panel [data-action="toggle-bullet-list"] {
    grid-area: bullet;
  }

  .editor-panel [data-action="toggle-numbered-list"] {
    grid-area: number;
  }

  .editor-panel [data-action="ai-optimize"] {
    grid-area: ai;
  }

  .editor-panel [data-action="save-file"] {
    grid-area: save;
  }

  .editor-panel [data-action="new-draft"] {
    grid-area: new;
  }

  .editor-panel [data-action="import"] {
    grid-area: import;
  }

  .editor-panel [data-action="download-md"] {
    grid-area: download;
  }

  .editor-panel [data-action="download-pdf"] {
    grid-area: pdf;
  }

  .preview-panel [data-action="copy-text"] {
    grid-area: copy;
  }

  .preview-panel [data-action="new-draft"] {
    grid-area: new;
  }

  .preview-panel [data-action="download-md"] {
    grid-area: download;
  }

  .preview-panel [data-action="download-pdf"] {
    grid-area: pdf;
  }

  .toolbar-menu-panel {
    position: fixed;
    top: calc(112px + env(safe-area-inset-top, 0px));
    right: 8px;
    z-index: 120;
    max-height: min(320px, 60dvh);
    overflow: auto;
  }

  .app-shell[data-file-panel="expanded"]::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 80;
    background: rgba(15, 23, 42, 0.46);
  }

  .file-panel {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 100;
    width: min(360px, 88vw);
    max-width: 88vw;
    min-height: 0;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    box-shadow: 18px 0 56px rgba(15, 23, 42, 0.28);
  }

  .file-panel .panel-bar {
    min-height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 10px 8px;
  }

  .file-panel .panel-bar h2 {
    min-width: 0;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .file-panel .panel-actions,
  .app-shell[data-file-panel="collapsed"] .file-panel .panel-actions {
    flex: 0 0 auto;
    justify-content: flex-end;
    gap: 5px;
  }

  .file-panel .icon-button {
    width: 30px;
    min-height: 30px;
  }

  .file-tools,
  .file-list {
    padding: 8px;
  }

  .app-shell[data-file-panel="collapsed"] .file-panel {
    top: calc(8px + env(safe-area-inset-top, 0px));
    left: 8px;
    right: auto;
    bottom: auto;
    width: 42px;
    max-width: none;
    height: 42px;
    min-height: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  .app-shell[data-file-panel="collapsed"] .file-panel .panel-bar {
    min-height: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    background: transparent;
  }

  .app-shell[data-file-panel="collapsed"] .file-panel .panel-bar h2,
  .app-shell[data-file-panel="collapsed"] .file-bottom-tools {
    display: none;
  }

  .app-shell[data-file-panel="collapsed"] .file-panel .icon-button[data-action="toggle-file-panel"] {
    width: 42px;
    min-height: 42px;
    border-radius: 10px;
    background: var(--surface);
    border-color: var(--border);
    box-shadow: var(--shadow);
  }

  .ai-draft-bar {
    align-items: flex-start;
    padding: 7px 8px;
  }

  .ai-draft-actions {
    flex-wrap: nowrap;
  }

  #markdownInput,
  .rich-editor {
    padding: 12px;
    font-size: 16px;
    line-height: 1.7;
    -webkit-overflow-scrolling: touch;
  }

  .markdown-preview {
    padding: 12px 12px 48px;
    font-size: 16px;
    line-height: 1.65;
    -webkit-overflow-scrolling: touch;
  }

  .plain-text-preview-host {
    padding: 12px;
  }

  .modal {
    width: min(420px, calc(100vw - 18px));
  }

  .modal-card {
    max-height: calc(100dvh - 24px);
    overflow: auto;
  }

  .ai-grid,
  .user-create-grid,
  .user-password-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .statusbar {
    min-height: 34px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    padding: 6px 10px calc(6px + env(safe-area-inset-bottom, 0px));
    font-size: 0.72rem;
  }

  .statusbar span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

@media (max-width: 700px) {
  body {
    overscroll-behavior: none;
  }

  .app-shell {
    grid-template-rows: minmax(0, 1fr) auto;
    background: var(--surface);
  }

  .app-shell::before,
  .app-shell[data-file-panel="expanded"]::before {
    content: none !important;
    display: none !important;
  }

  .workspace,
  .app-shell[data-file-panel="collapsed"] .workspace {
    height: 100%;
    min-height: 0;
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    padding: 0;
    overflow: hidden;
  }

  .app-shell[data-mobile-screen="detail"] .workspace {
    padding: 6px;
  }

  .app-shell[data-mobile-screen="list"] .document-workspace {
    display: none !important;
  }

  .app-shell[data-mobile-screen="list"] .statusbar {
    display: none;
  }

  .app-shell[data-mobile-screen="list"] .file-panel {
    position: relative;
    inset: auto;
    z-index: auto;
    width: 100%;
    max-width: none;
    height: 100%;
    min-height: 0;
    display: grid;
    grid-template-rows: auto auto auto minmax(0, 1fr);
    border: 0;
    border-radius: 0;
    background: var(--surface);
    box-shadow: none;
  }

  .app-shell[data-mobile-screen="list"] .file-panel .panel-bar {
    min-height: 54px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 9px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
  }

  .app-shell[data-mobile-screen="list"] .file-panel .panel-bar h2 {
    min-width: 0;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 1.02rem;
  }

  .app-shell[data-mobile-screen="list"] .file-panel .panel-actions {
    flex: 0 0 auto;
    display: flex;
    justify-content: flex-end;
    gap: 6px;
  }

  .app-shell[data-mobile-screen="list"] .file-panel [data-action="toggle-file-panel"] {
    display: none !important;
  }

  .app-shell[data-mobile-screen="list"] .mobile-new-draft-button {
    display: inline-grid;
  }

  .preview-panel .mobile-new-draft-button {
    display: inline-grid;
  }

  .app-shell[data-mobile-screen="list"] .file-tools,
  .app-shell[data-mobile-screen="list"] .file-list {
    display: grid;
  }

  .app-shell[data-mobile-screen="list"] .file-tools[hidden] {
    display: none !important;
  }

  .app-shell[data-mobile-screen="list"] .file-tools {
    gap: 7px;
    padding: 9px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
  }

  .app-shell[data-mobile-screen="list"] .file-search {
    min-height: 38px;
    border-radius: 8px;
    background: var(--surface-soft);
  }

  .app-shell[data-mobile-screen="list"] .file-list {
    grid-row: 4;
    min-height: 0;
    overflow: auto;
    padding: 8px;
    -webkit-overflow-scrolling: touch;
  }

  .app-shell[data-mobile-screen="list"] .file-bottom-tools {
    grid-row: 3;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 5px 12px;
    border-top: 0;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
  }

  .app-shell[data-mobile-screen="list"] .tree-row {
    height: 46px;
    grid-template-columns: 30px minmax(0, 1fr) 42px;
    padding-left: calc(var(--tree-depth, 0) * 14px);
    border-radius: 8px;
  }

  .app-shell[data-mobile-screen="list"] .tree-toggle {
    width: 30px;
    height: 46px;
  }

  .app-shell[data-mobile-screen="list"] .tree-label {
    height: 46px;
    grid-template-columns: 22px minmax(0, 1fr);
    gap: 8px;
    padding-right: 6px;
  }

  .app-shell[data-mobile-screen="list"] .tree-label svg {
    width: 18px;
    height: 18px;
  }

  .app-shell[data-mobile-screen="list"] .tree-label span {
    font-size: 0.95rem;
  }

  .app-shell[data-mobile-screen="list"] .tree-menu-button {
    width: 42px;
    height: 46px;
    display: grid;
    place-items: center;
    padding: 0;
    border-radius: 8px;
  }

  .app-shell[data-mobile-screen="list"] .tree-menu-button:hover {
    background: var(--accent-soft);
    color: var(--accent-strong);
  }

  .app-shell[data-mobile-screen="list"] .search-result-item {
    min-height: 52px;
    border-radius: 8px;
    padding: 8px 9px;
  }

  .app-shell[data-mobile-screen="detail"] .file-panel {
    position: fixed;
    top: calc(8px + env(safe-area-inset-top, 0px));
    left: 8px;
    right: auto;
    bottom: auto;
    z-index: 120;
    width: 42px;
    max-width: none;
    height: 42px;
    min-height: 0;
    display: block;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    overflow: visible;
  }

  .app-shell[data-mobile-screen="detail"] .file-panel .panel-bar {
    min-height: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    background: transparent;
  }

  .app-shell[data-mobile-screen="detail"] .file-panel .panel-bar h2,
  .app-shell[data-mobile-screen="detail"] .file-panel .panel-actions > :not([data-action="toggle-file-panel"]),
  .app-shell[data-mobile-screen="detail"] .file-tools,
  .app-shell[data-mobile-screen="detail"] .file-list,
  .app-shell[data-mobile-screen="detail"] .file-bottom-tools {
    display: none !important;
  }

  .app-shell[data-mobile-screen="detail"] .file-panel .icon-button[data-action="toggle-file-panel"] {
    width: 42px;
    min-height: 42px;
    border-radius: 10px;
    background: var(--surface);
    border-color: var(--border);
    box-shadow: var(--shadow);
  }

  .app-shell[data-mobile-screen="detail"] .document-workspace {
    height: 100%;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  .context-menu {
    z-index: 180;
  }
}
