*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.1);
  --item-hover: #f1f5f9;
  --item-active: #dbeafe;
  --item-active-text: #1d4ed8;
}

[data-theme="dark"] {
  --bg: #121212;
  --surface: #1e1e1e;
  --border: #2e2e2e;
  --text: #e0e0e0;
  --text-muted: #9e9e9e;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --shadow: 0 1px 3px rgba(0,0,0,.6);
  --item-hover: #2a2a2a;
  --item-active: #333333;
  --item-active-text: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121212;
    --surface: #1e1e1e;
    --border: #2e2e2e;
    --text: #e0e0e0;
    --text-muted: #9e9e9e;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --danger: #ef4444;
    --shadow: 0 1px 3px rgba(0,0,0,.6);
    --item-hover: #2a2a2a;
    --item-active: #333333;
    --item-active-text: #ffffff;
  }
}

/* App-Icon Web Component & General Icons */
app-icon, lucide-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  flex-shrink: 0;
  line-height: 0;
}

/* External link icon indicator (after link text) */
a.external-link::after {
  content: "";
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  margin-left: 0.25rem;
  vertical-align: -0.05em;
  background-color: currentColor;
  -webkit-mask: url("icons/external-link.svg") no-repeat center / contain;
  mask: url("icons/external-link.svg") no-repeat center / contain;
}

body { font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }

.hidden { display: none !important; }

/* Login overlay */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.overlay.hidden { display: none; }
.card {
  background: var(--surface); padding: 2rem; border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.2); width: 320px; max-width: 90vw;
}
.card h2 { margin-bottom: 1rem; }
.card input, .card button { width: 100%; margin-bottom: .5rem; }

input, textarea, select, button { font: inherit; }
input, textarea, select {
  padding: .5rem .75rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  outline: none;
}
input:focus, textarea:focus { border-color: var(--primary); }

button, .button-link, .button-link:visited {
  cursor: pointer; padding: .5rem 1rem; border: none; border-radius: var(--radius);
  background: var(--primary); color: #ffffff !important; font-weight: 500; text-decoration: none !important; display: inline-flex; align-items: center; justify-content: center;
}
button:hover, .button-link:hover { background: var(--primary-hover); color: #ffffff !important; }
button.danger, .button-link.danger, .button-link.danger:visited { background: var(--danger); color: #ffffff !important; }
button.secondary, .button-link.secondary, .button-link.secondary:visited { background: var(--surface); color: var(--text) !important; border: 1px solid var(--border); }
button.secondary:hover, .button-link.secondary:hover { background: var(--item-hover); color: var(--text) !important; }

/* App layout */
.app { display: flex; height: 100vh; }
.sidebar {
  width: 260px; min-width: 160px; max-width: 600px; flex-shrink: 0;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
  transition: background .15s, outline .15s;
}
.sidebar.drag-target-root {
  background: #eff6ff !important;
}
.sidebar-search {
  padding: 0.6rem 0.75rem 0.25rem 0.75rem; background: var(--surface);
}
.sidebar-search #searchBox {
  width: 100%; margin: 0; padding: 0.35rem 0.6rem; font-size: 0.85rem; border-radius: var(--radius);
}
.sidebar-tree-container {
  flex: 1; overflow-y: auto; padding: 0 6px;
}
.sidebar-resizer {
  width: 5px; cursor: col-resize; background: transparent; transition: background .15s;
  position: relative; z-index: 10; margin-left: -3px; flex-shrink: 0;
}
.sidebar-resizer:hover, .sidebar-resizer.resizing {
  background: var(--primary);
}
.sidebar h3 { padding: 0.75rem 1rem 0.25rem; font-size: .75rem; text-transform: uppercase; color: var(--text-muted); }

.tree-root, .tree-children { list-style: none; margin: 0; padding: 0; }
.tree-node { display: flex; flex-direction: column; }
.tree-item-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0.35rem 0.6rem; cursor: pointer;
  border-radius: var(--radius); font-size: 0.85rem; user-select: none; transition: background .12s, color .12s;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.2;
  margin: 1px 0;
  color: inherit;
  text-decoration: none;
}
.tree-item-row:hover { background: var(--item-hover); color: inherit; text-decoration: none; }
.tree-item-row:visited { color: inherit; }
.tree-item-row.active,
.tree-item-row.selected { background: var(--item-active); color: var(--item-active-text); }
.tree-node.drag-target-block {
  background: var(--item-active) !important;
  border-radius: var(--radius);
}
.tree-node.drag-target-block > .tree-item-row {
  background: var(--item-active) !important;
}
.tree-chevron {
  width: 12px; height: 12px; display: inline-block; flex-shrink: 0; opacity: 0.6;
}
.tree-chevron-placeholder { width: 12px; height: 12px; display: inline-block; flex-shrink: 0; }
.tree-icon { width: 14px; height: 14px; display: inline-block; opacity: 0.85; flex-shrink: 0; vertical-align: middle; }
.tree-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; line-height: 1.4; }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .6rem 1.25rem;
  background: var(--surface); border-bottom: 1px solid var(--border); min-height: 48px;
}
.nav-buttons { display: flex; align-items: center; gap: 0.4rem; }
.toolbar-title {
  flex: 1; text-align: center; font-size: 0.95rem; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 1rem;
}
.toolbar-actions { display: flex; align-items: center; gap: .5rem; }

