:root {
  --topbar-height: 64px;
  --reader-head-height: 64px;
  --workspace-divider: #e5e7eb;
  --workspace-accent: #15803d;
  --workspace-accent-muted: #eff6ff;
  --workspace-muted: #64748b;
}

.page {
  max-width: none;
  min-height: 100dvh;
  margin: 0;
  padding: 0;
}

#appView:not(.app-dimmed) {
  display: grid;
  width: 100%;
  height: 100dvh;
  grid-template-rows: var(--topbar-height) minmax(0, 1fr);
  overflow: hidden;
  background: #ffffff;
}

.workspace-layout,
.workspace-navigation,
.workspace-feed,
.workspace-reader,
.reader-document,
.note-list-scroll {
  min-width: 0;
  min-height: 0;
}

.workspace-layout {
  display: grid;
  grid-template-columns: 216px 360px minmax(0, 1fr);
  align-items: stretch;
  overflow: hidden;
}

.workspace-navigation,
.workspace-feed,
.workspace-reader {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #ffffff;
}

.workspace-navigation,
.workspace-feed {
  border-right: 1px solid var(--workspace-divider);
}

.workspace-navigation {
  display: flex;
  flex-direction: column;
  padding: 14px 10px 12px;
}

.navigation-head,
.list-head,
.list-head-title,
.list-head-actions,
.reader-head,
.topbar-identity,
.topbar-actions,
.reader-actions,
.note-row-labels,
.note-row-dates {
  display: flex;
  align-items: center;
}

.navigation-head {
  min-height: 44px;
  justify-content: space-between;
  padding: 0 8px 10px;
  color: #0f172a;
  font-size: 16px;
}

.workspace-navigation .navigation-close,
#navigationBtn {
  display: none;
}

.navigation-scroll {
  min-height: 0;
  overflow-y: auto;
}

.navigation-label {
  margin: 16px 8px 6px;
  color: var(--workspace-muted);
  font-size: 12px;
  font-weight: 700;
}

.folder-nav {
  display: grid;
  gap: 2px;
  padding: 0;
  overflow: visible;
}

.folder-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 36px;
  margin-top: 14px;
}

.folder-section-head .navigation-label {
  margin: 0 8px;
}

.folder-add-btn {
  width: 36px;
  height: 36px;
  min-height: 36px;
  color: var(--workspace-muted);
}

.nav-item-icon {
  display: inline-flex;
  flex: 0 0 22px;
  align-items: center;
  justify-content: center;
  color: currentColor;
  font-size: 13px;
  font-weight: 700;
}

.nav-item-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-item-count {
  flex: 0 0 auto;
  margin-left: auto;
  color: #94a3b8;
  font-size: 12px;
  font-weight: 500;
}

.folder-chip,
.folder-subfilter,
.navigation-command {
  position: relative;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  overflow: hidden;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #475569;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.folder-nav-row {
  display: flex;
  align-items: center;
}

.folder-nav-row .folder-chip {
  flex: 1 1 auto;
  min-width: 0;
}

.folder-toggle {
  flex: 0 0 32px;
  width: 32px;
  height: 36px;
  border: 0;
  background: transparent;
  color: #64748b;
  font-size: 20px;
  cursor: pointer;
}

.folder-toggle:hover,
.folder-toggle:focus-visible {
  color: #166534;
  background: #f0fdf4;
}

.folder-chip,
.folder-subfilter,
.navigation-command {
  display: flex;
  align-items: center;
  gap: 8px;
}

.folder-chip:hover,
.folder-subfilter:hover,
.navigation-command:hover,
.note-list-row:hover {
  background: #f8fafc;
}

.folder-chip.is-active,
.folder-subfilter.is-active {
  background: #f0fdf4;
  color: #166534;
  font-weight: 700;
}

.folder-chip.is-active::before,
.folder-subfilter.is-active::before,
.note-list-row.is-selected::before {
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 0;
  width: 3px;
  border-radius: 2px;
  background: var(--workspace-accent);
  content: "";
}

.folder-subfilters {
  display: grid;
  gap: 2px;
  padding-left: 22px;
}

