/*
 * FABBRAIN: the shell in the prototype's look (phase 2, Task 2): the icon
 * rail, the tree column and the tab strip. Values are tokens only
 * (fabbrain-tokens.css); js/fabbrain-ui-shell.js adds the few elements the
 * prototype has and the app had not (the "Mais" and avatar menus, the
 * workspace mark, the section label, the footer, the tab "+").
 *
 * Selectors start with html:root (and an id where the upstream rule has one)
 * so they outrank the light and the dark upstream rules by specificity and win
 * by order. !important only where the upstream declaration is !important.
 */

/* ---- Icons: the prototype's glyphs on the app's <i class="lucide"> ------- */
html:root .fabbrain-ico {
    display: inline-block;
    flex: none;
    width: var(--fb-icon);
    height: var(--fb-icon);
    background-color: currentColor;
    -webkit-mask: var(--fabbrain-glyph) center / contain no-repeat;
    mask: var(--fabbrain-glyph) center / contain no-repeat;
}

html:root .fabbrain-ico.sm { width: var(--fb-icon-sm); height: var(--fb-icon-sm); }
html:root .fabbrain-ico.xs { width: var(--fb-icon-xs); height: var(--fb-icon-xs); }

/* Rail and tree entries keep their <i>, which only changes glyph and size */
html:root #icon_sidebar .icon-sidebar-btn > .lucide,
html:root #fabbrainRailAvatarMenu .icon-sidebar-btn > .lucide {
    width: var(--fb-icon);
    height: var(--fb-icon);
    font-size: var(--fb-icon) !important;
}

html:root #fabbrainRailNotas > .lucide { -webkit-mask-image: var(--fb-icon-note); mask-image: var(--fb-icon-note); }
html:root #iconSidebarTasksBtn > .lucide { -webkit-mask-image: var(--fb-icon-tasks); mask-image: var(--fb-icon-tasks); }
html:root #iconSidebarDiaryBtn > .lucide { -webkit-mask-image: var(--fb-icon-journal); mask-image: var(--fb-icon-journal); }
html:root #iconSidebarGraphBtn > .lucide { -webkit-mask-image: var(--fb-icon-graph); mask-image: var(--fb-icon-graph); }
html:root #iconSidebarMemoriaBtn > .lucide { -webkit-mask-image: var(--fb-icon-brain); mask-image: var(--fb-icon-brain); }
html:root #iconSidebarSettingsBtn > .lucide { -webkit-mask-image: var(--fb-icon-settings); mask-image: var(--fb-icon-settings); }
/* The theme button shows where it goes: the moon in light, the sun in dark */
html:root #iconSidebarThemeToggleBtn > .lucide { -webkit-mask-image: var(--fb-icon-moon); mask-image: var(--fb-icon-moon); }
html:root[data-theme='dark'] #iconSidebarThemeToggleBtn > .lucide { -webkit-mask-image: var(--fb-icon-sun); mask-image: var(--fb-icon-sun); }
/* In the "Mais" menu, the destinations the prototype draws keep its glyph */
html:root #iconSidebarDashboardBtn > .lucide { -webkit-mask-image: var(--fb-icon-dashboard); mask-image: var(--fb-icon-dashboard); }
html:root #iconSidebarFoldersBtn > .lucide { -webkit-mask-image: var(--fb-icon-folder); mask-image: var(--fb-icon-folder); }
html:root #iconSidebarTagsBtn > .lucide { -webkit-mask-image: var(--fb-icon-tag); mask-image: var(--fb-icon-tag); }
/* FABBRAIN (fase 4b, Tarefa 4): the share glyph of the note bar, not a people glyph (review of Task 3) */
html:root #iconSidebarSharesBtn > .lucide { -webkit-mask-image: var(--fb-icon-share); mask-image: var(--fb-icon-share); }
html:root #iconSidebarAttachmentsBtn > .lucide { -webkit-mask-image: var(--fb-icon-clip); mask-image: var(--fb-icon-clip); }
html:root #iconSidebarTrashBtn > .lucide { -webkit-mask-image: var(--fb-icon-trash); mask-image: var(--fb-icon-trash); }
html:root #iconSidebarAboutBtn > .lucide { -webkit-mask-image: var(--fb-icon-info); mask-image: var(--fb-icon-info); }
html:root #iconSidebarLogoutBtn > .lucide { -webkit-mask-image: var(--fb-icon-logout); mask-image: var(--fb-icon-logout); }
html:root #iconSidebarNotesBtn > .lucide { -webkit-mask-image: var(--fb-icon-info2); mask-image: var(--fb-icon-info2); }

/* ---- 1. Rail --------------------------------------------------------------- */
html:root {
    --icon-sidebar-width: var(--fb-rail-width);
}

html:root #icon_sidebar {
    width: var(--fb-rail-width);
    padding: var(--fb-space-7) 0 var(--fb-space-6);
    gap: var(--fb-space-2);
    background: var(--fb-rail);
    border-right: 0;
}

/* The mark at the top: a letter on a text-coloured tile. Still the Home link */
html:root #iconSidebarHomeBtn {
    width: var(--fb-btn-height);
    height: var(--fb-btn-height);
    margin: 0 0 var(--fb-space-9);
    border-radius: var(--fb-radius);
    background: var(--fb-text);
    color: var(--fb-bg);
    font-size: var(--fb-text-base);
    font-weight: var(--fb-weight-semibold);
    letter-spacing: var(--fb-tracking-logo);
    line-height: 1;
}

html:root #iconSidebarHomeBtn > * {
    display: none;
}

html:root #iconSidebarHomeBtn::before {
    content: var(--fb-mark-letter);
}

html:root #iconSidebarHomeBtn:hover,
html:root #iconSidebarHomeBtn:focus-visible {
    background: var(--fb-text);
}

html:root #icon_sidebar .icon-sidebar-scroll {
    gap: var(--fb-space-2);
    flex: 0 1 auto;
}

html:root #icon_sidebar .icon-sidebar-divider,
html:root #icon_sidebar #iconSidebarOverflowBtn {
    display: none;
}

html:root #icon_sidebar .fabbrain-rail-gap {
    flex: none;
    height: var(--fb-space-7);
}

html:root #icon_sidebar .fabbrain-rail-spacer {
    flex: 1 1 auto;
}

html:root #icon_sidebar .icon-sidebar-btn {
    width: var(--fb-rail-btn);
    height: var(--fb-rail-btn);
    border-radius: var(--fb-radius-rail);
    color: var(--fb-muted);
    background: transparent;
}

html:root #icon_sidebar .icon-sidebar-btn:hover,
html:root #icon_sidebar .icon-sidebar-btn:focus-visible {
    color: var(--fb-text);
    background: var(--fb-hover);
}

/* The current destination: a soft filled pill, in text colour, not the accent */
html:root #icon_sidebar .icon-sidebar-btn.icon-sidebar-btn-active,
html:root #icon_sidebar .icon-sidebar-btn[aria-current="page"],
html:root #icon_sidebar .icon-sidebar-btn[aria-expanded="true"] {
    color: var(--fb-text);
    background: var(--fb-active);
}

/* The icon takes the button's colour in every state (the dark layer paints
   the current page's icon in the accent) */
html:root #icon_sidebar .icon-sidebar-btn .lucide {
    background-color: currentColor;
}

/* Account group: theme, settings, the avatar. No divider above it. */
html:root #icon_sidebar .icon-sidebar-bottom {
    gap: var(--fb-space-2);
    margin: auto 0 0;
    padding: 0;
    border-top: 0;
    align-self: center;
}

html:root #icon_sidebar .icon-sidebar-bottom .icon-sidebar-btn {
    height: var(--fb-rail-btn);
}

html:root #icon_sidebar .fabbrain-avatar {
    display: grid;
    place-items: center;
    width: var(--fb-btn-height);
    height: var(--fb-btn-height);
    margin-top: var(--fb-space-4);
    padding: 0;
    border: 0;
    border-radius: var(--fb-radius-round);
    background: var(--fb-avatar-bg);
    color: var(--fb-avatar-text);
    font: inherit;
    font-size: var(--fb-text-2xs);
    font-weight: var(--fb-weight-semibold);
    cursor: pointer;
}

/* The rail's own collapse chevron: kept, quiet until the rail is pointed at */
html:root #iconSidebarToggle {
    opacity: 0;
    transition: opacity var(--fb-dur-fast) var(--fb-ease);
}