/* Primary and Secondary button styling */
.primary-btn, .primary-btn:visited, a.primary-btn, a.primary-btn:visited {
  background: var(--primary) !important; color: #ffffff !important; border: 1px solid var(--primary) !important;
  font-weight: 600; display: inline-flex; align-items: center; gap: .4rem; padding: .45rem .85rem; border-radius: var(--radius);
  text-decoration: none !important;
}
.primary-btn:hover, a.primary-btn:hover { background: var(--primary-hover) !important; border-color: var(--primary-hover) !important; color: #ffffff !important; text-decoration: none !important; }

.secondary-btn, .secondary-btn:visited {
  background: var(--surface) !important; color: var(--text) !important; border: 1px solid var(--border) !important;
  display: inline-flex; align-items: center; gap: .4rem; padding: .45rem .75rem; border-radius: var(--radius); cursor: pointer; transition: all .15s; text-decoration: none !important;
}
.secondary-btn:hover { background: var(--item-hover) !important; border-color: var(--text-muted) !important; color: var(--text) !important; text-decoration: none !important; }
.secondary-btn.icon-only { padding: .45rem .55rem; }
.secondary-btn:disabled, button:disabled {
  opacity: 0.35 !important;
  cursor: not-allowed !important;
  pointer-events: none !important;
}

.danger-btn, .danger-btn:visited {
  background: var(--danger) !important; color: #ffffff !important; border: 1px solid var(--danger) !important;
  font-weight: 500; display: inline-flex; align-items: center; gap: .4rem; padding: .45rem .85rem; border-radius: var(--radius); cursor: pointer; transition: all .15s;
}
.danger-btn:hover { background: #b91c1c !important; border-color: #b91c1c !important; color: #ffffff !important; }

.btn-icon { width: 16px; height: 16px; display: block; opacity: 0.8; }
.btn-icon-white { width: 16px; height: 16px; display: block; filter: brightness(0) invert(1); }
.btn-icon-white.chevron { width: 12px; height: 12px; margin-left: 2px; }

/* Dropdown Menu */
.dropdown { position: relative; display: inline-block; }
.dropdown-toggle { border-radius: var(--radius); cursor: pointer; }
.dropdown-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 4px); background: var(--surface);
  min-width: 200px; box-shadow: 0 10px 25px rgba(0,0,0,0.15); border: 1px solid var(--border);
  border-radius: var(--radius); z-index: 100; padding: .4rem 0; overflow: hidden;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-item {
  display: flex; align-items: center; gap: .6rem; padding: .5rem 1rem; color: var(--text);
  text-decoration: none; font-size: .85rem; transition: background .15s;
}
.dropdown-item:hover { background: var(--item-hover); color: var(--primary); }
.dropdown-item img { width: 16px; height: 16px; }
#filterBar { display: flex; gap: .25rem; padding: .4rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.filter-pill { font-size: .8rem; padding: .2rem .6rem; background: transparent !important; color: var(--text-muted) !important; border: 1px solid var(--border); }
.filter-pill:hover { background: var(--bg) !important; border-color: var(--text-muted); color: var(--text) !important; }
.filter-pill.active { background: var(--primary) !important; color: #ffffff !important; border-color: var(--primary); }

#sortBar { display: flex; align-items: center; gap: .4rem; padding: .3rem 1rem; background: var(--bg); border-bottom: 1px solid var(--border); font-size: .8rem; color: var(--text-muted); }
.sort-pill { font-size: .78rem; padding: .15rem .5rem; background: var(--surface) !important; color: var(--text-muted) !important; border: 1px solid var(--border); }
.sort-pill:hover { border-color: var(--text-muted); color: var(--text) !important; }
.sort-pill.asc, .sort-pill.desc { background: var(--surface) !important; color: var(--primary) !important; border-color: var(--primary); font-weight: 600; }

#detailView { flex: 1; overflow-y: auto; padding: 0; background: var(--surface); }
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 3rem; color: var(--text-muted); }
.folder-header {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .5rem 1rem; margin-bottom: 1rem; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: .85rem; color: var(--text-muted); width: 100%;
}
.folder-header-title { font-size: .95rem; font-weight: 600; color: var(--text); }

#contentFooter {
  padding: .5rem 1.5rem; background: var(--surface); border-top: 1px solid var(--border);
  font-size: .8rem; color: var(--text-muted); display: flex; align-items: center; justify-content: space-between;
}

