:root {
  --bg: #fffdf8;
  --surface: #fffdf8;
  --surface-raised: rgba(255, 253, 248, 0.92);
  --surface-soft: #fffdf8;
  --text: #20242c;
  --muted: #687062;
  --line: #e5dece;
  --line-strong: #d5cbb9;
  --accent: #2f6f5e;
  --accent-soft: #e4f0e9;
  --accent-line: #a8c7b8;
  --select: #dbeafe;
  --select-border: #6aa7e8;
  --edit-border: #c9c0ae;
  --edit-ring: rgba(106, 167, 232, 0.18);
  --indent: 22px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow-soft: 0 12px 32px rgba(72, 59, 39, 0.10);
  --shadow-strong: 0 28px 70px rgba(42, 35, 25, 0.22);
  --font: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

body.modal-open {
  overflow: hidden;
}

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

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 4px var(--edit-ring);
}

a {
  color: #1f6f8b;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.app {
  --app-pad: 24px;
  max-width: 1160px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px var(--app-pad) 36px;
  background: var(--surface);
}

.topbar {
  position: relative;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
  padding: 10px;
  border: 1px solid rgba(213, 203, 185, 0.76);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(14px);
}

.search-stack {
  position: relative;
  display: grid;
  flex: 1;
  min-width: 220px;
  max-width: 720px;
  gap: 8px;
}

.search-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-wrap {
  position: relative;
  display: block;
  flex: 1;
  max-width: none;
}

.search-icon {
  position: absolute;
  top: 50%;
  left: 12px;
  width: 18px;
  height: 18px;
  color: #7c897d;
  transform: translateY(-50%);
  pointer-events: none;
}

.search-icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