.folder-subfilters[hidden] {
  display: none;
}

.folder-subfilter {
  min-height: 44px;
  padding-left: 14px;
  font-size: 13px;
}

.navigation-command {
  margin-top: 12px;
  border-top: 1px solid var(--workspace-divider);
  border-radius: 0;
  color: #334155;
}

.navigation-manage {
  margin-bottom: 8px;
  border-top: 1px solid var(--workspace-divider);
}

.folder-empty {
  padding: 8px 12px;
  color: #94a3b8;
  font-size: 12px;
}

.workspace-feed {
  display: flex;
  flex-direction: column;
}

.list-head {
  min-height: 72px;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--workspace-divider);
}

.list-head-title,
.list-head-actions {
  min-width: 0;
}

.list-head-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.list-head-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.sort-control {
  position: relative;
}

.sort-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 10;
  display: grid;
  min-width: 128px;
  padding: 4px;
  border: 1px solid var(--workspace-divider);
  border-radius: 6px;
  background: #ffffff;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.12);
}

.sort-menu button {
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #334155;
  text-align: left;
  cursor: pointer;
}

.sort-menu button:hover,
.sort-menu button:focus-visible {
  background: #f0fdf4;
  color: #166534;
}

.feed-new-btn {
  color: var(--workspace-accent);
}

.list-head h2 {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  color: #0f172a;
  font-size: 18px;
  line-height: 1.3;
}

#noteCount {
  flex: 0 0 auto;
  color: var(--workspace-muted);
  font-size: 12px;
}

.note-list-scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.note-list {
  display: block;
}

.note-list-row {
  position: relative;
  display: block;
  width: 100%;
  padding: 14px 20px;
  overflow: hidden;
  border: 0;
  border-bottom: 1px solid var(--workspace-divider);
  background: #ffffff;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.note-list-row.is-selected {
  background: var(--workspace-accent-muted);
}

.note-list-row.decrypt-failed {
  background: #fffbeb;
  color: #92400e;
}

.note-row-title,
.note-row-snippet,
.note-row-label,
.note-row-dates,
.reader-path,
.reader-meta {
  overflow-wrap: anywhere;
}

.note-row-title {
  display: -webkit-box;
  margin-bottom: 5px;
  overflow: hidden;
  color: #111827;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.note-list-row.decrypt-failed .note-row-title {
  color: #92400e;
}

.note-row-snippet {
  display: -webkit-box;
  margin-bottom: 9px;
  overflow: hidden;
  color: #64748b;
  font-size: 13px;
  letter-spacing: 0;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.note-row-snippet.is-empty {
  color: #94a3b8;
}

.note-row-labels {
  gap: 6px;
  min-width: 0;
}

.note-row-label {
  max-width: 48%;
  overflow: hidden;
  color: #475569;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-row-label + .note-row-label::before {
  margin-right: 6px;
  color: #cbd5e1;
  content: "·";
}

.note-row-dates {
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  color: #94a3b8;
  font-size: 11px;
}

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

.workspace-reader {
  position: relative;
}

.reader-empty-state {
  display: grid;
  min-height: 100%;
  place-content: center;
  padding: 32px;
  color: var(--workspace-muted);
  text-align: center;
}

.reader-empty-state h2 {
  margin: 0 0 6px;
  color: #334155;
  font-size: 18px;
}

.reader-empty-state p {
  margin: 0;
}

.reader-detail {
  min-height: 100%;
}

.reader-detail.is-editing .reader-actions,
.reader-detail.is-editing .reader-back {
  display: none;
}

.reader-head {
  position: sticky;
  top: 0;
  z-index: 5;
  min-height: 64px;
  margin: 0;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--workspace-divider);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
}

.reader-head > div:nth-child(2) {
  min-width: 0;
  flex: 1;
}

#readerPath {
  overflow: hidden;
  color: #64748b;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#readerMeta {
  overflow: hidden;
  color: #94a3b8;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-actions {
  flex: 0 0 auto;
  gap: 6px;
}

.reader-action-btn {
  color: #475569;
  font-size: 18px;
}