html:root #icon_sidebar:hover ~ #iconSidebarToggle,
html:root #iconSidebarToggle:hover,
html:root #iconSidebarToggle:focus-visible,
html:root body.icon-sidebar-collapsed #iconSidebarToggle {
    opacity: 1;
}

/* ---- 2. Popovers (the "Mais", avatar, create and pending menus) ------------ */
html:root .fabbrain-pop,
html:root #create-menu {
    position: fixed;
    z-index: 10001;
    min-width: var(--fb-pop-min);
    padding: var(--fb-space-3);
    border: 0;
    border-radius: var(--fb-radius-lg);
    background: var(--fb-surface-raised);
    box-shadow: var(--fb-shadow);
    color: var(--fb-text);
    font-size: var(--fb-text-base);
    line-height: var(--fb-leading-base);
}

html:root .fabbrain-pop[hidden] {
    display: none;
}

html:root .fabbrain-pop:not([hidden]),
html:root #create-menu.show {
    animation: fabbrain-pop var(--fb-dur-pop) var(--fb-ease-out);
}

@keyframes fabbrain-pop {
    from { opacity: 0; transform: translateY(calc(-1 * var(--fb-space-2))); }
    to { opacity: 1; transform: none; }
}

html:root .fabbrain-pop .fabbrain-ph {
    padding: var(--fb-space-3) var(--fb-space-5) var(--fb-space-2);
    font-size: var(--fb-text-xs);
    color: var(--fb-muted);
}

html:root .fabbrain-pop hr,
html:root #create-menu .create-section + .create-section:not([style*="none"])::before {
    content: "";
    display: block;
    height: var(--fb-hairline);
    margin: var(--fb-space-3) var(--fb-space-3);
    border: 0;
    background: var(--fb-line);
}

/* A menu item: icon, label, an optional hint at the right */
html:root .fabbrain-pop .fabbrain-mi,
html:root #icon_sidebar .fabbrain-pop .icon-sidebar-btn,
html:root #create-menu .create-menu-item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: var(--fb-space-gap-mi);
    width: 100%;
    height: auto;
    min-height: 0;
    padding: var(--fb-space-gap-row) var(--fb-space-5);
    margin: 0;
    border: 0;
    border-radius: var(--fb-radius);
    background: transparent;
    color: var(--fb-text);
    font: inherit;
    font-size: var(--fb-text-base);
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    box-sizing: border-box;
}

html:root .fabbrain-pop .fabbrain-mi:hover,
html:root .fabbrain-pop .fabbrain-mi:focus-visible,
html:root #icon_sidebar .fabbrain-pop .icon-sidebar-btn:hover,
html:root #icon_sidebar .fabbrain-pop .icon-sidebar-btn:focus-visible,
html:root #create-menu .create-menu-item:hover,
html:root #create-menu .create-menu-item:focus-visible {
    background: var(--fb-hover);
    color: var(--fb-text);
}

html:root #icon_sidebar .fabbrain-pop .icon-sidebar-btn.icon-sidebar-btn-active {
    color: var(--fb-text);
    background: var(--fb-active);
}

html:root .fabbrain-pop .fabbrain-mi > .lucide,
html:root .fabbrain-pop .fabbrain-mi > .fabbrain-ico,
html:root #icon_sidebar .fabbrain-pop .icon-sidebar-btn > .lucide,
html:root #create-menu .create-menu-item > .lucide {
    flex: none;
    width: var(--fb-icon);
    height: var(--fb-icon);
    font-size: var(--fb-icon) !important;
    color: var(--fb-muted);
    margin: 0;
}

html:root .fabbrain-pop .fabbrain-rail-rotulo,
html:root #create-menu .create-menu-item > span {
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;
}

/* The badges the rail entries carry stay with them, at the end of the row */
html:root .fabbrain-pop .icon-sidebar-btn .update-badge,
html:root .fabbrain-pop .icon-sidebar-btn .attention-badge,
html:root .fabbrain-pop .icon-sidebar-btn .mention-badge {
    position: static;
    margin-left: auto;
}

html:root .fabbrain-pop .fabbrain-mi-danger,
html:root .fabbrain-pop .fabbrain-mi-danger > .lucide {
    color: var(--fb-danger);
}

/* The "+" menu: the prototype's width and glyphs, a line under each choice */
html:root #create-menu .create-menu-item[data-type="html"] > .lucide { -webkit-mask-image: var(--fb-icon-note); mask-image: var(--fb-icon-note); }
html:root #create-menu .create-menu-item[data-type="canvas"] > .lucide { -webkit-mask-image: var(--fb-icon-canvas); mask-image: var(--fb-icon-canvas); }
html:root #create-menu .create-menu-item[data-type="list"] > .lucide { -webkit-mask-image: var(--fb-icon-tasks); mask-image: var(--fb-icon-tasks); }
html:root #create-menu .create-menu-item[data-type="diary"] > .lucide { -webkit-mask-image: var(--fb-icon-journal); mask-image: var(--fb-icon-journal); }
html:root #create-menu .create-menu-item[data-type="folder"] > .lucide,
html:root #create-menu .create-menu-item[data-type="subfolder"] > .lucide { -webkit-mask-image: var(--fb-icon-folder); mask-image: var(--fb-icon-folder); }

html:root #create-menu {
    min-width: var(--fb-pop-plus-min);
}

/* FABBRAIN (fase 4b, Tarefa 3): one divider only, a border on #otherSection ("Pasta"); the generated rule between
   sections (and the one a visible #columnSection added) is gone */
html:root #create-menu .create-section + .create-section::before,
html:root #create-menu .create-section + .create-section:not([style*="none"])::before {
    content: none;
    display: none;
}

html:root #create-menu #otherSection:not([style*="none"]) {
    margin-top: var(--fb-space-3);
    padding-top: var(--fb-space-3);
    border-top: var(--fb-hairline) solid var(--fb-line);
}

html:root #create-menu .create-menu-item > span[data-fabbrain-desc]::after {
    content: attr(data-fabbrain-desc);
    display: block;
    margin-top: calc(-1 * var(--fb-hairline));
    font-size: var(--fb-text-xs);
    color: var(--fb-muted);
}

/* ---- 3. Tree column -------------------------------------------------------- */
html:root {
    --left-col-width: var(--fb-tree-width);
    --sidebar-font-size: var(--fb-text-row);
}

html:root #left_col {
    padding: 0;
    background: var(--fb-side);
    border-right: 0;
}

/* The column's resize handle: no line at rest (the grounds already part the
   columns), the hairline only while it is pointed at or dragged */
html:root #resizeHandle {
    border-right-color: transparent;
    background: transparent;
}

html:root #resizeHandle:hover,
html:root #resizeHandle.dragging,
html:root #resizeHandle.resizing {
    border-right-color: var(--fb-line);
}

/* Workspace header: mark, name and subtitle, "+" at the right */
html:root #left_col .sidebar-header {
    padding: var(--fb-space-8) var(--fb-space-7) var(--fb-space-5) var(--fb-space-9);
    margin: 0;
}

html:root #left_col .sidebar-title-row {
    display: flex;
    align-items: center;
    gap: var(--fb-space-5);
    padding: 0;
    min-height: 0;
}

html:root #left_col .sidebar-title {
    display: flex;
    align-items: center;
    gap: var(--fb-space-5);
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    padding: 0;
    justify-content: flex-start;
    text-align: left;
    font-size: var(--fb-text-base);
    font-weight: var(--fb-weight-semibold);
    letter-spacing: var(--fb-tracking-tight);
    color: var(--fb-text);
}

html:root #left_col .sidebar-title .workspace-dropdown-icon {
    display: none;
}

/* FABBRAIN (fase 4b, Tarefa 3): the title opens nothing (no workspace selector) */
html:root #left_col .sidebar-title:not([data-action]) {
    cursor: default;
}

html:root #left_col .fabbrain-ws-name .workspace-title-text[hidden] {
    display: none;
}

html:root #left_col .fabbrain-ws-mark {
    display: grid;
    place-items: center;
    flex: none;
    width: var(--fb-ws-mark);
    height: var(--fb-ws-mark);
    border-radius: var(--fb-radius-sm);
    background: var(--fb-ws-mark-bg);
    color: var(--fb-ws-mark-text);
    font-size: var(--fb-text-2xs);
    font-weight: var(--fb-weight-semibold);
    letter-spacing: 0;
}