.search-input {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  height: 40px;
  padding: 0 148px 0 38px;
  outline: 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.search-wrap:focus-within .search-input {
  border-color: var(--accent-line);
  background: #fff;
  box-shadow: 0 0 0 4px var(--edit-ring);
}

.search-clear-btn {
  position: absolute;
  top: 8px;
  right: 112px;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  background: #eef0e8;
  color: #5b635e;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  display: grid;
  place-items: center;
  padding: 0 0 2px;
}

.search-clear-btn:hover {
  background: #e1e6db;
  color: var(--text);
}

.search-scope-select {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 102px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 10px;
  appearance: none;
  background-color: var(--accent-soft);
  background-image:
    linear-gradient(45deg, transparent 50%, #607469 50%),
    linear-gradient(135deg, #607469 50%, transparent 50%);
  background-position:
    calc(100% - 13px) 12px,
    calc(100% - 8px) 12px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  color: #315f51;
  font-size: 12px;
  font-weight: 700;
  padding: 0 24px 0 10px;
  cursor: pointer;
}

.search-scope-select:hover {
  border-color: var(--accent-line);
  background-color: #eef7f2;
}

.save-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  padding: 0 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.save-status-dot {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #e8ecdf;
  color: #586457;
  font-size: 11px;
  line-height: 1;
}

.save-status-saved {
  color: #1f6f45;
}

.save-status-saved .save-status-dot {
  background: #dff3e4;
  color: #1f7b4a;
}

.save-status-saving,
.save-status-unsaved {
  color: #8a6218;
}

.save-status-saving .save-status-dot,
.save-status-unsaved .save-status-dot {
  background: #fff0a8;
  color: #8a6218;
}

.save-status-error {
  color: #8b2e2e;
}

.save-status-error .save-status-dot {
  background: #fff4f1;
  color: #8b2e2e;
}

.search-results {
  position: absolute;
  top: 48px;
  left: 0;
  z-index: 60;
  width: min(620px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  max-height: min(52vh, 420px);
  overflow: auto;
}

.search-result-empty,
.search-result {
  display: grid;
  width: 100%;
  border: 0;
  border-top: 1px solid #eee8db;
  background: var(--surface);
  padding: 10px 12px;
  text-align: left;
}

.search-result-summary {
  padding: 8px 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid #eee8db;
}

.search-result-empty:first-child,
.search-result:first-child {
  border-top: 0;
}

.search-result {
  cursor: pointer;
  gap: 4px;
}

.search-result:hover,
.search-result-active {
  background: #f1f7f3;
}

.search-result-title {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  word-break: break-word;
}

.search-preview-link {
  color: #0759c7;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.search-hit {
  background: #fff0a8;
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

.search-result-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  word-break: break-word;
}

.search-result-empty {
  color: var(--muted);
  font-size: 14px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-left: auto;
}

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

.toolbar-select,
.nav-icon-btn {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 253, 248, 0.88);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
  transition: transform 120ms ease, border-color 140ms ease, box-shadow 140ms ease, background 140ms ease, color 140ms ease;
}

.nav-icon-btn {
  padding: 0 12px;
  cursor: pointer;
}

.toolbar-select:hover,
.nav-icon-btn:hover:not(:disabled) {
  border-color: var(--accent-line);
  background: #fff;
  box-shadow: 0 8px 18px rgba(72, 59, 39, 0.08);
  transform: translateY(-1px);
}

.nav-icon-btn:active:not(:disabled) {
  transform: translateY(0);
}

.nav-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  padding: 0;
}

.nav-icon-btn svg {
  width: 16px;
  height: 16px;
  display: block;
}

.icon-emoji {
  display: inline-block;
  line-height: 1;
}

.nav-icon-btn .icon-emoji {
  font-size: 17px;
}

.toolbar-menu {
  position: absolute;
  top: 46px;
  right: 0;
  z-index: 45;
  min-width: 222px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  padding: 6px;
}

.toolbar-menu-section {
  padding: 8px 10px 10px;
}

.toolbar-menu-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.toolbar-menu-value {
  margin-top: 4px;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  word-break: break-word;
}

.toolbar-menu-divider {
  height: 1px;
  margin: 4px 6px;
  background: #eee8db;
}

.nav-icon-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.toolbar-select {
  min-width: 110px;
  padding: 0 28px 0 12px;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, #7c897d 50%),
    linear-gradient(135deg, #7c897d 50%, transparent 50%);
  background-position:
    calc(100% - 14px) 14px,
    calc(100% - 9px) 14px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

#listSelect {
  width: clamp(128px, 18vw, 230px);
}

.header {
  position: relative;
  z-index: 30;
  margin: 0 0 10px;
  padding: 18px 0 14px;
}

.header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.header::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0 calc(50% - 50vw);
  background: var(--surface-soft);
  border-top: 1px solid transparent;
  border-bottom: 1px solid rgba(213, 203, 185, 0.58);
}

.title {
  display: block;
  flex: 1;
  min-width: 0;
  min-height: 1.2em;
  height: auto;
  border: 1px solid transparent;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 40px;
  line-height: 1.06;
  letter-spacing: -0.04em;
  font-weight: 600;
  padding: 4px 6px;
  margin: -4px -6px;
  border-radius: var(--radius-sm);
  resize: none;
  overflow: hidden;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  text-overflow: clip;
}

.title-actions {
  position: relative;
  flex: 0 0 auto;
  padding-top: 4px;
  z-index: 31;
}

.title-menu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: rgba(255, 253, 248, 0.46);
  color: #6c756c;
  padding: 0;
}

.title-menu-btn:hover,
.title-menu-btn[aria-expanded="true"] {
  border-color: var(--accent-line);
  background: rgba(255, 253, 248, 0.92);
  color: var(--text);
}

.title-menu-btn svg {
  width: 16px;
  height: 16px;
  display: block;
}

.title-menu {
  position: absolute;
  top: 40px;
  right: 0;
  z-index: 40;
  min-width: 188px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  padding: 6px;
}

.title:focus {
  background: var(--surface);
  border-color: var(--edit-border);
  box-shadow: 0 0 0 4px var(--edit-ring);
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  margin: 0 0 14px;
  padding: 0 4px;
  font-size: 14px;
  color: var(--muted);
}

.breadcrumbs:empty {
  display: none;
}

.crumb {
  border: 0;
  background: transparent;
  padding: 2px 4px;
  color: inherit;
  border-radius: 6px;
}

.crumb:hover {
  color: var(--text);
  background: rgba(255, 253, 248, 0.72);
}

.crumb.current {
  color: var(--text);
}

.crumb-sep {
  color: #a2a7b6;
}

.list {
  background: var(--surface);
}

.row {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 36px;
  background: transparent;
}

.row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  padding-left: calc(var(--level) * var(--indent));
  padding-right: 4px;
}

