:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --ink: #1f1f1f;
  --muted: #6f6f6f;
  --border: #e6e6e6;
  --accent: #3b3a39;
  --accent-soft: #f0efee;
  --radius: 6px;
  --font-sans: "IBM Plex Sans", "Source Sans 3", "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* {
  box-sizing: border-box;
}

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

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}

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

.brand__name {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 0;
  display: inline-flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn span {
  display: block;
  width: 14px;
  height: 1px;
  background: var(--ink);
}

.omnibox {
  flex: 1;
  display: flex;
  gap: 8px;
  max-width: 520px;
}

.omnibox input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 0;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 14px;
}

.btn {
  border: 1px solid var(--border);
  background: #fff;
  padding: 8px 12px;
  border-radius: 0;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
}

.btn--compact {
  padding: 6px 10px;
  font-size: 12px;
}

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

.btn--ghost {
  background: transparent;
}

.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 0;
  padding: 0;
  flex: 1;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  border-radius: 0;
  padding: 12px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tree {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.sidebar__footer {
  display: flex;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.sidebar__sync {
  margin-top: 12px;
  padding: 10px;
  border: 1px solid var(--border);
  background: #f7f6f4;
  display: grid;
  gap: 8px;
}

.sidebar__sync-actions {
  display: flex;
  gap: 8px;
}

.sidebar__sync-status {
  border-top: 1px solid var(--border);
  padding-top: 6px;
}


.sidebar__sync-status .panel__meta {
  font-size: 11px;
}

.tree__folder {
  padding: 8px 8px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
}

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

.tree__icon {
  width: 16px;
  height: 16px;
  display: inline-block;
  color: var(--muted);
  flex: 0 0 16px;
}

.tree__label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
}

.tree__folder:hover {
  background: var(--accent-soft);
}

.tree__folder.active {
  background: var(--accent);
  color: #fff;
}

.tree__notes {
  list-style: none;
  margin: 6px 0 12px 0;
  padding: 0 0 0 18px;
  display: grid;
  gap: 4px;
}

.tree__note {
  padding: 6px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.tree__note:hover {
  background: var(--accent-soft);
}

.tree__note.active {
  background: #e4e3e1;
}

.panel {
  background: var(--panel);
  border: 0;
  border-left: 1px solid var(--border);
  border-radius: 0;
  padding: 20px 24px 28px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.panel__header--content {
  align-items: flex-start;
  gap: 16px;
}

.panel__actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.panel__actions--inline {
  gap: 6px;
}

.panel__title {
  display: grid;
  gap: 2px;
}

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

#note-title {
  margin: 2px 0 2px;
  line-height: 1.1;
  font-size: 32px;
  font-weight: 700;
}

.note-view {
  overflow-y: auto;
  flex: 1;
}

.empty-state {
  display: grid;
  place-items: center;
  text-align: center;
  padding: 40px 0;
  color: var(--muted);
  gap: 8px;
}

.empty-state h3 {
  margin: 0;
  font-size: 20px;
  color: var(--ink);
}

.empty-state p {
  margin: 0;
  font-size: 14px;
}

.panel--empty {
  justify-content: center;
}

.panel--empty #note-view,
.panel--empty #note-header,
.panel--empty #note-footer,
.panel--empty #note-footer-divider {
  display: none;
}

.panel--empty #empty-state {
  display: grid;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.note-body {
  line-height: 1.6;
  font-size: 15px;
}

.note-body h1,
.note-body h2,
.note-body h3 {
  margin-top: 0.4em;
  margin-bottom: 0.3em;
}

.note-body p {
  margin-top: 0.4em;
  margin-bottom: 0.5em;
}

.note-body ul {
  margin-top: 0.4em;
}

.note-body > :first-child {
  margin-top: 0;
}

.note-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 6px 0 8px;
}

.note-divider--tight {
  margin: 4px 0 4px;
}

.note-divider--footer {
  margin: 16px 0 10px;
}

.note-divider--section {
  margin: 6px 0;
}

.note-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.note-body code {
  font-family: var(--font-mono);
  background: #f3f2f1;
  padding: 2px 6px;
  border-radius: 4px;
}

.note-body pre {
  background: #f3f2f1;
  padding: 12px;
  border-radius: 4px;
  overflow-x: auto;
}

.note-meta {
  margin-top: 24px;
  display: grid;
  gap: 12px;
}

.note-meta h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.chips {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 6px;
}

.chips li {
  background: transparent;
  padding: 8px 10px;
  border-radius: 0;
  border: 1px solid var(--border);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-start;
}

.chips li span {
  flex: 1;
}

.note-editor {
  display: grid;
  gap: 18px;
}

.field {
  display: grid;
  gap: 6px;
}

.field__label {
  font-size: 12px;
  color: var(--muted);
}

.field input,
.field textarea {
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 10px 12px;
  font-size: 14px;
  font-family: var(--font-sans);
}

.field select {
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 10px 12px;
  font-size: 14px;
  font-family: var(--font-sans);
  background: #fff;
}

.progress {
  height: 8px;
  border: 1px solid var(--border);
  background: #f3f2f1;
  width: 100%;
}

.progress__bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s ease;
}

.field__checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--ink);
}

.field__checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.inline-input {
  display: flex;
  gap: 8px;
}

.inline-input input {
  flex: 1;
}

.list--inline {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.list--inline li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 0;
  font-size: 13px;
  background: transparent;
  flex-wrap: wrap;
}

.list__actions {
  display: flex;
  gap: 6px;
}

.item-status {
  width: 100%;
  color: #b34b3a;
  font-size: 12px;
}

.attachment-thumb {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border: 1px solid var(--border);
  cursor: pointer;
}

.image-preview {
  gap: 12px;
}

.image-preview__controls {
  display: flex;
  gap: 8px;
}

.image-preview__canvas {
  background: #fafafa;
  border: 1px solid var(--border);
  height: 60vh;
  display: grid;
  place-items: center;
  overflow: auto;
  touch-action: none;
}

.image-preview__canvas img {
  max-width: 100%;
  max-height: 100%;
  transform-origin: center;
}

.section-card {
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 14px;
  background: #fff;
}

.section-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-card__header h4 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.editor-grid {
  display: grid;
  gap: 14px;
}

.dialog {
  border: none;
  padding: 0;
  border-radius: 0;
  width: min(420px, 90vw);
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 24px 40px rgba(0, 0, 0, 0.2);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.2);
}

.dialog__form {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.dialog__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.eyebrow {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.is-hidden {
  display: none;
}

@media (max-width: 900px) {
  .topbar {
    flex-wrap: wrap;
  }

  .omnibox {
    order: 3;
    width: 100%;
    max-width: none;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 64px;
    left: 0;
    bottom: 0;
    width: 80vw;
    max-width: 320px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 20;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  body.sidebar-open::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.2);
    z-index: 15;
  }
}

@media (max-width: 600px) {
  .topbar {
    padding: 12px 16px;
  }

  .layout {
    padding: 16px;
  }

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

  .panel__actions {
    width: 100%;
  }

  .panel__actions .btn {
    flex: 1;
  }
}