html:root #left_col .fabbrain-ws-name {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: var(--fb-leading-base);
}

html:root #left_col .fabbrain-ws-name .workspace-title-text,
/* FABBRAIN (fase 4b, Tarefa 3): the product's name in the header; the workspace's own text is hidden */
html:root #left_col .fabbrain-ws-name .fabbrain-ws-app {
    font-size: var(--fb-text-base);
    font-weight: var(--fb-weight-semibold);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

html:root #left_col .fabbrain-ws-sub {
    margin-top: calc(-1 * var(--fb-hairline));
    font-size: var(--fb-text-xs);
    font-weight: var(--fb-weight-regular);
    letter-spacing: 0;
    color: var(--fb-muted);
}

html:root #left_col .sidebar-title-actions {
    gap: 0;
}

html:root #left_col .sidebar-plus,
html:root #left_col .sidebar-title-actions .sidebar-folder-toggle {
    width: var(--fb-row-height);
    height: var(--fb-row-height);
    min-width: var(--fb-row-height);
    min-height: var(--fb-row-height);
    padding: 0;
    border-radius: var(--fb-radius);
    color: var(--fb-muted) !important;
    background: transparent;
}

html:root #left_col .sidebar-plus:focus:not(:focus-visible) {
    outline: none;
}

html:root #left_col .sidebar-plus:hover,
html:root #left_col .sidebar-plus[aria-expanded="true"],
html:root #left_col .sidebar-title-actions .sidebar-folder-toggle:hover {
    background: var(--fb-hover);
    color: var(--fb-text) !important;
}

html:root #left_col .sidebar-plus > .lucide {
    color: inherit !important;
    background-color: currentColor !important;
    width: var(--fb-icon);
    height: var(--fb-icon);
    font-size: var(--fb-icon) !important;
    -webkit-mask-image: var(--fb-icon-plus);
    mask-image: var(--fb-icon-plus);
}

/* Search: a quiet field with the glass, the shortcut at the right */
html:root #left_col #search-bar-container {
    width: auto;
    height: auto;
    min-height: 0;
    margin: var(--fb-space-3) var(--fb-space-6) var(--fb-space-7);
    padding: 0;
}

html:root #left_col .searchbar-row {
    position: relative;
    display: flex;
    width: 100%;
    margin: 0;
    box-sizing: border-box;
    align-items: center;
    height: var(--fb-search-height);
    padding: 0 var(--fb-space-5);
    gap: var(--fb-space-4);
    border-radius: var(--fb-radius);
    background: var(--fb-fill);
    color: var(--fb-muted);
}

html:root #left_col .searchbar-row::before {
    content: "";
    flex: none;
    order: -2;
    width: var(--fb-icon-sm);
    height: var(--fb-icon-sm);
    background-color: currentColor;
    -webkit-mask: var(--fb-icon-search) center / contain no-repeat;
    mask: var(--fb-icon-search) center / contain no-repeat;
}

html:root #left_col .searchbar-input-wrapper {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: var(--fb-space-3);
}

html:root #left_col #unified-search {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    height: var(--fb-search-height);
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    font-size: var(--fb-text-row);
    color: var(--fb-text);
}

html:root #left_col #unified-search:focus {
    outline: none;
    box-shadow: none;
}

html:root #left_col .searchbar-row:focus-within {
    box-shadow: 0 0 0 var(--fb-focus-ring) var(--fb-accent-soft);
}

html:root #left_col #unified-search-form,
html:root #left_col .unified-search-container {
    margin: 0;
    padding: 0;
}

/* The search's own controls (scope, date, help) stay, at the right, faint,
   and show while the field is in use; at rest the field reads as in the
   prototype: the glass, the words, the shortcut */
html:root #left_col .searchbar-row:not(:focus-within):not(:hover) .searchbar-type-icons,
html:root #left_col .searchbar-row:not(:focus-within):not(:hover) .searchbar-date-toggle,
html:root #left_col .searchbar-row:not(:focus-within):not(:hover) .searchbar-side-btn {
    display: none;
}

html:root #left_col .searchbar-row:is(:focus-within, :hover) .fabbrain-kbd {
    display: none;
}
html:root #left_col .searchbar-type-icons,
html:root #left_col .searchbar-date-toggle {
    position: static;
    order: 2;
    gap: 0;
    transform: none;
}

html:root #left_col .searchbar-type-btn,
html:root #left_col .searchbar-date-toggle,
html:root #left_col .searchbar-info,
html:root #left_col .searchbar-row .search-help-btn,
html:root #left_col .searchbar-row .searchbar-side-btn {
    width: var(--fb-chip-height);
    height: var(--fb-chip-height);
    min-width: 0;
    padding: 0;
    border: 0;
    border-radius: var(--fb-radius-sm);
    background: transparent;
    color: var(--fb-faint);
    font-size: var(--fb-icon-xs);
}

html:root #left_col .searchbar-type-btn.active {
    color: var(--fb-muted);
}

/* The search field's own glyphs take the token palette (fix wave): upstream
   paints the scope buttons in the accent (icons.css paints every lucide glyph
   so), the date toggle in the accent when on and the clear × in the danger
   colour. Off: faint; on: the text colour; the × (not destructive): muted. */
html:root #left_col .searchbar-row .searchbar-type-btn i[class*="lucide-"],
html:root #left_col .searchbar-row .searchbar-type-btn i[class*="lucide-"]:hover,
html:root #left_col .searchbar-row .searchbar-date-toggle i {
    color: inherit;
}

html:root #left_col .searchbar-row .searchbar-type-btn.active,
html:root #left_col .searchbar-row .searchbar-type-btn.active:hover,
html:root #left_col .searchbar-row .searchbar-date-toggle.active {
    color: var(--fb-text-2);
}

html:root #left_col .searchbar-row .searchbar-side-clear,
html:root #left_col .searchbar-row .searchbar-side-clear i[class*="lucide-"],
html:root #left_col .searchbar-row .searchbar-clear,
html:root #left_col .searchbar-row .searchbar-clear .clear-icon,
html:root #left_col .searchbar-row .searchbar-clear i[class*="lucide-"] {
    color: var(--fb-muted);
}

html:root #left_col .searchbar-row .searchbar-side-clear:hover i[class*="lucide-"],
html:root #left_col .searchbar-row .searchbar-clear:hover .clear-icon,
html:root #left_col .searchbar-row .searchbar-clear:hover i[class*="lucide-"] {
    color: var(--fb-text);
}

html:root #left_col .fabbrain-kbd {
    flex: none;
    font-size: var(--fb-text-2xs);
    color: var(--fb-muted); /* text: 4.5:1 or better (fix wave; --fb-faint is for glyphs only) */
    white-space: nowrap;
}

/* The tree itself */
html:root #left_col .notes-list-scrollable-content {
    padding: 0 var(--fb-space-4) var(--fb-space-10);
}

/* "Pastas" and, at the right, the tree's own controls, faint until pointed at */
html:root #left_col .notes-list-actions {
    display: flex;
    align-items: center;
    gap: 0;
    margin: 0;
    padding: var(--fb-space-7) 0 var(--fb-space-3) var(--fb-space-5);
    border: 0;
    min-height: 0;
}

html:root #left_col .notes-list-actions::before,
html:root #left_col .notes-list-actions::after {
    content: none;
}

html:root #left_col .fabbrain-sect {
    flex: 1 1 auto;
    font-size: var(--fb-text-xs);
    font-weight: var(--fb-weight-medium);
    color: var(--fb-muted);
}

html:root #left_col .notes-list-actions > button {
    width: var(--fb-chip-height);
    height: var(--fb-space-9);
    min-width: 0;
    min-height: 0;
    padding: 0;
    color: var(--fb-faint) !important;
    opacity: 0;
    transition: opacity var(--fb-dur-fast) var(--fb-ease);
}

html:root #left_col .notes-list-actions:hover > button,
html:root #left_col .notes-list-actions:focus-within > button,
html:root #left_col .notes-list-actions > button[aria-expanded="true"],
html:root #left_col .notes-list-actions > button[aria-pressed="true"] {
    opacity: 1;
}

/* Depth of a row, without the nested margins: rows span the whole column and
   indent their content, as in the prototype (8px, then 16px a level) */