/* List views */
.item-list { display: flex; flex-direction: column; gap: .5rem; }
.item-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .75rem 1rem; display: flex; align-items: center; gap: .75rem;
  box-shadow: var(--shadow); cursor: pointer; transition: box-shadow .15s;
}
.item-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.item-card .info { flex: 1; min-width: 0; }
.item-card .info .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-card .info .sub { font-size: .85rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-card .tags { display: flex; gap: .25rem; flex-wrap: wrap; }
.tag {
  font-size: .75rem; background: #e5e7eb; padding: .1rem .5rem; border-radius: 999px;
  color: var(--text-muted);
}
.item-card .actions { display: flex; gap: .25rem; }
.item-card .actions button { font-size: .8rem; padding: .25rem .5rem; }

/* Document view */
.doc-content { max-width: 900px; margin: 0 auto; width: 100%; box-sizing: border-box; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface); padding: 1.5rem; border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.2); width: 480px; max-height: 80vh; overflow-y: auto;
}
.modal h3 { margin-bottom: 1rem; }
.modal label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .25rem; color: var(--text-muted); }
.modal input, .modal textarea, .modal select { width: 100%; margin-bottom: .75rem; }
.modal textarea { resize: vertical; min-height: 80px; }
.modal-actions { display: flex; gap: .75rem; align-items: center; justify-content: flex-end; margin-top: .5rem; }
.modal-actions .spacer { flex: 1; min-width: 2.5rem; }

/* Dropzone Overlay */
.drop-overlay {
  position: fixed; inset: 0; background: rgba(37, 99, 235, 0.85);
  display: flex; align-items: center; justify-content: center; z-index: 999;
  backdrop-filter: blur(4px); transition: opacity .2s;
}
.drop-overlay.hidden { display: none; }
.drop-message {
  background: #ffffff; padding: 2.5rem 3.5rem; border-radius: 12px;
  text-align: center; border: 3px dashed var(--primary); box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}
.drop-message h3 { font-size: 1.4rem; color: var(--primary); margin-bottom: .5rem; }
.drop-message p { color: var(--text-muted); }

