.library-island, .profile-island {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel);
  color: var(--text);
  padding: 18px;
  direction: rtl;
}
.library-panel [hidden], .account-panel [hidden] { display: none !important; }
.library-panel, .account-panel { min-width: 0; }
.library-header, .account-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.library-header { justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.library-header h2 { margin: 0; color: var(--strong); font-size: 17px; line-height: 1.4; }
.library-header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.library-panel button, .account-panel button, .library-dialog button {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 10px;
  background: var(--panel-soft);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.5;
  cursor: pointer;
  box-shadow: none;
}
.library-panel button:hover, .account-panel button:hover, .library-dialog button:hover { border-color: var(--accent); filter: none; }
.library-panel button:disabled, .account-panel button:disabled, .library-dialog button:disabled { opacity: .5; cursor: wait; }
.library-panel input, .library-panel select, .account-panel input, .library-dialog input, .library-dialog select {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}
.library-panel :focus-visible, .account-panel :focus-visible, .library-dialog :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.library-panel button[hidden], .account-panel button[hidden] { display: none !important; }
.library-new-folder { flex: 0 0 auto; }
.library-panel .library-search { width: 100%; margin-bottom: 10px; }
.library-tree { display: grid; gap: 14px; min-width: 0; }
.library-section { min-width: 0; }
.library-section h3 { margin: 0 0 7px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .02em; }
.library-section > .library-folder + .library-folder { margin-top: 6px; }
.library-unfiled { border-radius: 11px; }
.library-documents { display: grid; gap: 4px; min-width: 0; }
.library-folder { min-width: 0; border: 1px solid var(--border); border-radius: 11px; background: var(--panel-soft); }
.library-folder-heading, .library-doc { display: flex; align-items: center; gap: 4px; min-width: 0; }
.library-folder-heading { padding: 4px 5px; }
.library-folder-toggle { display: flex; align-items: center; gap: 7px; flex: 1 1 auto; min-width: 0; text-align: right; border: 0 !important; background: transparent !important; box-shadow: none !important; }
.library-folder-chevron { flex: 0 0 auto; color: var(--muted); font-size: 15px; transition: transform .15s; }
.library-folder-toggle[aria-expanded="true"] .library-folder-chevron { transform: rotate(-90deg); }
.library-folder-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.library-badges { display: flex; gap: 4px; flex: 0 0 auto; }
.library-badge { padding: 0 7px; border: 1px solid var(--border); border-radius: 999px; color: var(--muted); font-size: 10.5px; font-weight: 700; line-height: 1.8; }
.library-badge.shared { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); color: var(--accent); }
.library-folder-count { flex: 0 0 auto; margin-inline-start: auto; color: var(--muted); font-size: 11px; }
.library-folder-items { padding: 0 6px 6px; }
.library-panel .library-result { display: grid; grid-template-columns: minmax(0, 1fr); justify-items: start; gap: 2px; width: 100%; margin-bottom: 4px; padding: 8px 10px !important; border: 1px solid var(--border) !important; border-radius: 10px; background: var(--panel-soft) !important; text-align: right; font-weight: 500 !important; }
.library-panel .library-result:hover { border-color: var(--accent) !important; }
.library-result strong { overflow: hidden; color: var(--text); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.library-result.is-open strong::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-inline-end: 6px; border-radius: 50%; background: var(--accent); vertical-align: middle; }
.library-result-folder { color: var(--accent); font-size: 10.5px; }
.library-result-snippet { display: -webkit-box; overflow: hidden; color: var(--muted); font-size: 11.5px; line-height: 1.7; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.library-result mark { border-radius: 3px; background: var(--glow); color: var(--accent); font-weight: 700; }
.library-trash summary { margin-bottom: 7px; color: var(--muted); font-size: 11px; font-weight: 800; cursor: pointer; }
.library-trash-doc { gap: 6px; }
.library-trash-doc .library-doc-title { cursor: default; }
.library-trash-actions { display: flex; flex: 0 0 auto; gap: 4px; }
.library-panel .library-small-button { padding: 3px 8px; font-size: 11px; }
.library-panel .library-small-button.danger:hover { border-color: var(--danger); color: var(--danger); }
.library-folder-items .library-empty { margin: 3px 8px 5px; }
.library-doc { min-height: 40px; padding: 3px 5px; border: 1px solid transparent; border-radius: 9px; }
.library-doc:hover { border-color: var(--border); background: var(--panel); }
.library-unfiled .library-doc { background: var(--panel-soft); border-color: var(--border); }
.library-doc[draggable="true"] { cursor: grab; }
.library-doc.dragging { opacity: .45; }
.library-doc.is-open .library-doc-name::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-inline-end: 6px; border-radius: 50%; background: var(--accent); vertical-align: middle; }
.library-doc-title { display: grid; flex: 1 1 auto; min-width: 0; padding: 3px 6px !important; text-align: right; border: 0 !important; background: transparent !important; box-shadow: none !important; }
.library-doc-name, .library-doc-date { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.library-doc-date { color: var(--muted); font-size: 10.5px; font-weight: 500; line-height: 1.4; }
.library-row-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 1px; }
/* On pointer devices, actions float over the row on hover so titles keep the full width. */
@media (hover: hover) {
  .library-doc, .library-folder-heading { position: relative; }
  .library-doc .library-row-actions, .library-folder-heading .library-row-actions {
    position: absolute; inset-inline-end: 4px; top: 50%; transform: translateY(-50%);
    padding: 1px 2px; border-radius: 8px; background: var(--panel); box-shadow: 0 2px 10px rgba(0,0,0,.18);
    opacity: 0; pointer-events: none; transition: opacity .12s;
  }
  .library-doc:hover .library-row-actions, .library-doc:focus-within .library-row-actions,
  .library-folder-heading:hover .library-row-actions, .library-folder-heading:focus-within .library-row-actions { opacity: 1; pointer-events: auto; }
}
.library-panel .library-icon-button { display: grid; place-items: center; flex: 0 0 28px; width: 28px; height: 28px; padding: 5px; border: 0; background: transparent; color: var(--muted); }
.library-panel .library-icon-button:hover { background: var(--glow); color: var(--accent); }
.library-panel .library-icon-button.library-icon-delete:hover, .library-panel .library-icon-button.library-icon-leave:hover { color: var(--danger); }
.library-icon-button svg { width: 16px; height: 16px; }
.drop-target { outline: 2px dashed var(--accent); outline-offset: 2px; background: var(--glow) !important; }
.library-empty { margin: 2px 0 6px; color: var(--muted); font-size: 12px; line-height: 1.7; }
.library-message { margin: 8px 0; color: var(--success); font-size: 12px; line-height: 1.6; overflow-wrap: anywhere; }
.library-message:empty { display: none; }
.library-message.error { color: var(--danger); }