html:root #left_col { --fabbrain-depth: 0; }
html:root #left_col .folder-content { --fabbrain-depth: 1; margin: 0; }
html:root #left_col .folder-content .folder-content { --fabbrain-depth: 2; }
html:root #left_col .folder-content .folder-content .folder-content { --fabbrain-depth: 3; }
html:root #left_col .folder-content .folder-content .folder-content .folder-content { --fabbrain-depth: 4; }
html:root #left_col .folder-content .folder-content .folder-content .folder-content .folder-content { --fabbrain-depth: 5; }
html:root #left_col .folder-content .folder-content .folder-content .folder-content .folder-content .folder-content { --fabbrain-depth: 6; }

html:root #left_col .folder-content > .folder-header,
html:root #left_col .folder-header {
    margin: 0;
    padding: 0;
}

html:root #left_col .pxbetweennotes {
    display: none;
}

/* Folder row: chevron that turns, the name, the count when closed */
html:root #left_col .folder-toggle {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--fb-space-gap-row);
    height: var(--fb-row-height);
    margin: 0;
    padding: 0 var(--fb-space-4) 0 calc(var(--fb-tree-pad) + var(--fabbrain-depth) * var(--fb-tree-indent));
    border-radius: var(--fb-radius-row);
    background: transparent;
    box-sizing: border-box;
    font-size: var(--fb-text-row);
}

html:root #left_col .folder-toggle:hover {
    background: var(--fb-hover);
}

html:root #left_col .folder-toggle::after {
    content: "";
    order: -1;
    flex: none;
    width: var(--fb-chev);
    height: var(--fb-chev);
    background-color: var(--fb-faint);
    -webkit-mask: var(--fb-icon-chev) center / contain no-repeat;
    mask: var(--fb-icon-chev) center / contain no-repeat;
    transition: transform var(--fb-dur-chev) var(--fb-ease);
}

html:root #left_col .folder-header[data-fb-aberta] > .folder-toggle::after {
    transform: rotate(90deg);
}

/* The folder glyph is the app's (it opens the icon picker): a chosen icon
   stays, the default one gives way to the chevron */
html:root #left_col .folder-toggle > .folder-icon[data-custom-icon="false"] {
    display: none;
}

html:root #left_col .folder-toggle > .folder-icon {
    margin: 0;
    font-size: var(--fb-icon-sm) !important;
    color: var(--fb-faint);
}

html:root #left_col .folder-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: var(--fb-text-row);
    font-weight: var(--fb-weight-medium);
    color: var(--fb-text);
}

html:root #left_col .folder-note-count {
    height: auto;
    margin: 0;
    padding: 0;
    border-radius: 0;
    background: transparent;
    font-size: var(--fb-text-xs);
    font-weight: var(--fb-weight-regular);
    line-height: inherit;
    color: var(--fb-muted); /* text: 4.5:1 or better (fix wave; --fb-faint is for glyphs only) */
}

html:root #left_col .folder-header[data-fb-aberta] > .folder-toggle > .folder-note-count {
    display: none;
}

html:root #left_col .folder-toggle > .folder-actions {
    display: flex;
    align-items: center;
    margin: 0;
}

/* Item row: the kind's glyph, the title, the amber dot at the right */
html:root #left_col .note-list-item {
    position: relative;
    display: flex;
    align-items: center;
    margin: 0;
    padding: 0;
}

html:root #left_col a.links_arbo_left,
html:root #left_col a.links_arbo_left.note-in-folder,
html:root #left_col a.links_arbo_left.note-without-folder {
    position: relative;
    display: flex !important;
    align-items: center;
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    height: var(--fb-row-height);
    margin: 0 !important;
    padding: 0 var(--fb-space-4) 0 calc(var(--fb-tree-pad) + var(--fabbrain-depth) * var(--fb-tree-indent) + var(--fb-tree-leaf-offset)) !important;
    border-radius: var(--fb-radius-row);
    background: transparent;
    color: var(--fb-text-2);
    font-size: var(--fb-text-row);
    line-height: var(--fb-leading-base);
    box-sizing: border-box;
}

html:root #left_col a.links_arbo_left:hover {
    background: var(--fb-hover);
}

html:root #left_col a.links_arbo_left.selected-note,
html:root[data-theme='dark'] #left_col a.links_arbo_left.selected-note {
    background: var(--fb-active) !important;
    border-radius: var(--fb-radius-row);
}

/* Hover only changes the ground (upstream turns the title to the accent) */
html:root #left_col a.links_arbo_left:hover .note-title,
html:root[data-theme='dark'] #left_col a.links_arbo_left:hover .note-title {
    color: var(--fb-text-2) !important;
}

html:root #left_col a.links_arbo_left.selected-note:hover .note-title,
html:root[data-theme='dark'] #left_col a.links_arbo_left.selected-note:hover .note-title {
    color: var(--fb-text) !important;
}

html:root #left_col a.links_arbo_left .note-title {
    display: block !important;
    flex: 1 1 auto;
    min-width: 0;
    margin: 0 !important;
    overflow: hidden !important;
    white-space: nowrap !important;
    text-overflow: ellipsis !important;
    font-size: var(--fb-text-row);
}

/* FABBRAIN (fase 4d): room for the signal (14 px and a gap) at rest; on hover the signal moves left of the row's "…",
   so the title gives room for both (only its ellipsis moves: the start, the height and the line stay) */
html:root #left_col a.links_arbo_left:has(.fabbrain-nc-dot, .fabbrain-fora-sinal) .note-title {
    padding-right: calc(var(--fb-tree-signal) + var(--fb-space-3));
}

html:root #left_col .note-list-item:hover a.links_arbo_left:has(.fabbrain-nc-dot, .fabbrain-fora-sinal) .note-title,
html:root #left_col .note-list-item:focus-within a.links_arbo_left:has(.fabbrain-nc-dot, .fabbrain-fora-sinal) .note-title {
    padding-right: calc(var(--fb-tree-signal-hover-right) - var(--fb-space-4) + var(--fb-tree-signal) + var(--fb-space-3));
}

html:root #left_col a.links_arbo_left .note-icon {
    width: var(--fb-icon-sm);
    height: var(--fb-icon-sm);
    margin: 0 var(--fb-space-gap-row) 0 0;
    font-size: var(--fb-icon-sm) !important;
    vertical-align: calc(-1 * var(--fb-space-1));
    color: var(--fb-faint);
}

html:root #left_col a.links_arbo_left.selected-note .note-icon {
    color: var(--fb-text-2);
}

html:root #left_col a.links_arbo_left .note-icon[data-custom-icon="false"] {
    -webkit-mask-image: var(--fb-icon-note);
    mask-image: var(--fb-icon-note);
}

html:root #left_col a.links_arbo_left[data-type="excalidraw"] .note-icon[data-custom-icon="false"] {
    -webkit-mask-image: var(--fb-icon-canvas);
    mask-image: var(--fb-icon-canvas);
}

/* FABBRAIN (fase 4d): "Feito por IA, falta revisar" and "N trechos feitos por IA": the robot (--fb-icon-robot) in the
   warning amber, 14 px, at the end of the row (it was the prototype's 6 px amber dot) */
html:root #left_col a.links_arbo_left .fabbrain-nc-dot {
    position: absolute;
    top: 50%;
    right: var(--fb-space-4);
    width: var(--fb-tree-signal);
    height: var(--fb-tree-signal);
    margin: calc(-0.5 * var(--fb-tree-signal)) 0 0;
    border-radius: 0;
    background-color: var(--fb-warn);
    -webkit-mask: var(--fb-icon-robot) center / contain no-repeat;
    mask: var(--fb-icon-robot) center / contain no-repeat;
    transition: right var(--fb-dur-fast) var(--fb-ease);
}

/* "Kept offline in this browser" (js/offline-marks.js): the prototype has no
   such mark; the state stays in the note's actions menu and on the Offline
   page, so the row does not carry a second dot next to the amber one */
html:root #left_col a.links_arbo_left .offline-mark {
    display: none;
}

/* The row's own actions (⋮): at the end of the row, only when pointed at */
html:root #left_col .note-list-item > .note-actions {
    position: absolute;
    top: 50%;
    right: var(--fb-space-1);
    margin: 0;
    transform: translateY(-50%);
    opacity: 0;
    transition: opacity var(--fb-dur-fast) var(--fb-ease);
}

