:root {
  color-scheme: light;
  --ink: #181714;
  --muted: #6f6b61;
  --line: #ded8cb;
  --paper: #fbfaf6;
  --panel: #f2eee5;
  --panel-strong: #fffdf8;
  --accent: #2f6b57;
  --accent-strong: #204a3d;
  --danger: #9b2f2f;
  --shadow: 0 18px 60px rgba(41, 36, 28, 0.14);
  font-family: "Georgia", "Times New Roman", "Noto Serif SC", serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(rgba(47, 107, 87, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(47, 107, 87, 0.05) 1px, transparent 1px),
    var(--paper);
  background-size: 32px 32px;
  color: var(--ink);
}

body.theme-dark {
  color-scheme: dark;
  --ink: #f4efe5;
  --muted: #bcb2a2;
  --line: #3a3d36;
  --paper: #151713;
  --panel: #20231d;
  --panel-strong: #252920;
  --accent: #82b99f;
  --accent-strong: #a8d8be;
  --danger: #e09090;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.34);
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: var(--paper);
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

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

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

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

.login-panel {
  width: min(520px, 100%);
  padding: clamp(28px, 6vw, 56px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  box-shadow: var(--shadow);
}

h1 {
  margin: 0;
  font-size: clamp(32px, 8vw, 58px);
  line-height: 1;
  letter-spacing: 0;
}

.login-form {
  margin-top: 32px;
}

.login-form label {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
}

.password-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel-strong) 88%, transparent);
  color: var(--ink);
  outline: none;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.password-row input {
  min-height: 46px;
  padding: 0 14px;
}

.form-message {
  min-height: 24px;
  margin: 14px 0 0;
  color: var(--danger);
}

.workspace-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
}