/* Document tabs above the editor */
.doc-tabs { display: flex; align-items: flex-end; gap: 6px; min-width: 0; margin-bottom: -14px; direction: rtl; }
.doc-tab-list { display: flex; flex: 0 1 auto; gap: 4px; min-width: 0; overflow-x: auto; scrollbar-width: thin; padding-top: 2px; }
.doc-tab { display: flex; flex: 0 0 auto; align-items: center; max-width: 220px; border: 1px solid var(--border); border-bottom: 0; border-radius: 11px 11px 0 0; background: var(--panel-soft); color: var(--muted); }
.doc-tab.active { background: var(--panel); color: var(--text); box-shadow: inset 0 2px 0 var(--accent); }
.doc-tab-main { display: flex; align-items: center; gap: 7px; min-width: 0; padding: 7px 12px 7px 4px; border: 0; background: transparent; color: inherit; font: inherit; font-size: 12.5px; font-weight: 700; box-shadow: none; cursor: pointer; }
.doc-tab-main:hover { filter: none; color: var(--text); }
.doc-tab-main:focus-visible, .doc-tab-close:focus-visible, .doc-tab-new:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.doc-tab-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-tab.draft .doc-tab-title { font-style: italic; }
.doc-tab.tool .doc-tab-dot { opacity: 1; width: 8px; height: 8px; border: 0; border-radius: 2px; background: var(--accent); }
.doc-tab-dot { flex: 0 0 auto; width: 7px; height: 7px; border-radius: 50%; border: 1.5px solid var(--muted); opacity: 0; }
.doc-tab.draft .doc-tab-dot { opacity: .9; }
.doc-tab.dirty:not(.draft) .doc-tab-dot { opacity: 1; border-color: var(--warning); background: var(--warning); }
.doc-tab.readonly .doc-tab-dot { opacity: 1; border-radius: 2px; }
.doc-tab-close { flex: 0 0 auto; width: 24px; height: 24px; margin-inline-start: 4px; padding: 0; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: 16px; line-height: 1; box-shadow: none; cursor: pointer; justify-content: center; }
.doc-tab-close:hover { filter: none; background: var(--glow); color: var(--danger); }
.doc-tab-new { flex: 0 0 auto; width: 32px; height: 32px; margin-bottom: 4px; padding: 0; border: 1px dashed var(--border); border-radius: 9px; background: transparent; color: var(--muted); font-size: 16px; box-shadow: none; justify-content: center; }
.doc-tab-new:hover { filter: none; border-color: var(--accent); color: var(--accent); }
.doc-tab-close-all { flex: 0 0 auto; display: grid; place-items: center; width: 32px; height: 32px; margin-bottom: 4px; padding: 0; border: 1px solid transparent; border-radius: 9px; background: transparent; color: var(--muted); box-shadow: none; }
.doc-tab-close-all[hidden] { display: none; }
.doc-tab-close-all svg { width: 17px; height: 17px; }
.doc-tab-close-all:hover { filter: none; border-color: var(--border); color: var(--danger); }
.doc-tab-close-all:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Folder sharing dialog */
.share-dialog { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow: auto; }
.share-dialog .share-intro { font-size: 12px; line-height: 1.9; }
.share-dialog h3 { margin: 18px 0 8px; color: var(--muted); font-size: 12px; font-weight: 800; }
.share-form { display: flex; flex-wrap: wrap; gap: 8px; }
.share-dialog .share-form input { flex: 1 1 100%; }
.share-dialog .share-form select { flex: 1 1 110px; width: auto; }
.share-dialog .share-form button { flex: 0 0 auto; }
.share-result { display: flex; gap: 8px; margin-top: 10px; }
.share-dialog .share-result input { flex: 1; width: 0; }
.share-list { display: grid; gap: 6px; }
.share-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel-soft); }
.share-row-info { display: grid; flex: 1; min-width: 0; }
.share-row-info strong { font-size: 13px; }
.share-row-info small { color: var(--muted); font-size: 11px; line-height: 1.7; }
.share-dialog .library-dialog-actions { margin-top: 16px; }
.share-dialog .share-row-action:hover { border-color: var(--danger); color: var(--danger); }
.profile-island { padding: 7px; }
.profile-island .account-summary { display: flex; align-items: center; gap: 10px; width: 100%; min-width: 0; padding: 5px 7px; border: 0; border-radius: 12px; background: transparent; color: var(--text); text-align: right; font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; box-shadow: none; }
.profile-island .account-summary:hover { background: var(--panel-soft); filter: none; }
.profile-island .account-summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.account-avatar { display: grid; place-items: center; flex: 0 0 34px; width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 50%; background: var(--panel-soft); color: var(--accent); }
.account-avatar svg { width: 19px; height: 19px; }
.account-summary-text { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-panel #accountState { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.7; overflow-wrap: anywhere; }
.account-email-label { display: grid; gap: 5px; margin: 12px 0; color: var(--muted); font-size: 12px; }
.account-email-label input { width: 100%; }
.account-actions { flex-wrap: wrap; align-items: stretch; margin-top: 16px; }
.account-actions button { flex: 1 1 100%; justify-content: center; }
.library-dialog .library-dialog-submit { background: var(--accent); color: var(--on-accent, #fff); border-color: var(--accent); }
.account-actions #logoutBtn { color: var(--danger); }
.account-dialog .account-note { margin: 4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.6; }
.account-dialog.authenticated .account-email-label,
.account-dialog.authenticated #passkeyBtn,
.account-dialog.authenticated .account-note { display: none; }
.account-dialog .account-close { display: block; margin: 12px 0 0 auto; }
.library-toast[hidden] { display: none; }
.library-toast { position: fixed; bottom: 20px; left: 50%; z-index: 2000; transform: translateX(-50%); max-width: min(440px, calc(100vw - 32px)); padding: 10px 15px; border: 1px solid var(--border); border-radius: 11px; background: var(--panel-soft); color: var(--text); box-shadow: 0 12px 32px rgba(0,0,0,.24); font-size: 13px; text-align: center; direction: rtl; }
.library-toast.error { border-color: var(--danger); color: var(--danger); }
.library-dialog { width: min(420px, calc(100vw - 32px)); padding: 22px; border: 1px solid var(--border); border-radius: 16px; background: var(--panel); color: var(--text); box-shadow: 0 24px 64px rgba(0,0,0,.35); direction: rtl; }
.library-dialog::backdrop { background: rgba(5,8,17,.65); }
.library-dialog h2 { margin: 0 0 14px; font-size: 17px; }
.library-dialog p { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.library-dialog label { display: grid; gap: 5px; margin-bottom: 16px; color: var(--muted); font-size: 12px; }
.library-dialog [hidden] { display: none !important; }
.library-dialog input, .library-dialog select { width: 100%; }
.library-dialog .library-dialog-skip { display: flex; align-items: center; gap: 8px; margin: -4px 0 16px; color: var(--muted); font-size: 12px; cursor: pointer; }
.library-dialog .library-dialog-skip input { width: auto; margin: 0; accent-color: var(--accent); }
.library-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.library-dialog .library-dialog-submit.destructive { background: var(--danger); border-color: var(--danger); }
@media (min-width: 1101px) {
  /* Both rails stay in view while the page scrolls; in the right rail the
     library takes the remaining height and scrolls on its own. */
  .app.mode-sidebar .right-rail { max-height: calc(100vh - 40px); grid-template-rows: auto minmax(0, 1fr); }
  .app.mode-sidebar .library-island { min-height: 210px; overflow: auto; scrollbar-width: thin; }
  .app.mode-sidebar .left-rail { max-height: calc(100vh - 40px); overflow: auto; scrollbar-width: thin; }
}
@media (max-width: 700px) {
  .library-island { padding: 16px; }
  .doc-tab { max-width: 160px; }
  .account-actions button { flex-basis: auto; }
}