html:root #left_col .note-list-item:hover > .note-actions,
html:root #left_col .note-list-item:focus-within > .note-actions,
html:root #left_col .folder-toggle:hover .folder-actions,
html:root #left_col .folder-toggle:focus-within .folder-actions {
    opacity: 1;
}

html:root #left_col .folder-toggle .folder-actions {
    opacity: 0;
    transition: opacity var(--fb-dur-fast) var(--fb-ease);
}

/* FABBRAIN (fase 4d): "Fora da memória · você deixou fora": Lucide's brain-off (--fb-icon-brain-off) in the muted grey,
   no colour (the amber wins), 14 px where the robot is */
html:root #left_col a.links_arbo_left .fabbrain-fora-sinal {
    position: absolute;
    top: 50%;
    right: var(--fb-space-4);
    width: var(--fb-tree-signal);
    height: var(--fb-tree-signal);
    margin: calc(-0.5 * var(--fb-tree-signal)) 0 0;
    background-color: var(--fb-muted);
    -webkit-mask: var(--fb-icon-brain-off) center / contain no-repeat;
    mask: var(--fb-icon-brain-off) center / contain no-repeat;
    transition: right var(--fb-dur-fast) var(--fb-ease);
}

/* FABBRAIN (fase 4d): on hover (or with the focus in the row) the signal stays: it moves left, and the row's "…"
   shows right of it, apart (--fb-tree-signal-hover-right: the "…" box, its 2 px from the edge and a 4 px gap) */
html:root #left_col .note-list-item:hover a.links_arbo_left :is(.fabbrain-nc-dot, .fabbrain-fora-sinal),
html:root #left_col .note-list-item:focus-within a.links_arbo_left :is(.fabbrain-nc-dot, .fabbrain-fora-sinal) {
    right: var(--fb-tree-signal-hover-right);
}

html:root #left_col a.links_arbo_left :is(.fabbrain-nc-dot, .fabbrain-fora-sinal):focus-visible {
    outline: var(--fb-focus-ring) solid var(--fb-accent);
    outline-offset: var(--fb-space-1);
}

html:root #left_col .note-actions-toggle,
html:root #left_col .folder-actions-toggle {
    width: var(--fb-chip-height);
    height: var(--fb-chip-height);
    min-width: 0;
    padding: 0;
    border: 0;
    border-radius: var(--fb-radius-sm);
    background: transparent;
    color: var(--fb-faint);
    display: inline-grid;
    place-items: center;
}

html:root #left_col .note-actions-toggle:hover,
html:root #left_col .folder-actions-toggle:hover {
    background: var(--fb-hover);
    color: var(--fb-text);
}

/* FABBRAIN (fase 4b, Tarefa 6): the upstream mini calendar (a floating icon over the tree) is hidden by
   css/fabbrain-ocultos.css; the calendar is now the section at the foot of the column (below, "Calendar section"). */

/* ---- Calendar section (phase 4b, Task 6) ------------------------------------
   The prototype's .cal: a fixed section at the foot of the column (flex: none, so the tree above it scrolls and is never
   covered), a header that collapses and opens it, the month, the days with a dot where there is a diary entry or a task
   due. js/fabbrain-calendario.js fills it. */
html:root #left_col .notes-list-scrollable-content {
    min-height: var(--fb-cal-tree-min);
}

html:root #left_col #fabbrainCalendario {
    flex: none;
    border-top: var(--fb-hairline) solid var(--fb-line);
    background: var(--fb-side);
}

html:root #left_col #fabbrainCalendario .fabbrain-cal-cab {
    display: flex;
    align-items: center;
    gap: var(--fb-space-4);
    box-sizing: border-box;
    width: 100%;
    margin: 0;
    padding: var(--fb-cal-head-pad-y) var(--fb-space-9);
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--fb-muted);
    font: inherit;
    font-size: var(--fb-text-xs);
    line-height: var(--fb-leading-base);
    text-align: left;
    cursor: pointer;
}

html:root #left_col #fabbrainCalendario .fabbrain-cal-cab:hover {
    color: var(--fb-text);
}

html:root #left_col #fabbrainCalendario .fabbrain-cal-cab:focus-visible,
html:root #left_col #fabbrainCalendario .fabbrain-cal-nav:focus-visible,
html:root #left_col #fabbrainCalendario .fabbrain-cal-dia:focus-visible {
    outline: var(--fb-focus-ring) solid var(--fb-accent);
    outline-offset: calc(-1 * var(--fb-focus-ring));
}

html:root #left_col #fabbrainCalendario .fabbrain-cal-icone {
    --fabbrain-glyph: var(--fb-icon-cal);
}

/* open: the chevron points down; collapsed: right (the tree's own chevron) */
html:root #left_col #fabbrainCalendario .fabbrain-cal-seta {
    --fabbrain-glyph: var(--fb-icon-chev);
    margin-left: auto;
    color: var(--fb-faint);
    transform: rotate(90deg);
    transition: transform var(--fb-dur-fast) var(--fb-ease);
}

html:root #left_col #fabbrainCalendario.fechado .fabbrain-cal-seta {
    transform: none;
}

html:root #left_col #fabbrainCalendario .fabbrain-cal-corpo {
    padding: 0 var(--fb-space-7) var(--fb-space-6);
}

html:root #left_col #fabbrainCalendario .fabbrain-cal-corpo[hidden] {
    display: none;
}

html:root #left_col #fabbrainCalendario .fabbrain-cal-mes {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--fb-space-2) var(--fb-space-3);
    color: var(--fb-text);
    font-size: var(--fb-text-ui);
    font-weight: var(--fb-weight-medium);
}

html:root #left_col #fabbrainCalendario .fabbrain-cal-nav {
    display: grid;
    place-items: center;
    width: var(--fb-cal-nav);
    height: var(--fb-cal-nav);
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: var(--fb-radius-sm);
    background: transparent;
    color: var(--fb-muted);
    cursor: pointer;
}

html:root #left_col #fabbrainCalendario .fabbrain-cal-nav:hover {
    background: var(--fb-hover);
    color: var(--fb-text);
}

html:root #left_col #fabbrainCalendario .fabbrain-cal-nav .esq {
    transform: scaleX(-1);
}

html:root #left_col #fabbrainCalendario .fabbrain-cal-grade {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: var(--fb-hairline);
    text-align: center;
    font-size: var(--fb-text-xs);
}

html:root #left_col #fabbrainCalendario .fabbrain-cal-semana {
    padding: var(--fb-space-1) 0;
    color: var(--fb-muted);
}

html:root #left_col #fabbrainCalendario .fabbrain-cal-dia {
    position: relative;
    height: var(--fb-cal-day);
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: var(--fb-radius-row);
    background: transparent;
    color: var(--fb-text-2);
    font: inherit;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
}

html:root #left_col #fabbrainCalendario .fabbrain-cal-dia:hover {
    background: var(--fb-hover);
}

html:root #left_col #fabbrainCalendario .fabbrain-cal-dia.fora {
    color: var(--fb-faint);
}

html:root #left_col #fabbrainCalendario .fabbrain-cal-dia.hoje {
    background: var(--fb-accent);
    color: var(--fb-on-accent);
    font-weight: var(--fb-weight-semibold);
}

html:root #left_col #fabbrainCalendario .fabbrain-cal-dia.tem::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: var(--fb-cal-dot-bottom);
    width: var(--fb-cal-dot);
    height: var(--fb-cal-dot);
    margin-left: calc(-1 * var(--fb-cal-dot) / 2);
    border-radius: var(--fb-radius-round);
    background: var(--fb-accent);
}

html:root #left_col #fabbrainCalendario .fabbrain-cal-dia.hoje.tem::after {
    background: var(--fb-on-accent);
}

/* The column's collapse chevron at its bottom edge: quiet until pointed at */
html:root #toggleSidebarBtn {
    opacity: 0;
    transition: opacity var(--fb-dur-fast) var(--fb-ease);
}

html:root #resizeHandle:hover #toggleSidebarBtn,
html:root #left_col:hover + #resizeHandle #toggleSidebarBtn,
html:root #toggleSidebarBtn:hover,
html:root #toggleSidebarBtn:focus-visible,
html:root body.sidebar-collapsed #toggleSidebarBtn,
html:root body.left-col-collapsed #toggleSidebarBtn {
    opacity: 1;
}