.sidebar {
  min-height: 100vh;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.editor-topbar,
.list-actions,
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.workspace-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.tab-button {
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
}

.tab-button.is-active {
  background: var(--accent);
  color: var(--paper);
}

.list-actions {
  justify-content: flex-end;
  gap: 8px;
}

.list-actions button,
.ghost-button,
.danger-button,
.drag-handle {
  background: transparent;
  color: var(--accent);
}

.list-actions button {
  min-height: 32px;
  padding: 0 10px;
  border-radius: 7px;
  font-size: 14px;
}

.list-actions button:hover,
.ghost-button:hover,
.drag-handle:hover {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

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

.danger-button:hover {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

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

.document-item {
  min-height: 72px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  align-items: stretch;
  border: 1px solid transparent;
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel-strong) 72%, transparent);
  color: var(--ink);
  position: relative;
}

.document-item:hover,
.document-item.is-active {
  border-color: var(--accent);
  background: var(--panel-strong);
}

.document-item.is-drop-target {
  outline: 2px dashed var(--accent);
}

.document-item.is-empty {
  display: block;
  padding: 14px;
  color: var(--muted);
}

.document-main {
  min-width: 0;
  min-height: 70px;
  padding: 12px;
  border: 0;
  border-radius: 8px 0 0 8px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.document-main:hover {
  background: transparent;
}

.sort-cell {
  position: relative;
  display: grid;
}

.drag-handle {
  min-height: 70px;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0 8px 8px 0;
  font-size: 20px;
  cursor: grab;
  touch-action: none;
}

.drag-handle:active {
  cursor: grabbing;
}

.sort-actions {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 8;
  min-width: 78px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
}

.sort-actions.is-open {
  display: grid;
  gap: 4px;
}

.sort-step {
  min-height: 32px;
  padding: 0 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--accent);
  font-size: 14px;
}

.sort-delete {
  color: var(--danger);
}

.sort-delete:hover {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

.document-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-meta {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.editor-pane {
  min-width: 0;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.editor-topbar {
  min-height: 50px;
  padding: 8px 18px;
  position: sticky;
  top: 0;
  z-index: 3;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  gap: 8px;
}

.editor-topbar .save-state {
  margin-left: 0;
  text-align: right;
}

.save-state {
  min-width: 0;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.save-state.is-saving {
  color: #9a741f;
}

.save-state.is-saved {
  color: var(--accent);
}

.save-state.is-error {
  color: var(--danger);
}

.editor-toolbar {
  min-height: 34px;
  gap: 6px;
  flex: 0 0 auto;
  margin-left: auto;
}

.icon-button {
  width: 34px;
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--accent);
  font-size: 18px;
  line-height: 1;
}

.icon-button:hover {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.workspace-switch-button {
  min-width: 46px;
  min-height: 34px;
  padding: 0 10px;
  border-radius: 7px;
  background: transparent;
  color: var(--accent);
  font-size: 14px;
  white-space: nowrap;
}

.workspace-switch-button:hover {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.is-syncing::before {
  content: "";
  width: 11px;
  height: 11px;
  margin-right: 5px;
  border: 2px solid color-mix(in srgb, var(--accent) 24%, transparent);
  border-top-color: var(--accent);
  border-radius: 999px;
  display: inline-block;
  vertical-align: -1px;
  animation: spin 0.7s linear infinite;
}

.save-state.is-saving::before {
  content: "";
  width: 12px;
  height: 12px;
  margin-right: 6px;
  border: 2px solid color-mix(in srgb, #9a741f 24%, transparent);
  border-top-color: #9a741f;
  border-radius: 999px;
  display: inline-block;
  vertical-align: -2px;
  animation: spin 0.7s linear infinite;
}

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

.tool-dialog {
  width: min(420px, calc(100vw - 36px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--ink);
  box-shadow: var(--shadow);
  position: fixed;
  top: 58px;
  right: 18px;
  margin: 0;
}

.tool-dialog::backdrop {
  background: rgba(24, 23, 20, 0.28);
}

.tool-dialog-form {
  display: grid;
  gap: 10px;
  padding: 18px;
}

.tool-dialog h2 {
  margin: 0 0 4px;
  font-size: 22px;
  line-height: 1.15;
}

.tool-dialog label {
  color: var(--muted);
  font-size: 14px;
}

.dialog-input {
  min-height: 40px;
  padding: 0 12px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.dialog-actions button {
  min-height: 34px;
  padding: 0 12px;
}

.editor-card {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: clamp(18px, 4vw, 46px);
}

.title-input {
  padding: 0 0 18px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  font-size: clamp(30px, 5vw, 62px);
  line-height: 1.08;
}

.title-input:focus {
  box-shadow: none;
}

.body-input {
  min-height: 480px;
  padding: 24px 0 60px;
  resize: none;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: 20px;
  line-height: 1.8;
}

.body-input:focus {
  box-shadow: none;
}

.mobile-only {
  display: none;
}

@media (max-width: 760px) {
  .workspace-screen {
    display: block;
  }

  .sidebar,
  .editor-pane {
    min-height: 100vh;
  }

  .sidebar {
    border-right: 0;
  }

  .editor-pane {
    display: none;
  }

  .workspace-screen.editor-open .sidebar {
    display: none;
  }

  .workspace-screen.editor-open .editor-pane {
    display: grid;
  }

  .mobile-only {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .editor-topbar {
    align-items: center;
    flex-wrap: nowrap;
    padding: 8px 10px;
  }

  .editor-toolbar {
    gap: 5px;
    min-width: 0;
  }

  .icon-button {
    width: 32px;
    min-width: 32px;
    min-height: 32px;
    font-size: 17px;
  }

  .editor-toolbar button {
    flex: 0 0 auto;
  }

  .save-state {
    max-width: 70px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .workspace-switch-button {
    min-width: 42px;
    min-height: 32px;
    padding: 0 8px;
    font-size: 13px;
  }

  .tool-dialog {
    width: auto;
    top: 52px;
    right: 10px;
    left: 10px;
  }

  .editor-card {
    padding: 18px;
  }

  .title-input {
    font-size: 32px;
  }

  .body-input {
    font-size: 18px;
  }

  .password-row {
    grid-template-columns: 1fr;
  }
}
