/*
 * Theme tokens. Loaded after Water.css and overrides its variables.
 *
 * <html data-theme="light|dark|classic"> is set server-side from the
 * profile/cookie. Without the attribute ("auto"), the OS preference
 * picks Light or Dark.
 *
 * App tokens (beyond Water.css's own):
 *   --accent / --accent-hover  action icons, "+", drag indicators
 *   --danger                   errors, unreachable warning
 *   --bm-link / --folder-link  bookmark names / folder tree links
 *   --active-bg / --active-fg  selected folder
 *   --row-hover                bookmark row hover background
 *   --icon-rest                action icon opacity when row isn't hovered
 *   --btn-fg                   button text
 *   --success-* / --warning-*  flash messages
 *   --toast-*                  no-reload action toast
 *   --page / --card / --side   page background, content card, folder side of the card
 *   --header-*                 ink header bar
 *
 * Classic keeps its flat single-background layout: the surface rules below
 * are scoped to :root:not([data-theme="classic"]).
 */

/* ---------- Light (default) ---------- */
:root {
    color-scheme: light;
    --background-body: #ffffff;
    --background: #f1f5f5;
    --background-alt: #f5f8f8;
    --selection: #b7e6de;
    --text-main: #33403f;
    --text-bright: #0f1a1b;
    --text-muted: #667677;
    --links: #0f8a7a;
    --focus: #0f8a7a66;
    --border: #dde5e5;
    --code: #0b6b5f;
    --button-base: #0f2a2c;
    --button-hover: #1c4a4c;
    --scrollbar-thumb: #c3cfcf;
    --scrollbar-thumb-hover: #9fb0b0;
    --form-placeholder: #8a9899;
    --form-text: #142021;
    --variable: #0b6b5f;
    --highlight: #0b6b5f;
    --select-arrow: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' height='62.5' width='116.9' fill='%23475758'%3E%3Cpath d='M115.3,1.6 C113.7,0 111.1,0 109.5,1.6 L58.5,52.7 L7.4,1.6 C5.8,0 3.2,0 1.6,1.6 C0,3.2 0,5.8 1.6,7.4 L55.5,61.3 C56.3,62.1 57.3,62.5 58.4,62.5 C59.4,62.5 60.5,62.1 61.3,61.3 L115.2,7.4 C116.9,5.8 116.9,3.2 115.3,1.6Z'/%3E%3C/svg%3E");

    --accent: #0f8a7a;
    --accent-hover: #0b6b5f;
    --danger: #c9302c;
    --bm-link: #142021;
    --folder-link: #475758;
    --active-bg: #e2f4f1;
    --active-fg: #0b6b5f;
    --row-hover: #f1f5f5;
    --icon-rest: 0.55;
    --btn-fg: #ffffff;
    --success-bg: #e2f4f1;
    --success-fg: #0b5249;
    --warning-bg: #fdf1d8;
    --warning-fg: #6b4400;
    --toast-bg: #0f2a2c;
    --toast-fg: #e3eded;
    --page: #edf2f2;
    --card: #ffffff;
    --card-shadow: 0 1px 2px rgba(15, 42, 44, 0.06), 0 8px 24px rgba(15, 42, 44, 0.06);
    --side: #eef4f3;
    --header-bg: #0f2a2c;
    --header-fg: #e6f2f1;
    --header-accent: #5fdcc9;
}