/* ---- 4. Tab strip ----------------------------------------------------------- */
html:root #app-tab-bar {
    display: flex;
    align-items: center;
    gap: var(--fb-space-2);
    height: var(--fb-topbar-height);
    min-height: var(--fb-topbar-height);
    padding: 0 var(--fb-space-6) 0 var(--fb-space-7);
    border: 0;
    background: var(--fb-bg);
    box-sizing: border-box;
}

html:root #app-tab-bar .app-tab-strip {
    display: flex;
    align-items: center;
    gap: var(--fb-space-1);
    height: 100%;
    padding: 0;
    min-width: 0;
}

html:root #app-tab-bar .app-tab-scroll-btn:disabled {
    display: none;
}

html:root #app-tab-bar .app-tab,
html:root #app-tab-bar .app-tab.active {
    position: relative;
    top: 0;
    display: flex;
    align-items: center;
    gap: var(--fb-space-gap-row);
    height: var(--fb-row-height);
    min-width: 0;
    max-width: var(--fb-tab-max);
    margin: 0;
    padding: 0 var(--fb-space-4) 0 var(--fb-space-5);
    border: 0;
    border-radius: var(--fb-radius);
    background: transparent;
    box-shadow: none;
    color: var(--fb-muted);
    font-size: var(--fb-text-ui);
    font-weight: var(--fb-weight-regular);
}

html:root #app-tab-bar .app-tab::before,
html:root #app-tab-bar .app-tab::after {
    display: none;
}

html:root #app-tab-bar .app-tab:hover {
    background: var(--fb-hover);
    color: var(--fb-text-2);
}

html:root #app-tab-bar .app-tab.active,
html:root[data-theme='dark'] #app-tab-bar .app-tab.active {
    background: var(--fb-active);
    color: var(--fb-text);
}

html:root #app-tab-bar .app-tab .app-tab-title {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: inherit;
    font-weight: inherit;
}

html:root #app-tab-bar .fabbrain-tab-kind {
    --fabbrain-glyph: var(--fb-icon-note);
}

html:root #app-tab-bar .app-tab[data-fb-kind="canvas"] .fabbrain-tab-kind {
    --fabbrain-glyph: var(--fb-icon-canvas);
}

html:root #app-tab-bar .app-tab[data-fb-kind="kanban"] .fabbrain-tab-kind {
    --fabbrain-glyph: var(--fb-icon-grid);
}

html:root #app-tab-bar .app-tab-close {
    display: grid;
    place-items: center;
    flex: none;
    width: var(--fb-tab-close);
    height: var(--fb-tab-close);
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: var(--fb-radius-xs);
    background: transparent;
    color: var(--fb-faint);
    font-size: 0;
    opacity: 0;
}

/* The hit area: 28px around the 18px control, the glyph unchanged (fix wave) */
html:root #app-tab-bar .app-tab-close {
    position: relative;
}

html:root #app-tab-bar .app-tab-close::after {
    content: "";
    position: absolute;
    inset: calc((var(--fb-tab-close) - var(--fb-hit-min)) / 2);
}

html:root #app-tab-bar .app-tab-close::before {
    content: "";
    width: var(--fb-icon-xs);
    height: var(--fb-icon-xs);
    background-color: currentColor;
    -webkit-mask: var(--fb-icon-x) center / contain no-repeat;
    mask: var(--fb-icon-x) center / contain no-repeat;
}

html:root #app-tab-bar .app-tab:hover .app-tab-close,
html:root #app-tab-bar .app-tab.active .app-tab-close,
html:root #app-tab-bar .app-tab-close:focus-visible {
    opacity: 1;
}

html:root #app-tab-bar .app-tab-close:hover {
    background: var(--fb-hover);
    color: var(--fb-text);
}

html:root #app-tab-bar #fabbrainTabNova {
    display: grid;
    place-items: center;
    flex: none;
    width: var(--fb-row-height);
    height: var(--fb-row-height);
    padding: 0;
    border: 0;
    border-radius: var(--fb-radius);
    background: transparent;
    color: var(--fb-faint);
    cursor: pointer;
}

html:root #app-tab-bar #fabbrainTabNova:hover {
    background: var(--fb-hover);
    color: var(--fb-text);
}

/* "Close all" (upstream): kept at the right end, as a quiet text button */
html:root #app-tab-bar .app-tab-close-all {
    margin-left: auto;
    height: var(--fb-row-height);
    padding: 0 var(--fb-space-5);
    border: 0;
    border-radius: var(--fb-radius);
    background: transparent;
    color: var(--fb-faint);
    font-size: var(--fb-text-ui);
}

html:root #app-tab-bar .app-tab-close-all .lucide {
    width: var(--fb-icon-xs);
    height: var(--fb-icon-xs);
    color: inherit;
    background-color: currentColor;
    -webkit-mask-image: var(--fb-icon-x);
    mask-image: var(--fb-icon-x);
}

html:root #app-tab-bar .app-tab-close-all:hover {
    background: var(--fb-hover);
    color: var(--fb-text);
}

/* ---- 5. Narrow windows ------------------------------------------------------
   At 800px and below the app switches to its phone layout (index-mobile.css):
   the rail sits at the bottom or is hidden and the tree takes the screen. The
   look follows; the layout stays the app's. */
@media (max-width: 800px) {
    html:root #icon_sidebar .fabbrain-rail-gap,
    html:root #icon_sidebar .fabbrain-rail-spacer {
        display: none;
    }

    /* index-mobile.css pins the folder's count next to its name with
       !important; the row keeps the prototype's order: name, then the count
       at the right, only while the folder is closed */
    html:root #left_col .folder-name {
        flex: 1 1 auto !important;
    }

    html:root #left_col .folder-note-count {
        margin: 0 !important;
    }

    html:root #left_col .folder-header[data-fb-aberta] > .folder-toggle > .folder-note-count {
        display: none !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    html:root .fabbrain-pop:not([hidden]),
    html:root #create-menu.show {
        animation: none;
    }
}

/* ---- One quiet dot on a rail entry (fix wave) --------------------------------
   Upstream can put two dots on Settings: a red one at the top (.update-badge, a
   release is out, admins only) and an amber one at the bottom (.attention-badge,
   the account still uses a shipped default username or password). The rail
   shows ONE small dot at the top right: the danger colour for the security
   warning (it wins when both are there), the accent for a release. The warning
   itself is spelled out at the top of the Settings page. */
html:root #icon_sidebar .icon-sidebar-btn .update-badge,
html:root #icon_sidebar .icon-sidebar-btn .attention-badge {
    top: var(--fb-space-2);
    right: var(--fb-space-2);
    bottom: auto;
    width: var(--fb-udot);
    height: var(--fb-udot);
    border: 0;
    box-shadow: 0 0 0 var(--fb-hairline) var(--fb-rail);
}

html:root #icon_sidebar .icon-sidebar-btn .update-badge {
    background: var(--fb-accent);
}

html:root #icon_sidebar .icon-sidebar-btn .attention-badge {
    background: var(--fb-danger);
}

/* ---- Memória: the state dot on its rail entry (phase 4; js/fabbrain-memoria-comum.js) ------
   The prototype's .rdot: 8px at the top right, ringed in the rail colour. Red: a send failed;
   amber: paused or a note waits for confirmation; the accent otherwise; it pulses while notes are
   queued or being sent; grey and still when the memory could not be asked. No dot when all is
   in order. */
html:root #icon_sidebar #iconSidebarMemoriaBtn {
    position: relative;
}

html:root #icon_sidebar .fabbrain-memoria-dot {
    position: absolute;
    top: var(--fb-space-3);
    right: var(--fb-space-3);
    width: var(--fb-mem-dot);
    height: var(--fb-mem-dot);
    border-radius: var(--fb-radius-round);
    background: var(--fb-accent);
    color: var(--fb-accent);
    box-shadow: 0 0 0 var(--fb-space-1) var(--fb-rail);
    pointer-events: none;
}

html:root #icon_sidebar .fabbrain-memoria-dot[hidden] {
    display: none;
}

html:root #icon_sidebar .fabbrain-memoria-dot[data-tom='erro'] { background: var(--fb-danger); color: var(--fb-danger); }
html:root #icon_sidebar .fabbrain-memoria-dot[data-tom='aviso'] { background: var(--fb-warn-bar); color: var(--fb-warn-bar); }
html:root #icon_sidebar .fabbrain-memoria-dot[data-tom='neutro'] { background: var(--fb-faint); color: var(--fb-faint); }

