/*
 * FABBRAIN: the base of the FabBrain look (phase 2, Task 1).
 *
 * Loaded after every other stylesheet of a page (index_css.php group
 * "fabbrain", and the end of every page of css_assets.php), on top of the
 * app's own light/dark mechanism. It does four things, in this order:
 *
 *   1. (the Geist faces are fabbrain-fontes.css, linked just before it);
 *   2. points the app's vocabulary (--pz-*, css/tokens.css) at the FabBrain
 *      tokens (--fb-*, fabbrain-tokens.css), so every screen, including the
 *      ones the prototype does not draw, takes the new palette for free;
 *   3. sets the base typography, the surfaces of the shell and removes the
 *      structural borders the prototype does without;
 *   4. focus, selection and scrollbars.
 *
 * Every value is a token. Regions (rail, tree, tabs, note header, canvas,
 * remaining screens) get their own files in later tasks.
 */

/* ---- 1. Geist ---------------------------------------------------------------
   The faces live in fabbrain-fontes.css, linked before this file on every page. */

/* ---- 2. The app's tokens, from ours -----------------------------------------
   One block for both modes: the --fb-* values switch with data-theme, so the
   bridge itself does not have to. The selector carries an id inside :not() on
   purpose: (1,0,1) outranks every block that sets these names, the theme
   variants of css/tokens.css (html.theme-sepia, html.theme-black[data-theme])
   and the workspace colour (lib/workspace-accent.php), so the owner sees ONE
   look whatever theme or workspace colour a profile carries, and no
   !important is needed. Nothing in the app has that id. */
html:not(#fabbrain-tema) {
    /* surfaces */
    --pz-bg: var(--fb-bg);
    --pz-surface: var(--fb-side);
    --pz-surface-hover: var(--fb-hover);
    --pz-surface-sunken: var(--fb-active);
    --pz-surface-strong: var(--fb-active);
    --pz-surface-strong-hover: var(--fb-dot);
    --pz-chrome-bg: var(--fb-side);
    --pz-sidebar-bg: var(--fb-side);
    --pz-sidebar-surface: var(--fb-fill);
    --pz-code-bg: var(--fb-fill);
    --pz-active-bg: var(--fb-active);
    --pz-tabbar-bg: var(--fb-bg);
    --pz-tab-bg: transparent;
    --pz-tab-hover-bg: var(--fb-hover);
    --pz-tab-active-bg: var(--fb-active);
    --pz-disabled: var(--fb-active);

    /* text */
    --pz-text: var(--fb-text);
    --pz-text-strong: var(--fb-text);
    --pz-text-secondary: var(--fb-text-2);
    --pz-text-muted: var(--fb-muted);
    --pz-text-subtle: var(--fb-faint);
    --pz-text-inverse: var(--fb-on-accent);
    --pz-icon: var(--fb-muted);
    --pz-icon-hover: var(--fb-text);
    --pz-tooltip-bg: var(--fb-text);
    --pz-tooltip-text: var(--fb-bg);

    /* lines: few, and all of them the same faint hairline */
    --pz-border-light: var(--fb-line);
    --pz-border: var(--fb-line);
    --pz-border-strong: var(--fb-dot);
    --pz-scrollbar: var(--fb-dot);
    --pz-scrollbar-hover: var(--fb-faint);

    /* the one accent */
    --pz-accent: var(--fb-accent);
    --pz-accent-hover: var(--fb-accent-text);
    --pz-accent-rgb: var(--fb-accent-rgb);
    --pz-accent-strong: var(--fb-accent-text);
    --pz-accent-soft: var(--fb-accent-soft);
    --pz-accent-text: var(--fb-accent-text);
    --pz-accent-text-hover: var(--fb-accent);
    --pz-accent-text-rgb: var(--fb-accent-rgb);
    --pz-link: var(--fb-accent-text);
    --pz-selection: var(--fb-selection);

    /* "Não confirmado" amber, and the prototype's destructive red */
    --pz-warning: var(--fb-warn-bar);
    --pz-warning-hover: var(--fb-warn);
    --pz-warning-soft: var(--fb-warn-soft);
    --pz-warning-strong: var(--fb-warn);
    --pz-warning-text: var(--fb-warn);
    --pz-warning-text-hover: var(--fb-warn);
    --pz-danger: var(--fb-danger);
    --pz-danger-text: var(--fb-danger);

    /* shape and weight */
    --pz-radius-sm: var(--fb-radius-sm);
    --pz-radius: var(--fb-radius);
    --pz-radius-lg: var(--fb-radius-md);
    --pz-radius-xl: var(--fb-radius-lg);
    --pz-radius-2xl: var(--fb-radius-group);
    --pz-weight-light: var(--fb-weight-regular);
    --pz-weight-normal: var(--fb-weight-regular);
    --pz-weight-medium: var(--fb-weight-medium);
    --pz-weight-semibold: var(--fb-weight-semibold);
    --pz-weight-bold: var(--fb-weight-semibold);

    background-color: var(--fb-bg);
}