/* File preview thumbnail & item icon containers */
.item-icon-box {
  width: 48px; height: 48px; border-radius: 6px; background: #f1f5f9; border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.item-icon-box img {
  width: 24px; height: 24px; object-fit: contain; display: block;
}
.file-thumb {
  width: 48px; height: 48px; border-radius: 6px; object-fit: cover; background: #e2e8f0; border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.75rem; color: #475569; text-transform: uppercase; flex-shrink: 0;
}

.card-icon-btn {
  background: var(--surface); border: 1px solid var(--border); color: var(--text-muted);
  border-radius: 4px; padding: 6px; display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all .15s; vertical-align: middle;
}
.card-icon-btn:hover {
  background: var(--item-hover); color: var(--primary); border-color: var(--primary);
}
.card-icon-btn img {
  width: 14px; height: 14px; display: block; opacity: 0.7;
}
.card-icon-btn:hover img {
  opacity: 1;
}

.sidebar {
  display: flex;
  flex-direction: column;
}
.sidebar-tree-container {
  flex: 1;
  overflow-y: auto;
}
.sidebar-footer {
  padding: 0.6rem 0.75rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.sidebar-add-btn {
  flex: 1;
  justify-content: center;
}

.add-modal {
  max-width: 440px;
}
.type-radio-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.type-radio-card {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  justify-content: flex-start !important;
  gap: 0.75rem !important;
  padding: 0.7rem 1rem !important;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  font-size: 0.95rem;
  color: var(--text);
  min-height: 44px;
  box-sizing: border-box;
}
.type-radio-card input[type="radio"] {
  display: none !important;
}
.type-radio-card:hover {
  border-color: var(--text-muted);
  background: var(--item-hover);
}
.type-radio-card.active {
  border-color: var(--primary);
  background: var(--item-active);
  color: var(--primary);
  font-weight: 600;
}
.type-radio-card img {
  width: 20px !important;
  height: 20px !important;
  min-width: 20px;
  min-height: 20px;
  display: block !important;
  margin: 0 !important;
  flex-shrink: 0 !important;
}
.type-radio-card span {
  display: inline-block !important;
  margin: 0 !important;
  padding: 0 !important;
  line-height: 1.2 !important;
}

/* Custom Sidebar Context Menu */
.menu-backdrop {
  position: fixed; inset: 0; z-index: 999; background: transparent;
}
.menu-backdrop.hidden { display: none; }

.context-menu {
  position: fixed; z-index: 1000; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 10px 25px rgba(0,0,0,0.15); min-width: 170px; padding: 4px 0;
}
.context-menu.hidden { display: none; }
.context-menu-divider { height: 1px; background: var(--border); margin: 4px 0; }
.context-menu-item {
  position: relative; display: flex; align-items: center; gap: 8px; padding: 6px 12px;
  font-size: 0.85rem; color: var(--text); cursor: pointer; transition: background .12s;
  white-space: nowrap;
}
.context-menu-item:hover { background: var(--item-hover); color: var(--primary); }
.context-menu-item.danger:hover { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.context-menu-item img { width: 14px; height: 14px; opacity: 0.75; }
.context-menu-item .submenu-arrow { margin-left: auto; width: 10px; height: 10px; opacity: 0.5; }

/* Submenu */
.context-menu-item.has-submenu .context-submenu {
  display: none; position: absolute; left: 100%; top: -4px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 10px 25px rgba(0,0,0,0.15); min-width: 180px; padding: 4px 0;
}
.context-menu-item.has-submenu:hover > .context-submenu {
  display: block;
}

/* Mobile Sidebar Backdrop */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 140;
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.25s ease;
}
.sidebar-backdrop.active {
  display: block;
  opacity: 1;
}

.menu-btn {
  display: none;
}

/* Responsive Breakpoints */
@media (max-width: 768px) {
  .menu-btn {
    display: inline-flex;
  }
  .sidebar-resizer {
    display: none;
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px !important;
    max-width: 85vw;
    z-index: 150;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s ease;
    box-shadow: none;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
  }
  .toolbar {
    padding: 0.5rem 0.75rem;
    gap: 0.4rem;
  }
  .toolbar-title {
    font-size: 0.88rem;
    padding: 0 0.25rem;
  }
  .toolbar-actions {
    gap: 0.25rem;
  }
  .item-card {
    padding: 0.6rem 0.75rem;
    gap: 0.5rem;
  }
  .item-icon-box, .file-thumb {
    width: 40px;
    height: 40px;
  }
  .modal {
    width: 92vw;
    padding: 1rem;
    max-height: 90vh;
  }
}

/* Mode Switcher Buttons */
.mode-toggle-group {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
  gap: 2px;
}

.mode-toggle-btn {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 500;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: calc(var(--radius) - 2px);
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-toggle-btn.active {
  background: var(--primary);
  color: #ffffff !important;
}

/* Search Snippets in Sidebar */
.search-snippet {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* Backlinks Accordion Panel */
.backlinks-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 1.5rem auto 0;
  max-width: 900px;
  padding: 1rem 1.25rem;
  box-sizing: border-box;
}
.backlinks-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text);
  margin-bottom: 0.6rem;
}
.backlinks-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.backlinks-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  background: var(--bg);
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
  color: var(--text);
  font-size: 0.88rem;
}
.backlinks-item:hover {
  background: var(--item-hover);
}
.backlinks-item img,
.backlinks-item app-icon {
  width: 14px;
  height: 14px;
}

