/* ---------- Notes app layout (on top of custom.css) ---------- */

:root
{
    --side-w: 290px;
    --line: rgba(128, 128, 128, .45);
    --hover: #f3f4f2;
    --active: #e7ebe6;
}

.app-body
{
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.app-body > header { flex: 0 0 auto; }

.app-shell
{
    flex: 1 1 auto;
    display: flex;
    min-height: 0;
}

.app-main
{
    flex: 1 1 auto;
    min-width: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.page-pad { padding: 1rem 1.5rem 3rem; }

@media (max-width: 575.98px)
{
    .page-pad { padding: .75rem 1rem 3rem; }
}

/* top nav */
.nav-slim .container-fluid { height: 100%; align-items: stretch; }
.nav-slim .navbar-brand { display: flex; align-items: center; margin: 0; }
.nav-slim .nav-auth-material { height: auto; align-self: stretch; }

.sidenav-toggle
{
    border: 0;
    border-right: .25px gray solid;
    background: #fff;
    width: 2.6em;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.link-button
{
    border: 0;
    background: none;
    padding: 0;
    color: var(--dkherbgreen);
    letter-spacing: .05em;
}

.link-button:hover { color: var(--terracotta); }

/* ---------- side nav ---------- */

.sidenav
{
    background: #fff;
    display: flex;
    flex-direction: column;
}

@media (min-width: 992px)
{
    .sidenav
    {
        flex: 0 0 var(--side-w);
        width: var(--side-w);
        border-right: .25px solid var(--line);
        overflow: hidden;
    }
}

@media (max-width: 991.98px)
{
    .sidenav.offcanvas-lg { --bs-offcanvas-width: 100vw; }
}

.sidenav-head
{
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .45rem .5rem .35rem .9rem;
    border-bottom: .25px solid var(--line);
}

.sidenav-title
{
    font-size: .8rem;
    letter-spacing: .12em;
    color: var(--herbgreen) !important;
}

.sidenav-tools { display: flex; gap: 2px; }

.icon-btn
{
    border: 0;
    background: none;
    padding: 3px 4px;
    line-height: 1;
    border-radius: 0;
}

.icon-btn:hover { background: var(--hover); }

.sidenav-filter { padding: .45rem .6rem; }
.sidenav-filter .form-control { font-size: .85rem; }

.tree
{
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 2rem;
    font-size: .92rem;
}

.tree-list { list-style: none; margin: 0; padding: 0; }

.tree-row
{
    display: flex;
    align-items: center;
    min-height: 30px;
    padding-left: calc(var(--lvl, 0) * 14px + 4px);
    padding-right: 2px;
    position: relative;
}

.tree-row:hover { background: var(--hover); }
.tree-row.active { background: var(--active); }
.tree-row.active::before
{
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3px;
    background: var(--herbgreen);
}

.tree-twist, .tree-more
{
    border: 0;
    background: none;
    padding: 0;
    width: 22px;
    height: 26px;
    flex: 0 0 22px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tree-twist .material-icons-outlined { font-size: 18px; }
.tree-twist-spacer { flex: 0 0 22px; }

.tree-link
{
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 3px 2px;
    font-weight: 300;
    color: var(--charcoal) !important;
}

.tree-link .material-icons-outlined { font-size: 18px; flex: 0 0 auto; }
.tree-row.note .tree-link .material-icons-outlined { color: #8a948a; }
.tree-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tree-more { opacity: 0; }
.tree-row:hover .tree-more, .tree-row.active .tree-more, .tree-more:focus { opacity: 1; }

@media (hover: none)
{
    .tree-more { opacity: .7; }
    .tree-row { min-height: 38px; }
}

.tree-empty
{
    padding: 2px 0 4px calc(var(--lvl, 0) * 14px + 30px);
    font-size: .78rem;
    color: #9a9a9a;
    font-style: italic;
}

.tree-none { padding: 1rem; font-size: .85rem; color: #888; }

.tree-menu
{
    position: fixed;
    z-index: 2000;
    min-width: 11rem;
    padding: 0;
}

/* ---------- breadcrumbs, folder pages ---------- */

.crumbs
{
    font-size: .8rem;
    color: #888;
    margin-bottom: .35rem;
    overflow-wrap: anywhere;
}

.crumbs .sep { margin: 0 .3rem; color: #bbb; }
.crumbs a { font-weight: 300; }

.folder-table td a { font-weight: 300; }
.file-hint { font-size: .75rem; color: #9a9a9a; margin-left: .5rem; }

.empty-state
{
    text-align: center;
    color: #8a8a8a;
    padding: 3rem 1rem;
    border: .25px dashed var(--line);
}

.empty-state .material-icons-outlined { font-size: 40px; color: #aab2a9; }

.meta-line { display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; align-items: center; }

/* ---------- editor page ---------- */

.editor-page
{
    display: flex;
    flex-direction: column;
    min-height: 100%;
}

.editor-head { padding: .75rem 1.5rem 0; }

@media (max-width: 575.98px)
{
    .editor-head { padding: .5rem .75rem 0; }
    .editor-head .btn { padding: .2rem .55rem; font-size: .9rem; }
    .editor-head #noteTitle { font-size: 1.1rem; padding: .35rem .6rem; }
    .editor-head .meta-line { gap: 0 .9rem; font-size: .75rem; }
    .editor-head .filename-field input { width: 11em; }

    /* one row: status · Save · Read · Close (Archive is hidden on phones) */
    .editor-actions { flex-wrap: nowrap !important; }
    .editor-actions #saveStatus
    {
        flex: 1 1 auto;
        min-width: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .editor-actions .btn { flex: 0 0 auto; }
}

#noteTitle { font-weight: 300; }

.filename-field
{
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    margin: 0;
}

.filename-field input
{
    border: 0;
    border-bottom: .1em solid rgba(185, 184, 184, .756);
    padding: 0 2px;
    font-size: .85rem;
    width: 16em;
    max-width: 50vw;
    color: var(--charcoal);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.filename-field input:focus { outline: 0; border-bottom-color: var(--herbgreen); }

.note-editor-wrap
{
    flex: 1 1 auto;
    padding: 0 1.5rem;
}

@media (max-width: 575.98px)
{
    .note-editor-wrap { padding: 0; }
}

.note-editor-wrap .ck.ck-editor { width: 100%; }

.note-editor-wrap .ck.ck-editor__top
{
    position: sticky;
    top: 0;
    z-index: 5;
}

.note-editor-wrap .ck-editor__editable_inline
{
    min-height: 60vh;
    /* horizontal padding reduced 10% from the original centered-column value */
    padding: 1.5rem max(1.35rem, calc((100% - 46rem) / 2 * 0.9)) !important;
}

/* writing surface + reading view typography */
.note-editor-wrap .ck-content,
.reading
{
    font-family: "Open Sans", Arial, sans-serif;
    font-weight: 400;
    font-size: 14px;
    line-height: 1.45;
    color: #000000;
}

.reading, .reading-foot { max-width: 46rem; }

/* push read view text away from the left nav (wider screens only) */
@media (min-width: 768px)
{
    .reading, .reading-foot { margin-left: 15%; }
}

.ck-content h1, .ck-content h2, .ck-content h3, .ck-content h4 { color: var(--charcoal); margin-top: 1.4em; }

.ck-content blockquote
{
    border-left: 3px solid var(--herbgreen);
    font-style: normal;
    color: #555;
}

.ck-content .cite { color: var(--dkherbgreen); }
.note-editor-wrap .ck-content .cite { background: #eef1ed; }

.ck-content .bib-entry
{
    padding-left: 2em;
    text-indent: -2em;
    margin-bottom: .5em;
}

.ck.ck-button.ck-button_with-text .ck-button__label { font-size: .85em; }

.editor-statusbar
{
    position: sticky;
    bottom: 0;
    z-index: 4;
    display: flex;
    gap: 1.25rem;
    align-items: center;
    padding: .35rem 1.5rem;
    font-size: .8rem;
    background: #fafafa;
    border-top: .25px solid var(--line);
}

.editor-statusbar strong { font-weight: 600; color: var(--herbgreen); }

.versions-menu { max-height: 60vh; overflow-y: auto; min-width: 18rem; }

/* citation picker */
.cite-list { max-height: 45vh; overflow-y: auto; border: .25px solid var(--line); }

.cite-item
{
    display: flex;
    gap: .6rem;
    align-items: flex-start;
    padding: .5rem .75rem;
    border-bottom: .25px solid #eee;
    cursor: pointer;
    margin: 0;
}

.cite-item:hover { background: var(--hover); }
.cite-item.chosen { background: var(--active); }
.cite-item input { margin-top: .35rem; }

.bib-preview { border: .25px solid var(--line); padding: 1rem 1.25rem; font-weight: 400; }

/* dialog bits */
#dlgSelect { border: .1em solid rgba(185, 184, 184, .756); padding: .4rem; }

/* ---------- print: just the text ---------- */
@media print
{
    header, .sidenav, .crumbs, .meta-line a, .read-page .d-flex.gap-2, .read-page .text-center { display: none !important; }
    .app-body { height: auto; overflow: visible; }
    .app-main { overflow: visible; }
    .reading { max-width: none; font-size: 12pt; margin-left: 0; }
    .page-break { page-break-after: always; }
}

/* ---------- sequencing: drag and drop in the side nav ---------- */
.tree-row[draggable="true"] { cursor: grab; -webkit-user-drag: element; }
.tree-row.order-dragging { opacity: .45; }
.tree-row.order-over-top { box-shadow: inset 0 2px 0 0 var(--bs-success, #4a7c59); }
.tree-row.order-over-bottom { box-shadow: inset 0 -2px 0 0 var(--bs-success, #4a7c59); }

/* ---------- phones: keep the page inside the screen ---------- */

/* nothing may push the page wider than the screen */
html, body { max-width: 100%; overflow-x: hidden; }
.app-main { overflow-x: hidden; }
.ck-content, .reading { overflow-wrap: anywhere; }
.ck-content img, .reading img { max-width: 100%; height: auto; }
.ck-content figure.table, .reading figure.table { max-width: 100%; overflow-x: auto; }

/* iOS Safari zooms in (and stays zoomed) when a field with text under 16px gets focus.
   16px on phones stops that. */
@media (max-width: 575.98px)
{
    input, select, textarea, .form-control,
    .filename-field input,
    .sidenav-filter .form-control,
    .note-editor-wrap .ck-content,
    .ck.ck-input { font-size: 16px !important; }
}

/* Phones: pin the app frame to the screen so the page itself can never slide or bounce
   (Vivaldi and other iOS browsers size their toolbars differently from Safari).
   Only the content area inside scrolls. */
@media (max-width: 575.98px)
{
    html, body { overscroll-behavior: none; }
    body.app-body
    {
        position: fixed;
        inset: 0;
        width: 100%;
        height: auto;
        overflow: hidden;
    }
    .app-main { overscroll-behavior: contain; }
}