/* ---- 3. Typography and surfaces ------------------------------------------- */
html,
body {
    font-family: var(--fb-font-sans);
    color: var(--fb-text);
    background-color: var(--fb-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

code,
kbd,
pre,
samp {
    font-family: var(--fb-font-mono);
}

/* The shell: rail, tree column, main area. Hierarchy by ground, not by lines.
   Region rules start with html:root (0,1,1): that ties with the dark layer's
   html[data-theme='dark'] prefix and wins by order, so one rule serves both
   themes without !important. */
html:root #icon_sidebar {
    background: var(--fb-rail);
    border-right: 0;
}

html:root #left_col,
html:root #left_col .mini-calendar-container {
    background: var(--fb-side);
}

html:root #left_col .mini-calendar-container {
    border-top: 0;
}

html:root #right_pane,
html:root #right_col,
html:root #app-tab-bar,
html:root .notecard,
html:root .note-header,
html:root .note-edit-toolbar,
html:root .note-header-spacer {
    background-color: var(--fb-bg);
}

html:root #app-tab-bar {
    border-bottom: 0;
}

/* The note: title and body in the prototype's type */
html:root .css-title {
    font-family: 'Poznote Title Emoji', var(--fb-font-sans);
    font-weight: var(--fb-weight-semibold);
    letter-spacing: var(--fb-tracking-title);
    color: var(--fb-text);
    background: transparent;
}

/* The title size of a text note. --note-title-size is the per-note size (the
   title's right-click menu); only the default changes. A canvas's title is
   drawn on its floating strip (fabbrain-ui-canvas.css). */
html:root .notecard:not(:has(.fabbrain-canvas-entry)) .css-title {
    font-size: var(--note-title-size, var(--fb-text-title));
    line-height: var(--fb-leading-title);
}

html:root .noteentry {
    font-family: var(--fb-font-sans);
    color: var(--fb-text);
    line-height: var(--fb-leading-body);
}

html:root .noteentry h1,
html:root .noteentry h2,
html:root .noteentry h3,
html:root .noteentry h4,
html:root .noteentry h5,
html:root .noteentry h6 {
    font-weight: var(--fb-weight-semibold);
    letter-spacing: var(--fb-tracking-h2);
    line-height: var(--fb-leading-heading);
    color: var(--fb-text);
}

html:root .noteentry li::marker {
    color: var(--fb-faint);
}

html:root .noteentry blockquote {
    border-left-color: var(--fb-text);
    color: var(--fb-text);
}

html:root .noteentry th {
    font-weight: var(--fb-weight-medium);
    color: var(--fb-muted);
}

html:root .noteentry td,
html:root .noteentry th {
    border-color: var(--fb-line);
}

/* The tree: folders in medium and full text, items in regular, a step lighter */
html:root #left_col .folder-name {
    font-weight: var(--fb-weight-medium);
    color: var(--fb-text);
}

html:root #left_col .note-title {
    font-weight: var(--fb-weight-regular);
    color: var(--fb-text-2);
}

/* The open item reads in full text, not in the accent nor bolder (.row.active).
   !important: dark-mode/layout.css paints it in the accent with !important. */
html:root #left_col .links_arbo_left.selected-note .note-title {
    font-weight: var(--fb-weight-regular);
    color: var(--fb-text) !important;
}

/* Fields: a quiet fill instead of a box */
html:root #unified-search {
    background: var(--fb-fill);
    border-color: transparent;
    color: var(--fb-text);
}

html:root #unified-search::placeholder {
    color: var(--fb-muted);
}

/* The floating buttons at the right edge: raised surface, no outline */
html:root .pz-edge-btn {
    background: var(--fb-surface-raised);
    border-color: transparent;
    box-shadow: var(--fb-shadow);
    color: var(--fb-muted);
}

/* ---- 4. Focus, selection, scrollbars ------------------------------------- */
:focus-visible {
    outline: var(--fb-focus-ring) solid var(--fb-accent);
    outline-offset: var(--fb-space-1);
}

/* Selection: components/selection.css reads --pz-selection, bridged above to
   --fb-selection, so there is no rule of our own. */

html {
    scrollbar-color: var(--fb-dot) transparent;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition-duration: 0s !important;
        animation-duration: 0s !important;
    }
}