/* Bookmark Blocked Embed / Open in New Tab Center View */
.bookmark-embed-container {
  display: flex;
  align-items: center;
  justify-content: center;
  height: calc(100vh - 100px);
  padding: 2rem;
  background: var(--surface);
  box-sizing: border-box;
}

.bookmark-embed-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2.5rem 2rem;
  max-width: 500px;
  width: 100%;
  box-shadow: var(--shadow);
}

.bookmark-embed-icon-wrapper {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--item-active);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.25rem;
}

.bookmark-embed-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
  word-break: break-word;
}

.bookmark-embed-url {
  font-size: 0.85rem;
  color: var(--text-muted);
  word-break: break-all;
  margin-bottom: 1.25rem;
  max-width: 100%;
}

.bookmark-embed-notice {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.45rem 0.85rem;
  border-radius: 6px;
  margin-bottom: 1.5rem;
  max-width: 90%;
  text-align: left;
}

.bookmark-embed-open-btn {
  padding: 0.6rem 1.4rem;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

/* Print Stylesheet */
@media print {
  @page {
    margin: 1.5cm;
  }

  /* Unconstrain viewport / body scroll traps */
  html, body {
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    background: #ffffff !important;
    color: #000000 !important;
  }

  /* Hide app chrome, sidebars, toolbars, overlays, navigation and modals */
  .sidebar,
  .sidebar-backdrop,
  .sidebar-resizer,
  .toolbar,
  #contentFooter,
  .context-menu,
  .menu-backdrop,
  .modal-overlay,
  .drop-overlay,
  .overlay,
  #filterBar,
  #sortBar,
  .nav-buttons,
  .toolbar-actions,
  .doc-actions,
  .editor-header,
  .editor-tabs,
  .meta-fields,
  .page-header {
    display: none !important;
  }

  /* Expand main content container and unset flex / scroll traps */
  html,
  body,
  .app,
  .main,
  #appContainer,
  #contentPane,
  #detailView,
  .document-iframe-container,
  .doc-content,
  #docContainer,
  #docBodyContainer,
  .preview-panel,
  .settings-content-panel,
  .tag-content-panel {
    display: block !important;
    position: static !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
  }

  /* Allow iframes containing documents to render naturally when printing parent page */
  #mainDocIframe,
  #docBodyIframe,
  #livePreviewIframe {
    width: 100% !important;
    height: auto !important;
    min-height: 100vh !important;
    border: none !important;
    background: transparent !important;
  }

  /* Clean up cards, lists, tags, links and titles for paper printing */
  .item-card {
    box-shadow: none !important;
    border: 1px solid #ccc !important;
    page-break-inside: avoid;
    break-inside: avoid;
  }

  a, a:visited {
    color: #000000 !important;
    text-decoration: underline !important;
  }
}