.gutter {
  width: 22px;
  flex: 0 0 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #9ca1af;
  text-align: center;
  user-select: none;
  cursor: default;
  line-height: 1;
  min-height: 34px;
}

.gutter.caret {
  cursor: pointer;
}

.gutter.empty {
  color: transparent;
}

.row-content {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  position: relative;
  margin: 0;
  padding: 0 6px 0 4px;
  border-radius: var(--radius-sm);
}

.row.editing .row-content {
  padding: 0;
  background: transparent;
  box-shadow: none;
}

.row:hover .row-content {
  background: rgba(255, 253, 248, 0.78);
}

.row.selected .row-content {
  background: var(--select);
  border-radius: 0;
}

.row.focused .row-content {
  box-shadow: inset 3px 0 0 var(--select-border);
}

.row.selected[class*="color-"] .row-content {
  padding-right: 32px;
}

.row.selected[class*="color-"] .row-content::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 10px;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  border-radius: 999px;
  background: var(--row-accent);
}

.text,
.editor-shell {
  min-width: 0;
  font-size: 15px;
  line-height: 1.35;
}

.text {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 34px;
  padding: 3px 0;
}

.text-chip {
  display: inline-block;
  max-width: 100%;
  padding: 3px 6px;
  border-radius: 6px;
  white-space: normal;
  word-break: break-word;
}

.editor-shell {
  width: 100%;
  margin: 0;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: var(--radius-sm);
  box-shadow: none;
}

.editor {
  display: block;
  width: 100%;
  min-height: 32px;
  border: 0;
  outline: 0;
  background: transparent;
  color: inherit;
  resize: none;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
  font: inherit;
  line-height: inherit;
  padding: 5px 6px;
}

.actions-wrap {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  min-height: 36px;
  padding: 0 0 0 6px;
}

.actions-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  background: transparent;
  color: #8f97aa;
  border-radius: var(--radius-sm);
  width: 30px;
  height: 30px;
  padding: 0;
  opacity: 0;
}

.actions-btn svg {
  width: 16px;
  height: 16px;
  display: block;
}

.row:hover .actions-btn,
.row.focused .actions-btn,
.actions-btn[aria-expanded="true"] {
  opacity: 1;
}

.actions-btn:hover {
  border-color: var(--line-strong);
  background: #fff;
  color: #455066;
}

.actions-menu {
  position: absolute;
  top: 34px;
  right: 0;
  z-index: 10;
  min-width: 196px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
  padding: 6px;
}

.actions-menu-count {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 10px 8px;
  border-bottom: 1px solid #eee8db;
  margin-bottom: 4px;
}

.actions-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 10px;
}

.actions-item:hover {
  background: #f1f7f3;
}

.actions-item-danger {
  color: #8d2b2b;
}

.actions-item-danger:hover {
  background: #fff2ef;
}

.actions-item-danger .actions-item-icon {
  border-color: #ebc7bd;
  background: #fff4f1;
  color: #8d2b2b;
}

.actions-item-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: 1px solid #e2dbc9;
  border-radius: 7px;
  color: #647062;
  background: #fbf8ef;
  flex: 0 0 22px;
}

.actions-item-icon svg {
  width: 14px;
  height: 14px;
  display: block;
}

.actions-item-icon .icon-emoji {
  font-size: 14px;
}

.actions-item-label {
  font-size: 14px;
  font-weight: 600;
}

.empty-state {
  padding: 28px 12px;
  color: var(--muted);
  font-size: 15px;
}

.empty-state-action {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.empty-state-action:hover {
  color: var(--text);
}

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 80;
  background:
    radial-gradient(circle at 16% 12%, rgba(47, 111, 94, 0.14), transparent 32%),
    linear-gradient(180deg, rgba(246, 242, 233, 0.98), rgba(255, 253, 248, 0.98));
}

.auth-screen[hidden] {
  display: none;
}

.auth-shell {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-strong);
  padding: 28px 26px 24px;
}

.auth-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  font-size: 24px;
}

.auth-title {
  margin: 0 0 8px;
  font-size: 30px;
  line-height: 1.05;
  letter-spacing: -0.04em;
}

.auth-body {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.45;
}

.auth-status-message {
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fbf8ef;
  color: #445069;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.45;
}

.auth-status-message.auth-status-error {
  border-color: #ebc7bd;
  background: #fff4f1;
  color: #8b2e2e;
}