/* ---------- Dark (Ink + teal) ---------- */
/* Duplicated: once for "auto" on a dark OS, once for an explicit choice. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        color-scheme: dark;
        --background-body: #0f1415;
        --background: #162021;
        --background-alt: #131a1b;
        --selection: #1f5f57;
        --text-main: #c6d1d2;
        --text-bright: #eef5f5;
        --text-muted: #7b8c8e;
        --links: #3fc8b4;
        --focus: #3fc8b499;
        --border: #223032;
        --code: #5fdcc9;
        --button-base: #3fc8b4;
        --button-hover: #5fdcc9;
        --scrollbar-thumb: #2a3a3c;
        --scrollbar-thumb-hover: #3a4e50;
        --form-placeholder: #6a7b7d;
        --form-text: #e3eded;
        --variable: #5fdcc9;
        --highlight: #5fdcc9;
        --select-arrow: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' height='62.5' width='116.9' fill='%23a6b6b7'%3E%3Cpath d='M115.3,1.6 C113.7,0 111.1,0 109.5,1.6 L58.5,52.7 L7.4,1.6 C5.8,0 3.2,0 1.6,1.6 C0,3.2 0,5.8 1.6,7.4 L55.5,61.3 C56.3,62.1 57.3,62.5 58.4,62.5 C59.4,62.5 60.5,62.1 61.3,61.3 L115.2,7.4 C116.9,5.8 116.9,3.2 115.3,1.6Z'/%3E%3C/svg%3E");

        --accent: #3fc8b4;
        --accent-hover: #6fe3d1;
        --danger: #f2777a;
        --bm-link: #e3eded;
        --folder-link: #a6b6b7;
        --active-bg: #3fc8b424;
        --active-fg: #5fdcc9;
        --row-hover: #172022;
        --icon-rest: 0.55;
        --btn-fg: #062420;
        --success-bg: #163a35;
        --success-fg: #bdf0e6;
        --warning-bg: #3a2f17;
        --warning-fg: #f3dba6;
        --toast-bg: #1c2729;
        --toast-fg: #e3eded;
        --page: #0a0e0f;
        --card: #121819;
        --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.35);
        --side: #0e1415;
        --header-bg: #0d2426;
        --header-fg: #e3eded;
        --header-accent: #5fdcc9;
    }
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --background-body: #0f1415;
    --background: #162021;
    --background-alt: #131a1b;
    --selection: #1f5f57;
    --text-main: #c6d1d2;
    --text-bright: #eef5f5;
    --text-muted: #7b8c8e;
    --links: #3fc8b4;
    --focus: #3fc8b499;
    --border: #223032;
    --code: #5fdcc9;
    --button-base: #3fc8b4;
    --button-hover: #5fdcc9;
    --scrollbar-thumb: #2a3a3c;
    --scrollbar-thumb-hover: #3a4e50;
    --form-placeholder: #6a7b7d;
    --form-text: #e3eded;
    --variable: #5fdcc9;
    --highlight: #5fdcc9;
    --select-arrow: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' height='62.5' width='116.9' fill='%23a6b6b7'%3E%3Cpath d='M115.3,1.6 C113.7,0 111.1,0 109.5,1.6 L58.5,52.7 L7.4,1.6 C5.8,0 3.2,0 1.6,1.6 C0,3.2 0,5.8 1.6,7.4 L55.5,61.3 C56.3,62.1 57.3,62.5 58.4,62.5 C59.4,62.5 60.5,62.1 61.3,61.3 L115.2,7.4 C116.9,5.8 116.9,3.2 115.3,1.6Z'/%3E%3C/svg%3E");

    --accent: #3fc8b4;
    --accent-hover: #6fe3d1;
    --danger: #f2777a;
    --bm-link: #e3eded;
    --folder-link: #a6b6b7;
    --active-bg: #3fc8b424;
    --active-fg: #5fdcc9;
    --row-hover: #172022;
    --icon-rest: 0.55;
    --btn-fg: #062420;
    --success-bg: #163a35;
    --success-fg: #bdf0e6;
    --warning-bg: #3a2f17;
    --warning-fg: #f3dba6;
    --toast-bg: #1c2729;
    --toast-fg: #e3eded;
    --page: #0a0e0f;
    --card: #121819;
    --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.35);
    --side: #0e1415;
    --header-bg: #0d2426;
    --header-fg: #e3eded;
    --header-accent: #5fdcc9;
}

/* ---------- Classic (Water.css dark + orange, as before) ---------- */
:root[data-theme="classic"] {
    color-scheme: dark;
    --background-body: #202b38;
    --background: #161f27;
    --background-alt: #1a242f;
    --selection: #1c76c5;
    --text-main: #dbdbdb;
    --text-bright: #fff;
    --text-muted: #a9b1ba;
    --links: #41adff;
    --focus: #0096bfab;
    --border: #526980;
    --code: #ffbe85;
    --button-base: #0c151c;
    --button-hover: #040a0f;
    --scrollbar-thumb: #040a0f;
    --scrollbar-thumb-hover: #000;
    --form-placeholder: #a9a9a9;
    --form-text: #fff;
    --variable: #d941e2;
    --highlight: #c9b458;
    --select-arrow: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' height='62.5' width='116.9' fill='%23efefef'%3E%3Cpath d='M115.3,1.6 C113.7,0 111.1,0 109.5,1.6 L58.5,52.7 L7.4,1.6 C5.8,0 3.2,0 1.6,1.6 C0,3.2 0,5.8 1.6,7.4 L55.5,61.3 C56.3,62.1 57.3,62.5 58.4,62.5 C59.4,62.5 60.5,62.1 61.3,61.3 L115.2,7.4 C116.9,5.8 116.9,3.2 115.3,1.6Z'/%3E%3C/svg%3E");

    --accent: #e8923e;
    --accent-hover: #f0b06a;
    --danger: #ee5555;
    --bm-link: #41adff;
    --folder-link: #41adff;
    --active-bg: transparent;
    --active-fg: #41adff;
    --row-hover: transparent;
    --icon-rest: 1;
    --btn-fg: #fff;
    --success-bg: #2e7d32;
    --success-fg: #dbdbdb;
    --warning-bg: #b8860b;
    --warning-fg: #dbdbdb;
    --toast-bg: #2e7d32;
    --toast-fg: #fff;
}