html:root #icon_sidebar .fabbrain-memoria-dot.pulsa::after {
    content: "";
    position: absolute;
    inset: calc(-1 * var(--fb-space-2));
    border-radius: var(--fb-radius-round);
    border: var(--fb-mem-pulse-ring) solid currentColor;
    opacity: 0;
    animation: fabbrain-memoria-pulso var(--fb-dur-pulse) var(--fb-ease-out) infinite;
}

@keyframes fabbrain-memoria-pulso {
    0% { transform: scale(.5); opacity: .7; }
    100% { transform: scale(1.25); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    html:root #icon_sidebar .fabbrain-memoria-dot.pulsa::after {
        animation: none;
    }
}

html:root #icon_sidebar .icon-sidebar-btn:has(.attention-badge) .update-badge {
    display: none;
}


/* ---- FABBRAIN (fase 4b, Tarefa 3) -------------------------------------------- */

/* "Mais ferramentas" (js/fabbrain-submenu.js): the trigger is a row of its menu, the panel a menu of its own */
html:root .fabbrain-sub {
    position: relative;
}

html:root .fabbrain-sub-gatilho {
    display: flex;
    align-items: center;
    gap: var(--fb-space-gap-mi);
    width: 100%;
    margin: 0;
    padding: var(--fb-space-gap-row) var(--fb-space-5);
    border: 0;
    border-radius: var(--fb-radius);
    background: transparent;
    color: var(--fb-text);
    font: inherit;
    font-size: var(--fb-text-base);
    line-height: var(--fb-leading-base);
    text-align: left;
    cursor: pointer;
}

html:root .fabbrain-sub-gatilho:hover,
html:root .fabbrain-sub-gatilho:focus-visible,
html:root .fabbrain-sub.is-open > .fabbrain-sub-gatilho {
    background: var(--fb-hover);
    color: var(--fb-text);
}

html:root .fabbrain-sub-gatilho > .fabbrain-sub-icone {
    color: var(--fb-muted);
}

html:root .fabbrain-sub-gatilho > .fabbrain-sub-rotulo {
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;
}

html:root .fabbrain-sub-gatilho > .fabbrain-sub-chevron {
    margin-left: auto;
    color: var(--fb-faint);
}

html:root .fabbrain-sub-painel {
    position: fixed;
    z-index: 10002;
    min-width: var(--fb-pop-min);
    padding: var(--fb-space-3);
    border-radius: var(--fb-radius-lg);
    background: var(--fb-surface-raised);
    box-shadow: var(--fb-shadow);
    color: var(--fb-text);
    font-size: var(--fb-text-base);
}

html:root .fabbrain-sub-painel[hidden] {
    display: none;
}

html:root .fabbrain-sub-painel > .folder-actions-menu-item,
html:root .fabbrain-sub-painel > .note-actions-menu-item,
html:root .fabbrain-sub-painel > .dropdown-item {
    width: 100%;
    white-space: nowrap;
}

/* The tree's folder and note menus in the prototype's .pop/.mi (the same rows as the note's "…" menu) */
html:root #folder-actions-menu,
html:root #note-actions-menu {
    min-width: var(--fb-pop-min);
    font-size: var(--fb-text-base);
}

html:root #folder-actions-menu .folder-actions-menu-item,
html:root #note-actions-menu .note-actions-menu-item {
    display: flex;
    align-items: center;
    gap: var(--fb-space-gap-mi);
    padding: var(--fb-space-gap-row) var(--fb-space-5);
    border-radius: var(--fb-radius);
    font-size: var(--fb-text-base);
    line-height: var(--fb-leading-base);
    white-space: nowrap;
}

html:root #folder-actions-menu .folder-actions-menu-item > i,
html:root #note-actions-menu .note-actions-menu-item > i {
    flex: none;
    width: var(--fb-icon);
    height: var(--fb-icon);
    font-size: var(--fb-icon);
    color: var(--fb-muted);
}

html:root #folder-actions-menu .folder-actions-menu-item.danger > i,
html:root #note-actions-menu .note-actions-menu-item.danger > i {
    color: var(--fb-danger);
}

html:root #folder-actions-menu .actions-menu-shortcut,
html:root #note-actions-menu .actions-menu-shortcut {
    margin-left: auto;
    padding-left: var(--fb-space-5);
    font-size: var(--fb-text-xs);
    color: var(--fb-faint);
}

/* A folder row shows its count or its "…", never both (spec section 6, defect 4): hovering or focusing the row, or
   its menu being open, swaps the count for the toggle */
html:root #left_col .folder-toggle:hover > .folder-note-count,
html:root #left_col .folder-toggle:focus-visible > .folder-note-count,
html:root #left_col .folder-toggle:has(:focus-visible) > .folder-note-count,
html:root #left_col .folder-toggle:has(.folder-actions-toggle.open) > .folder-note-count {
    display: none;
}

/* The "…" of a folder row only on hover, keyboard focus or while its menu is open, as the prototype's .row .more
   (the rule above this file's tree section showed it always: defect 4) */
html:root #left_col .folder-toggle .folder-actions-toggle {
    display: none;
}

html:root #left_col .folder-toggle:hover .folder-actions-toggle,
html:root #left_col .folder-toggle:focus-visible .folder-actions-toggle,
html:root #left_col .folder-toggle:has(:focus-visible) .folder-actions-toggle,
html:root #left_col .folder-toggle .folder-actions-toggle.open {
    display: inline-grid;
}

@media (hover: none), (max-width: 800px) {
    /* no hover there: the toggle stays, so the count goes */
    html:root #left_col .folder-toggle .folder-actions-toggle {
        display: inline-grid;
    }

    html:root #left_col .folder-toggle > .folder-note-count {
        display: none;
    }
}

/* The provisional tab (js/tabs.js, spec section 4): its title in italic */
html:root #app-tab-bar .app-tab.is-preview .app-tab-title {
    font-style: italic;
}

/* ---- FABBRAIN (fase 4b, Tarefa 4): folder icons, area dots, menu rows ---------------------------------------- */

/* The folder icon in its colour, in the prototype's .fic: a small box (notes_list.php wraps the icon, a mask, in
   .fabbrain-fic, painted in the same colour) tinted with that colour. Every folder shows it, the default glyph too;
   the chevron stays before it, as in the prototype's .row */
html:root #left_col .folder-toggle > .fabbrain-fic {
    display: inline-grid;
    place-items: center;
    flex: none;
    width: var(--fb-fic);
    height: var(--fb-fic);
    border-radius: var(--fb-radius-xs);
    background: color-mix(in srgb, currentColor var(--fb-area-tint), transparent);
    color: var(--fb-muted);
    cursor: pointer;
}

html:root #left_col .folder-toggle > .fabbrain-fic > .folder-icon,
html:root #left_col .folder-toggle > .fabbrain-fic > .folder-icon[data-custom-icon="false"] {
    display: block;
    width: var(--fb-fic-glyph);
    height: var(--fb-fic-glyph);
    margin: 0;
    font-size: var(--fb-fic-glyph) !important;
    color: inherit;
}

/* The name takes its own width; what is left goes after the area dot (or after the name), so the count and "…" stay
   at the end of the row */
html:root #left_col .folder-toggle > .folder-name {
    flex: 0 1 auto;
    margin-right: auto;
}

html:root #left_col .folder-toggle > .folder-name:has(+ .fabbrain-area-ponto) {
    margin-right: 0;
}

/* FABBRAIN (fase 4d): a folder with its own memory bank: the brain (--fb-icon-brain) in the bank's colour, 14 px, after
   the name (it was a 7 px dot); it stays on hover, the count gives way to the "…" as before */
html:root #left_col .folder-toggle > .fabbrain-area-ponto {
    flex: none;
    width: var(--fb-tree-signal);
    height: var(--fb-tree-signal);
    margin: 0 auto 0 var(--fb-space-1);
    border-radius: 0;
    -webkit-mask: var(--fb-icon-brain) center / contain no-repeat;
    mask: var(--fb-icon-brain) center / contain no-repeat;
}