.auth-form {
  display: grid;
  gap: 12px;
}

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

.auth-label {
  font-size: 13px;
  font-weight: 700;
  color: #5a6759;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.auth-input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
  outline: 0;
}

.auth-input:focus {
  border-color: var(--accent-line);
  box-shadow: 0 0 0 4px var(--edit-ring);
}

.auth-submit-btn {
  justify-self: start;
  min-width: 128px;
  margin-top: 4px;
}

.auth-toggle-btn {
  margin-top: 14px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  padding: 0;
}

.auth-toggle-btn:hover {
  text-decoration: underline;
}

.color-1,
.color-2,
.color-3,
.color-4,
.color-5,
.color-6,
.color-7,
.color-8,
.color-9 {
  --row-accent: transparent;
  --row-fill: transparent;
}

.color-1 {
  --row-accent: #fff0a8;
  --row-fill: #fff0a8;
}

.color-2 {
  --row-accent: #c8d2ff;
  --row-fill: #c8d2ff;
}

.color-3 {
  --row-accent: #decaff;
  --row-fill: #decaff;
}

.color-4 {
  --row-accent: #b9f2d0;
  --row-fill: #b9f2d0;
}

.color-5 {
  --row-accent: #ffc9be;
  --row-fill: #ffc9be;
}

.color-6 {
  --row-accent: #ffd1e3;
  --row-fill: #ffd1e3;
}

.color-7 {
  --row-accent: #c53510;
}

.color-8 {
  --row-accent: #144bd6;
}

.color-9 {
  --row-accent: #0d8a48;
}

.color-7 .text-chip,
.color-7 .editor-shell {
  color: #c53510;
}

.color-8 .text-chip,
.color-8 .editor-shell {
  color: #144bd6;
}

.color-9 .text-chip,
.color-9 .editor-shell {
  color: #0d8a48;
}

.color-1 .text-chip,
.color-1 .editor-shell,
.color-2 .text-chip,
.color-2 .editor-shell,
.color-3 .text-chip,
.color-3 .editor-shell,
.color-4 .text-chip,
.color-4 .editor-shell,
.color-5 .text-chip,
.color-5 .editor-shell,
.color-6 .text-chip,
.color-6 .editor-shell {
  background: var(--row-fill);
}

.row.selected.color-1 .text-chip,
.row.selected.color-2 .text-chip,
.row.selected.color-3 .text-chip,
.row.selected.color-4 .text-chip,
.row.selected.color-5 .text-chip,
.row.selected.color-6 .text-chip,
.row.selected.color-7 .text-chip,
.row.selected.color-8 .text-chip,
.row.selected.color-9 .text-chip {
  color: inherit;
  background: transparent;
}

.row.selected.color-1 .editor-shell,
.row.selected.color-2 .editor-shell,
.row.selected.color-3 .editor-shell,
.row.selected.color-4 .editor-shell,
.row.selected.color-5 .editor-shell,
.row.selected.color-6 .editor-shell,
.row.selected.color-7 .editor-shell,
.row.selected.color-8 .editor-shell,
.row.selected.color-9 .editor-shell {
  color: inherit;
  background: var(--surface);
}

.text strong {
  font-weight: 700;
}

.text em {
  font-style: italic;
}

.text blockquote {
  margin: 0.2em 0;
  padding-left: 12px;
  border-left: 2px solid var(--accent-line);
  color: #586175;
}

.text ul,
.text ol {
  margin: 0.35em 0 0.15em 1.2em;
  padding: 0;
}

.text ul ul,
.text ul ol,
.text ol ul,
.text ol ol {
  margin-top: 0.2em;
}

.text li {
  margin: 0.15em 0;
}

.text .md-inline-image-link {
  display: inline-flex;
  max-width: min(100%, 420px);
  vertical-align: middle;
  margin: 0.1em 0;
}

.text .md-inline-image {
  display: block;
  max-width: 100%;
  max-height: 280px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  object-fit: contain;
}

.text .md-heading {
  margin: 0.15em 0;
  font-weight: 700;
  line-height: 1.18;
}

.text .md-heading-1 {
  font-size: 1.32em;
}

.text .md-heading-2 {
  font-size: 1.22em;
}

.text .md-heading-3 {
  font-size: 1.13em;
}

.text .md-heading-4 {
  font-size: 1.05em;
}