/* ---------- Shared rules driven by the tokens ---------- */
button, input[type="submit"], input[type="button"], input[type="reset"] { color: var(--btn-fg); }
.bookmark-item > a { color: var(--bm-link); }
.folder-tree a, .sidebar > a { color: var(--folder-link); }
.folder-tree a:hover, .sidebar > a:hover { color: var(--text-bright); }
.folder-tree .active > a { background: var(--active-bg); color: var(--active-fg); border-radius: 4px; box-shadow: 0 0 0 0.2em var(--active-bg); }
.favicon-fallback, .favicon-fallback-lg { color: var(--text-muted); }

/* Single-color line icons from _icons.html */
.icon { width: 1em; height: 1em; display: inline-block; vertical-align: -0.125em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Surfaces: ink header bar, tinted page, content card (not Classic) ---------- */
:root:not([data-theme="classic"]) { overflow-x: clip; }
:root:not([data-theme="classic"]) body { background: var(--page); }

/* Full-width bar behind the header; reaches up over body's top margin */
:root:not([data-theme="classic"]) header { position: relative; color: var(--header-fg); padding-bottom: 0.9em; }
:root:not([data-theme="classic"]) header::before { content: ""; position: absolute; inset: -20px -100vmax 0; background: var(--header-bg); z-index: -1; }
:root:not([data-theme="classic"]) header h1 { color: #ffffff; }
:root:not([data-theme="classic"]) header nav > a,
:root:not([data-theme="classic"]) header nav > .nav-logout button,
:root:not([data-theme="classic"]) header .user-menu-toggle,
:root:not([data-theme="classic"]) header h1 .edit-icon { color: var(--header-accent); }
:root:not([data-theme="classic"]) header .search-toggle,
:root:not([data-theme="classic"]) header .theme-toggle,
:root:not([data-theme="classic"]) header .burger-btn { color: var(--header-fg); }
:root:not([data-theme="classic"]) header .search-toggle:hover,
:root:not([data-theme="classic"]) header .theme-toggle:hover { color: var(--header-accent); }

:root:not([data-theme="classic"]) main { background: var(--card); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--card-shadow); padding: 0.6em 1.6em 1.2em; margin-top: 1.4em; }

/* Bookmark list / shared page: folder side shaded, bookmark side on the card */
@media (min-width: 769px) {
    :root:not([data-theme="classic"]) main:has(> .two-col) { padding: 0; }
    :root:not([data-theme="classic"]) main:has(> .two-col) > .search-bar { margin: 1em 1.6em 0.3em; }
    :root:not([data-theme="classic"]) main:has(> .two-col) > .search-results { margin: 0 1.6em 1em; }
    :root:not([data-theme="classic"]) main > .two-col { gap: 0; }
    :root:not([data-theme="classic"]) main > .two-col .sidebar { background: var(--side); border-right: 1px solid var(--border); border-radius: 12px 0 0 12px; padding: 0.6em 1.4em 1.2em; }
    :root:not([data-theme="classic"]) main > .two-col .main { padding: 0.6em 1.6em 1.2em; min-width: 0; }
}
@media (max-width: 768px) {
    :root:not([data-theme="classic"]) main { padding: 0.6em 1em 1em; }
}