html:root .fabbrain-area-ponto { background: var(--fb-area-cinza); }
html:root .fabbrain-area-ponto[data-cor="azul"] { background: var(--fb-area-azul); }
html:root .fabbrain-area-ponto[data-cor="verde"] { background: var(--fb-area-verde); }
html:root .fabbrain-area-ponto[data-cor="roxo"] { background: var(--fb-area-roxo); }
html:root .fabbrain-area-ponto[data-cor="ambar"] { background: var(--fb-area-ambar); }
html:root .fabbrain-area-ponto[data-cor="vermelho"] { background: var(--fb-area-vermelho); }
html:root .fabbrain-area-ponto[data-cor="cinza"] { background: var(--fb-area-cinza); }

/* Menu rows as the prototype's .pop/.mi (review of Task 3): 32 px rows, 13.5 px text, 16 px glyphs in the faint
   colour; the same in the tree's folder and note menus, the note's "…" menu, its "Mais ferramentas" and the "+" menu */
html:root #folder-actions-menu,
html:root #note-actions-menu,
html:root #right_col .note-edit-toolbar[data-fabbrain-acoes] .mobile-toolbar-menu,
html:root .fabbrain-sub-painel,
html:root #create-menu {
    padding: var(--fb-pop-pad);
    font-size: var(--fb-text-row);
}

html:root #folder-actions-menu .folder-actions-menu-item,
html:root #note-actions-menu .note-actions-menu-item,
html:root #right_col .note-edit-toolbar[data-fabbrain-acoes] .mobile-toolbar-menu .dropdown-item,
html:root .fabbrain-sub-painel > .dropdown-item,
html:root .fabbrain-sub-gatilho {
    box-sizing: border-box;
    height: var(--fb-mi-height);
    min-height: var(--fb-mi-height);
    padding: 0 var(--fb-space-5);
    gap: var(--fb-space-gap-mi);
    font-size: var(--fb-text-row);
    line-height: var(--fb-mi-height);
    color: var(--fb-text-2);
}

html:root #folder-actions-menu .folder-actions-menu-item > i,
html:root #note-actions-menu .note-actions-menu-item > i,
html:root #right_col .note-edit-toolbar[data-fabbrain-acoes] .mobile-toolbar-menu .dropdown-item > i,
html:root .fabbrain-sub-painel > .dropdown-item > i,
html:root .fabbrain-sub-gatilho > .fabbrain-sub-icone,
html:root #create-menu .create-menu-item > .lucide {
    flex: none;
    width: var(--fb-mi-icon);
    height: var(--fb-mi-icon);
    font-size: var(--fb-mi-icon) !important;
    line-height: 1;
    color: var(--fb-faint);
}

html:root #folder-actions-menu .folder-actions-menu-item.danger,
html:root #note-actions-menu .note-actions-menu-item.danger,
html:root #folder-actions-menu .folder-actions-menu-item.danger > i,
html:root #note-actions-menu .note-actions-menu-item.danger > i,
html:root #right_col .note-edit-toolbar[data-fabbrain-acoes] .mobile-toolbar-menu .fabbrain-nota-perigo,
html:root #right_col .note-edit-toolbar[data-fabbrain-acoes] .mobile-toolbar-menu .fabbrain-nota-perigo > i {
    color: var(--fb-danger);
}

/* "Mais ferramentas": the panel is as wide as its widest row, and a row keeps its shortcut (⌘C, ⌘X) inside, at the
   right (it overflowed the panel's edge) */
html:root .fabbrain-sub-painel {
    width: max-content;
    max-width: calc(100vw - var(--fb-space-8));
    box-sizing: border-box;
}

html:root .fabbrain-sub-painel > .folder-actions-menu-item,
html:root .fabbrain-sub-painel > .note-actions-menu-item,
html:root .fabbrain-sub-painel > .dropdown-item {
    display: flex;
    box-sizing: border-box;
    width: 100%;
}

html:root .fabbrain-sub-painel .actions-menu-shortcut {
    flex: none;
    margin-left: auto;
    padding-left: var(--fb-space-6);
}

/* The "+" menu: the prototype's .mi.two (46 px, the title and its line under it) */
html:root #create-menu .create-menu-item {
    min-height: var(--fb-mi-two-height);
    padding: 0 var(--fb-space-5);
    font-size: var(--fb-text-row);
    color: var(--fb-text-2);
}

/* The tab strip in a narrow window (review of Task 3: at 820 px a second tab showed half drawn, its icon cut, next to
   the scroll arrow). The tabs give up room first, down to --fb-tab-min, their titles ending in "…"; past that the
   strip scrolls and its clipped edge fades out, so no tab is ever drawn cut */
html:root #app-tab-bar .app-tab,
html:root #app-tab-bar .app-tab.active {
    flex: 0 1 var(--fb-tab-max);
    min-width: var(--fb-tab-min);
}

html:root #app-tab-bar.has-overflow .app-tab-strip {
    --fabbrain-fade-l: var(--fb-tab-fade);
    --fabbrain-fade-r: var(--fb-tab-fade);
    -webkit-mask-image: linear-gradient(to right, transparent 0, var(--fb-mask-on) var(--fabbrain-fade-l), var(--fb-mask-on) calc(100% - var(--fabbrain-fade-r)), transparent 100%);
    mask-image: linear-gradient(to right, transparent 0, var(--fb-mask-on) var(--fabbrain-fade-l), var(--fb-mask-on) calc(100% - var(--fabbrain-fade-r)), transparent 100%);
}

/* at an end, that side is not clipped: no fade there */
html:root #app-tab-bar.has-overflow:has(.app-tab-scroll-prev:disabled) .app-tab-strip {
    --fabbrain-fade-l: 0%;
}

html:root #app-tab-bar.has-overflow:has(.app-tab-scroll-next:disabled) .app-tab-strip {
    --fabbrain-fade-r: 0%;
}

/* ---- FABBRAIN (fase 4b, Tarefa 5): focus mode (js/fabbrain-foco.js; prototype's .focus-h and .app.foco) ----
   The icon rail stays; the notes column, the tab bar, the canvas strip and the memory panel go; a thin header with
   the note's glyph, its title and "Sair do foco" (a muted "Esc") sits on top of the main area. */
html:root.fabbrain-foco :is(#left_col, #resizeHandle, #iconSidebarToggle, #app-tab-bar, #fabbrainMemoriaPainel, .pz-edge-stack),
html:root.fabbrain-foco #right_col .fabbrain-canvas-faixa,
html:root.fabbrain-foco #right_col .notecard .note-edit-toolbar {
    display: none !important; /* the tree, the tab bar and the panel set their own display (and size) with !important */
}

html:root .fabbrain-foco-cabecalho {
    display: none;
}

html:root.fabbrain-foco .fabbrain-foco-cabecalho {
    display: flex;
    flex: none;
    align-items: center;
    gap: var(--fb-space-gap-mi);
    box-sizing: border-box;
    height: var(--fb-foco-head);
    padding: 0 var(--fb-space-7);
    border-bottom: var(--fb-hairline) solid var(--fb-line);
    background: var(--fb-bg);
    color: var(--fb-text);
    font-size: var(--fb-text-ui);
    font-weight: var(--fb-weight-semibold);
}

html:root .fabbrain-foco-cabecalho .fabbrain-foco-ico {
    flex: none;
    width: var(--fb-icon-sm);
    height: var(--fb-icon-sm);
    color: var(--fb-faint);
}

html:root .fabbrain-foco-cabecalho .fabbrain-foco-titulo {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* .btn, at the right end */
html:root .fabbrain-foco-cabecalho .fabbrain-foco-sair {
    display: inline-flex;
    flex: none;
    align-items: center;
    gap: var(--fb-space-3);
    height: var(--fb-row-height);
    margin: 0 0 0 auto;
    padding: 0 var(--fb-space-gap-mi);
    border: 0;
    border-radius: var(--fb-radius-row);
    background: transparent;
    box-shadow: inset 0 0 0 var(--fb-hairline) var(--fb-line-2);
    color: var(--fb-text-2);
    font: inherit;
    font-size: var(--fb-text-ui);
    font-weight: var(--fb-weight-medium);
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
}

html:root .fabbrain-foco-cabecalho .fabbrain-foco-sair:hover {
    background: var(--fb-hover);
    color: var(--fb-text);
}

html:root .fabbrain-foco-cabecalho .fabbrain-foco-sair:focus-visible {
    outline: var(--fb-focus-ring) solid var(--fb-accent);
    outline-offset: var(--fb-hairline);
}

html:root .fabbrain-foco-cabecalho .fabbrain-foco-esc {
    color: var(--fb-faint);
    font-weight: var(--fb-weight-regular);
}