.text .md-heading-5,
.text .md-heading-6 {
  font-size: 0.97em;
  letter-spacing: 0.01em;
}

.text .md-table-wrap {
  max-width: 100%;
  overflow-x: auto;
  margin: 0.25em 0;
}

.text table {
  border-collapse: collapse;
  min-width: min(100%, 320px);
  background: #fff;
}

.text th,
.text td {
  border: 1px solid var(--line);
  padding: 4px 8px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

.text th {
  background: #f4f0e6;
  font-weight: 700;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow: auto;
  padding: 24px;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(32, 36, 44, 0.22);
  backdrop-filter: blur(8px);
}

.modal-card {
  position: relative;
  width: min(460px, 100%);
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  margin: auto 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-strong);
  padding: 22px 22px 18px;
}

.paste-card {
  width: min(820px, 100%);
}

.stats-card {
  width: min(560px, 100%);
}

.settings-card {
  width: min(760px, 100%);
}

.export-card {
  width: min(760px, 100%);
}

.confirm-card {
  width: min(420px, 100%);
}

.share-card {
  width: min(520px, 100%);
}

.history-card {
  width: min(680px, 100%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.modal-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--accent);
  background: var(--accent-soft);
}

.modal-close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: #74809a;
  padding: 0;
}

.modal-close-btn:hover {
  background: #f1f7f3;
  color: var(--text);
}

.modal-close-btn svg {
  width: 16px;
  height: 16px;
  display: block;
}

.modal-badge svg {
  width: 18px;
  height: 18px;
  display: block;
}

.modal-badge .icon-emoji {
  font-size: 19px;
}

.modal-badge-danger {
  color: #8d2b2b;
  border-color: #ebc7bd;
  background: #fff4f1;
}

.modal-title {
  margin: 0 0 8px;
  font-size: 23px;
  line-height: 1.12;
  letter-spacing: -0.03em;
}

.modal-body {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.45;
}