.reader-action-btn:hover,
.reader-action-btn:focus-visible {
  background: #f0fdf4;
  color: #166534;
}

.danger-icon:hover,
.danger-icon:focus-visible {
  background: #fef2f2;
  color: #b91c1c;
}

.reader-document {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 28px 48px 64px;
}

.reader-editor {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 24px 48px 64px;
}

.reader-editor-card {
  width: 100%;
  max-height: none;
  padding: 0;
  overflow: visible;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.reader-editor-card .document-toolbar {
  margin-left: -48px;
  margin-right: -48px;
  padding-left: 48px;
  padding-right: 48px;
}

.reader-editor-card .composer-action-bar {
  margin-left: -48px;
  margin-right: -48px;
  padding-left: 48px;
  padding-right: 48px;
}

.reader-editor-card .textarea {
  min-height: min(56dvh, 640px);
}

.reader-title {
  margin: 0 0 22px;
  overflow-wrap: anywhere;
  color: #111827;
  font-size: 32px;
  letter-spacing: 0;
  line-height: 1.2;
}

.markdown-body,
.markdown-body > *,
.password-field,
.password-reader-value {
  min-width: 0;
  overflow-wrap: anywhere;
}

.markdown-body {
  color: #334155;
  line-height: 1.8;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  overflow-wrap: anywhere;
}

.markdown-body pre {
  max-width: 100%;
  overflow-x: auto;
  overflow-wrap: normal;
  border-radius: 6px;
}

.markdown-body img {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: min(70dvh, 720px);
  border-radius: 6px;
  object-fit: contain;
}

.password-fields {
  display: grid;
  gap: 0;
}

.markdown-password-block {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
  padding: 12px 14px;
  border-top: 1px solid var(--workspace-divider);
  border-bottom: 1px solid var(--workspace-divider);
  background: #f8fafc;
}

.password-block-label {
  color: #475569;
  font-size: 13px;
  font-weight: 700;
}

.password-block-input {
  min-width: 0;
}

.password-block-value {
  min-width: 0;
  overflow: hidden;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: copy;
  font: inherit;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.password-block-input[readonly] {
  cursor: default;
}

.password-block-remove,
.markdown-password-block .password-visibility-toggle {
  width: 44px;
  height: 44px;
}

@media (max-width: 640px) {
  .markdown-password-block {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .password-block-remove {
    grid-column: 2 / -1;
    width: auto;
  }
}

.password-reader-field {
  display: grid;
  grid-template-columns: minmax(96px, 150px) minmax(0, 1fr) auto;
  align-items: center;
  gap: 20px;
  padding: 16px 0;
  border: 0;
  border-bottom: 1px solid var(--workspace-divider);
  border-radius: 0;
  background: transparent;
}

.password-reader-field .password-field-label {
  min-width: 0;
  overflow: hidden;
  color: #64748b;
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.password-reader-field .password-reader-value {
  grid-column: 2;
  grid-row: 1;
  width: 100%;
  display: block;
  min-width: 0;
  min-height: 44px;
  margin: 0;
  padding: 0;
  appearance: none;
  border: 0;
  background: transparent;
  overflow-wrap: anywhere;
  color: #1f2937;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.7;
  text-align: left;
  white-space: pre-wrap;
  cursor: copy;
}

.password-reader-field .password-reader-value:focus-visible {
  outline: 2px solid var(--workspace-accent);
  outline-offset: 2px;
}

.password-reader-actions {
  grid-column: 3;
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
}

.password-reader-field .password-field-action {
  width: auto;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0 8px;
  color: #64748b;
  font-size: 12px;
}

.password-reader-field .password-field-action:hover,
.password-reader-field .password-field-action:focus-visible {
  background: #f0fdf4;
  color: #166534;
}

.password-visibility-toggle::before {
  content: '\1F441';
  font-size: 16px;
}

.password-reader-field.is-multiline {
  align-items: start;
}

.password-reader-field.is-multiline .password-reader-value {
  min-height: 72px;
  padding: 8px 0;
}

.more-menu {
  position: fixed;
  top: calc(var(--topbar-height) + var(--reader-head-height) + 8px);
  right: 16px;
  z-index: 6;
  padding: 8px;
  border: 1px solid var(--workspace-divider);
  border-radius: 6px;
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}

.topbar {
  display: flex;
  min-width: 0;
  height: var(--topbar-height);
  min-height: var(--topbar-height);
  margin: 0;
  padding: 0 16px;
  border: 0;
  border-bottom: 1px solid var(--workspace-divider);
  border-radius: 0;
  box-shadow: none;
}

.topbar-identity {
  min-width: 0;
  gap: 10px;
}

.topbar-title {
  overflow: hidden;
  color: #111827;
  font-size: 17px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-subtitle {
  margin-top: 0;
  color: var(--workspace-muted);
  font-size: 12px;
}

.topbar-actions {
  min-width: 0;
  gap: 8px;
  flex: 1;
  justify-content: flex-end;
}

.search-wrap {
  width: min(360px, 42vw);
}

.icon-btn {
  display: inline-grid;
  width: 40px;
  min-width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  place-items: center;
  background: transparent;
  color: #475569;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.icon-btn:hover {
  background: #f1f5f9;
}

.btn,
.input,
.textarea {
  border-radius: 6px;
}

.btn {
  min-height: 40px;
  box-shadow: none;
}

.btn.secondary {
  border: 1px solid #dbe1e8;
  background: #ffffff;
}

.input,
.textarea {
  border-color: #dbe1e8;
}

.navigation-backdrop {
  display: none;
}

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

.search-highlight {
  border-radius: 2px;
  background: #fef3c7;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 2px solid var(--workspace-accent);
  outline-offset: 2px;
}

.empty-feed {
  margin: 20px;
  border-radius: 6px;
}

.decrypt-warning {
  margin: 14px 20px 0;
  border-radius: 6px;
}

.reader-back {
  display: none;
}

@media (min-width: 768px) and (max-width: 1179px) {
  .workspace-layout {
    grid-template-columns: minmax(320px, 360px) minmax(0, 1fr);
  }

  .workspace-navigation {
    position: fixed;
    inset: var(--topbar-height) auto 0 0;
    z-index: 50;
    width: min(320px, calc(100vw - 48px));
    transform: translateX(-100%);
    transition: transform 160ms ease;
    box-shadow: 12px 0 28px rgba(15, 23, 42, 0.12);
  }

  .workspace-navigation.is-open {
    transform: translateX(0);
  }

  #navigationBtn,
  .workspace-navigation .navigation-close {
    display: inline-grid;
  }

  .navigation-backdrop:not(.hidden) {
    position: fixed;
    inset: var(--topbar-height) 0 0;
    z-index: 45;
    display: block;
    border: 0;
    background: rgba(15, 23, 42, 0.22);
  }

  .reader-document {
    padding: 28px 32px 56px;
  }
}

@media (max-width: 767px) {
  :root {
    --topbar-height: 56px;
    --reader-head-height: 56px;
  }

  #appView:not(.app-dimmed) {
    grid-template-rows: var(--topbar-height) minmax(0, 1fr);
  }

  .topbar {
    gap: 8px;
    padding: 0 8px;
    flex-wrap: nowrap;
  }

  .topbar-identity {
    flex: 0 0 auto;
  }

  .topbar-title,
  .topbar-subtitle {
    display: none;
  }

  .topbar-actions {
    gap: 6px;
  }

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

  .search {
    min-height: 40px;
    padding-left: 10px;
  }

  .topbar-new-btn,
  #settingsBtn {
    min-width: 44px;
    padding: 0 8px;
    font-size: 12px;
  }

  #settingsBtn.settings-trigger {
    width: 40px;
    min-width: 40px;
    padding: 0;
  }

  #settingsBtn .settings-btn-label {
    display: none;
  }

  #settingsBtn .settings-btn-icon {
    display: inline;
    font-size: 18px;
    line-height: 1;
  }

  #navigationBtn,
  .workspace-navigation .navigation-close {
    display: inline-grid;
  }

  .workspace-layout {
    display: block;
    overflow: hidden;
  }

  .workspace-feed,
  .workspace-reader {
    width: 100%;
    height: calc(100dvh - var(--topbar-height));
    border: 0;
  }

  .workspace-layout[data-active-view="list"] .workspace-reader,
  .workspace-layout[data-active-view="reader"] .workspace-feed {
    display: none;
  }

  .workspace-navigation {
    position: fixed;
    inset: 0;
    z-index: 60;
    width: 100%;
    transform: translateX(-100%);
    transition: transform 160ms ease;
    box-shadow: none;
  }

  .workspace-navigation.is-open {
    transform: translateX(0);
  }

  .navigation-backdrop:not(.hidden) {
    display: none;
  }

  .list-head {
    min-height: 60px;
    padding: 12px 16px;
  }

  .note-list-row {
    padding: 14px 16px;
  }

  .reader-head {
    min-height: 56px;
    padding: 8px 10px;
    gap: 8px;
  }

  .reader-head > div:nth-child(2) {
    min-width: 0;
  }

  .reader-back {
    display: inline-grid;
  }

  .reader-actions {
    gap: 2px;
  }

  .reader-action-btn {
    min-width: 40px;
    min-height: 40px;
    padding: 0 6px;
    border: 0;
    background: transparent;
    color: #334155;
    font-size: 12px;
  }

  .reader-document {
    padding: 20px 16px calc(40px + env(safe-area-inset-bottom));
  }

  .reader-editor {
    padding: 14px 16px calc(24px + env(safe-area-inset-bottom));
  }

  .reader-editor-card .textarea {
    min-height: 54dvh;
  }

  .reader-editor-card .document-editor {
    min-height: 54dvh;
  }

  .reader-title {
    font-size: 26px;
  }

  .workspace-reader,
  .reader-document,
  .password-fields,
  .password-reader-field {
    min-width: 0;
    max-width: 100%;
  }

  .password-reader-field {
    grid-template-columns: minmax(54px, 72px) minmax(0, 1fr) auto;
    align-items: start;
    gap: 8px;
    padding: 14px 0;
  }

  .password-reader-field .password-reader-label {
    grid-column: 1;
    grid-row: 1;
    font-size: 12px;
    line-height: 1.5;
    white-space: nowrap;
  }

  .password-reader-field .password-reader-value {
    grid-column: 2;
    grid-row: 1;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .password-reader-actions {
    grid-column: 3;
    grid-row: 1;
    justify-content: flex-end;
    width: auto;
  }

  .password-reader-field.is-multiline .password-reader-value {
    width: 100%;
    min-height: 88px;
  }

  .more-menu {
    right: 8px;
  }

  .fab-new {
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
  }

  #editorModal {
    display: block;
    padding: 0;
    background: #ffffff;
  }

  #editorModal .modal-card {
    width: 100%;
    min-height: 0;
    height: 100dvh;
    max-height: none;
    padding: max(12px, env(safe-area-inset-top)) 14px calc(12px + env(safe-area-inset-bottom));
    overflow-y: auto;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  #editorModal .textarea {
    min-height: 46dvh;
    font-size: 16px;
  }

  .document-toolbar {
    margin-bottom: 10px;
    padding-left: 0;
    padding-right: 0;
  }

  .reader-editor-card .document-toolbar {
    margin-left: -16px;
    margin-right: -16px;
    padding-left: 16px;
    padding-right: 16px;
  }

  .reader-editor-card .composer-action-bar {
    margin-left: -16px;
    margin-right: -16px;
    padding-left: 16px;
    padding-right: 16px;
  }

  .composer-action-bar {
    margin-left: -14px;
    margin-right: -14px;
    padding-left: 16px;
    padding-right: 16px;
  }

  .btn,
  .icon-btn,
  .folder-chip,
  .folder-subfilter,
  .navigation-command {
    min-height: 44px;
  }

  .folder-chip:focus-visible,
  .folder-subfilter:focus-visible {
    outline: 2px solid var(--workspace-accent);
    outline-offset: -2px;
  }
}