.modal-preview {
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fbf8ef;
  color: #52607a;
  font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.paste-card .modal-preview {
  max-height: min(46vh, 420px);
  overflow: auto;
}

.export-preview {
  min-height: 220px;
  max-height: min(56vh, 520px);
  overflow: auto;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-btn {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 0 14px;
  font-size: 14px;
  font-weight: 600;
  transition: transform 120ms ease, border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.modal-btn-secondary {
  background: #fffdf8;
  color: var(--text);
}

.modal-btn-secondary:hover {
  background: #fff;
  border-color: var(--line-strong);
}

.modal-btn-primary {
  border-color: #276450;
  background: linear-gradient(180deg, #367a67, #276450);
  color: #fff;
  box-shadow: 0 10px 20px rgba(39, 100, 80, 0.18);
}

.modal-btn-primary:hover {
  background: linear-gradient(180deg, #3d866f, #235844);
}

.modal-btn-danger {
  border-color: #d9afa4;
  background: #ffe1d9;
  color: #7e2222;
}

.modal-btn-danger:hover {
  background: #ffd4ca;
}

.settings-section + .settings-section {
  margin-top: 20px;
}

.settings-section-title {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 700;
}

.settings-section-body {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.settings-shortcuts {
  display: grid;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fff;
  overflow: hidden;
}

.settings-shortcut-row {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding: 12px 14px;
  border-top: 1px solid #eee8db;
}

.settings-shortcut-row:first-child {
  border-top: 0;
}

.settings-shortcut-label {
  min-width: 0;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.settings-shortcut-keys {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.keycap {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbf8ef;
  color: #445069;
  padding: 0 8px;
  font: 12px/1 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  white-space: nowrap;
}

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

.settings-colour-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fbf8ef;
  padding: 10px 12px;
}

.settings-swatch {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
}

.settings-swatch.color-1,
.settings-swatch.color-2,
.settings-swatch.color-3,
.settings-swatch.color-4,
.settings-swatch.color-5,
.settings-swatch.color-6,
.settings-swatch.color-7,
.settings-swatch.color-8,
.settings-swatch.color-9 {
  background: var(--row-accent);
}

.settings-swatch-clear {
  background:
    linear-gradient(135deg, transparent 45%, #d5dcea 45%, #d5dcea 55%, transparent 55%),
    #fff;
}

.settings-colour-name {
  min-width: 0;
  flex: 1;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.settings-action-btn {
  min-width: 140px;
}

.settings-status {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fbf8ef;
  color: #445069;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.45;
}

.settings-status-success {
  border-color: #c9e2d4;
  background: #f5fff8;
  color: #285d45;
}

.settings-status-error {
  border-color: #ebc7bd;
  background: #fff4f1;
  color: #8b2e2e;
}

.export-status {
  margin: 0 0 16px;
}

.confirm-name {
  margin: 0 0 16px;
  border: 1px solid #ead2ca;
  border-radius: var(--radius-md);
  background: #fff6f2;
  color: #4e586d;
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 600;
  word-break: break-word;
}

.share-form {
  margin: 0 0 16px;
}

.share-public {
  display: grid;
  gap: 10px;
  margin: 0 0 16px;
}

.share-public-head {
  display: grid;
  gap: 4px;
}

.share-section-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

.share-section-body {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.share-public-link {
  overflow-wrap: anywhere;
}

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

.share-collaborators {
  display: grid;
  gap: 10px;
  margin: 0 0 16px;
}

.share-collaborator,
.share-empty {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fbf8ef;
  padding: 10px 12px;
}

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

.share-role-select {
  width: 112px;
  min-width: 112px;
  padding: 8px 10px;
}

.share-collaborator-email {
  min-width: 0;
  flex: 1;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  word-break: break-word;
}

.share-empty {
  color: var(--muted);
  font-size: 14px;
}

.share-remove-btn {
  min-width: 86px;
}

.conflict-card {
  width: min(760px, calc(100vw - 28px));
}

.conflict-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 12px;
}

.conflict-column {
  display: grid;
  gap: 8px;
}

.conflict-preview {
  min-height: 140px;
  max-height: 280px;
  overflow: auto;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fbf8ef;
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.conflict-actions {
  justify-content: space-between;
}

.history-checkpoint {
  display: grid;
  gap: 10px;
  margin: 0 0 16px;
}

.history-actions {
  justify-content: flex-start;
}

.history-entries {
  display: grid;
  gap: 10px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
  overscroll-behavior: contain;
}

.history-entry {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fbf8ef;
  padding: 12px;
}

.history-entry-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.history-entry-title {
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

.history-entry-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.history-entry-diff {
  display: grid;
  gap: 4px;
  border-top: 1px solid #eee8db;
  padding-top: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.history-entry-preview {
  margin: 0;
  padding-left: 18px;
}

.history-entry-actions {
  justify-content: flex-start;
}

.stats-content {
  display: grid;
  gap: 16px;
}

.stats-status {
  min-height: 120px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fbf8ef;
  color: #5c667b;
  padding: 16px;
}

.stats-status-error {
  color: #8b2e2e;
  background: #fff4f1;
  border-color: #ebc7bd;
}

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

.stats-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fbf8ef;
  padding: 12px 12px 10px;
}

.stats-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stats-value {
  margin-top: 6px;
  color: var(--text);
  font-size: 24px;
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-weight: 600;
}

.stats-meta {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fff;
  padding: 14px;
}

.stats-meta-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.stats-meta-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.stats-meta-value {
  min-width: 0;
  color: var(--text);
  font-size: 14px;
  word-break: break-word;
}

@media (max-width: 720px) {
  :root {
    --indent: 17px;
    --radius-lg: 14px;
  }

  .app {
    --app-pad: 12px;
    padding-top: max(10px, env(safe-area-inset-top));
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }

  .topbar {
    position: sticky;
    top: 0;
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    margin: 0 calc(var(--app-pad) * -1) 12px;
    padding: 10px var(--app-pad);
    border-right: 0;
    border-left: 0;
    border-radius: var(--radius-md);
    box-shadow: 0 8px 18px rgba(72, 59, 39, 0.08);
  }

  .search-stack {
    min-width: 0;
    max-width: none;
  }

  .search-wrap {
    max-width: none;
  }

  .search-input {
    height: 44px;
    font-size: 16px;
    padding-right: 136px;
  }

  .search-clear-btn {
    top: 10px;
    right: 104px;
  }

  .search-scope-select {
    top: 6px;
    right: 6px;
    width: 92px;
    height: 32px;
    font-size: 12px;
  }

  .search-results {
    top: 52px;
    width: 100%;
    max-height: min(58vh, 420px);
  }

  #listSelect {
    flex: 1 1 120px;
    width: auto;
    min-width: 116px;
  }

  .toolbar-select,
  .nav-icon-btn {
    height: 44px;
    min-height: 44px;
    font-size: 16px;
  }

  .nav-icon-btn {
    width: 44px;
    flex: 0 0 44px;
  }

  .controls {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-left: 0;
  }

  .controls .toolbar-menu-wrap {
    flex: 0 0 44px;
  }

  .controls .save-status:not([hidden]) {
    flex: 1 0 100%;
    order: -1;
  }

  .toolbar-menu {
    top: 52px;
    right: 0;
    width: min(280px, calc(100vw - 24px));
  }

  .actions-item {
    min-height: 44px;
  }

  .header {
    padding: 10px 0 10px;
  }

  .title {
    font-size: clamp(24px, 7.4vw, 34px);
    line-height: 1.1;
  }

  .header-row {
    align-items: center;
    gap: 8px;
  }

  .title-menu-btn {
    width: 44px;
    height: 44px;
  }

  .title-menu {
    top: 48px;
    width: min(240px, calc(100vw - 24px));
  }

  .breadcrumbs {
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
    white-space: nowrap;
  }

  .breadcrumbs::-webkit-scrollbar {
    display: none;
  }

  .row {
    align-items: stretch;
    min-height: 44px;
  }

  .row-main {
    align-items: stretch;
    padding-left: calc(var(--level) * var(--indent));
    padding-right: 2px;
  }

  .gutter {
    width: 28px;
    flex-basis: 28px;
    min-height: 44px;
    font-size: 15px;
  }

  .row-content {
    align-items: stretch;
    padding-right: 4px;
  }

  .text {
    min-height: 44px;
    align-items: center;
    font-size: 16px;
  }

  .text-chip {
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .editor-shell {
    align-self: center;
  }

  .editor {
    min-height: 42px;
    font-size: 16px;
  }

  .actions-wrap {
    min-height: 44px;
    padding-left: 2px;
  }

  .actions-btn {
    width: 38px;
    height: 38px;
    opacity: 1;
  }

  .actions-menu {
    top: 42px;
    right: 4px;
    width: min(220px, calc(100vw - 24px));
  }

  .empty-state {
    padding: 24px 4px;
  }

  .modal {
    align-items: end;
    padding: 10px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .modal-card {
    width: 100%;
    max-height: calc(100dvh - 20px - env(safe-area-inset-bottom));
    overflow: auto;
    border-radius: 16px;
    padding: 18px 16px 16px;
  }

  .modal-actions {
    flex-direction: column-reverse;
    gap: 8px;
  }

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

  .conflict-actions {
    justify-content: flex-start;
  }

  .modal-btn {
    width: 100%;
    min-height: 44px;
    font-size: 15px;
  }

  .share-collaborator {
    align-items: stretch;
    flex-direction: column;
  }

  .share-role-select {
    width: 100%;
    min-height: 44px;
    font-size: 16px;
  }

  .settings-shortcut-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .settings-colours {
    grid-template-columns: 1fr;
  }

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

  .stats-meta-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}

@media (max-width: 480px) {
  .app {
    --app-pad: 10px;
  }

  .topbar {
    padding-right: var(--app-pad);
    padding-left: var(--app-pad);
  }

  .search-input {
    padding-left: 34px;
    padding-right: 120px;
  }

  .search-icon {
    left: 10px;
    width: 16px;
    height: 16px;
  }

  .search-scope-select {
    width: 78px;
    padding-left: 8px;
    padding-right: 20px;
  }

  .search-clear-btn {
    right: 88px;
  }

  .save-status {
    justify-content: center;
    min-height: 44px;
    padding: 0;
  }

  .save-status-label {
    display: none;
  }

  .toolbar-select {
    min-width: 0;
  }

  .header-row {
    align-items: flex-start;
  }

  .title {
    font-size: clamp(21px, 6.2vw, 26px);
    letter-spacing: -0.035em;
  }

  .row-main {
    padding-left: calc(var(--level) * 14px);
  }

  .text .md-inline-image-link {
    max-width: 100%;
  }

  .settings-actions,
  .share-actions,
  .history-actions,
  .history-entry-actions {
    flex-direction: column;
  }

  .settings-action-btn {
    width: 100%;
  }

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