/* ---------- Reset & variables ---------- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --sidebar-w: 220px;
    --font: system-ui, -apple-system, sans-serif;
    --mono: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;
}

/* Deep Ocean (default dark) */
[data-theme="ocean"] {
    --bg: #1a1a2e;
    --bg-surface: #16213e;
    --bg-hover: #1f2b47;
    --text: #e0e0e0;
    --text-muted: #8892a4;
    --accent: #4fc3f7;
    --accent-dim: #2a6f97;
    --tag-bg: #253350;
    --tag-text: #81d4fa;
    --border: #2a3550;
    --code-bg: #0f1729;
}

/* Forest — muted greens */
[data-theme="forest"] {
    --bg: #1a2318;
    --bg-surface: #212d1e;
    --bg-hover: #2a3926;
    --text: #d4ddd0;
    --text-muted: #8a9b84;
    --accent: #8bc48a;
    --accent-dim: #4a7a49;
    --tag-bg: #2a3d28;
    --tag-text: #a3d4a2;
    --border: #334630;
    --code-bg: #141c12;
}

/* Dusk — warm purple-grey */
[data-theme="dusk"] {
    --bg: #1e1a24;
    --bg-surface: #262030;
    --bg-hover: #312a3c;
    --text: #ddd6e4;
    --text-muted: #9990a8;
    --accent: #c4a7e7;
    --accent-dim: #7c5dac;
    --tag-bg: #352d42;
    --tag-text: #d4bff0;
    --border: #3a3248;
    --code-bg: #16121c;
}

/* Sand — warm light theme */
[data-theme="sand"] {
    --bg: #f5f0e8;
    --bg-surface: #ebe5d9;
    --bg-hover: #e0d8ca;
    --text: #3a3530;
    --text-muted: #7a7468;
    --accent: #b07040;
    --accent-dim: #c49474;
    --tag-bg: #ddd5c4;
    --tag-text: #6b5040;
    --border: #d0c8b8;
    --code-bg: #e8e0d2;
}

/* Paper — clean minimal light */
[data-theme="paper"] {
    --bg: #fafaf8;
    --bg-surface: #f0efed;
    --bg-hover: #e6e5e2;
    --text: #2c2c2c;
    --text-muted: #777;
    --accent: #3a7bc8;
    --accent-dim: #6a9fd8;
    --tag-bg: #e4e8f0;
    --tag-text: #3060a0;
    --border: #d8d8d4;
    --code-bg: #eceae6;
}

/* Peach — warm peachpuff light */
[data-theme="peach"] {
    --bg: #ffdab9;
    --bg-surface: #ffe6cc;
    --bg-hover: #ffcfa3;
    --text: #4a2a18;
    --text-muted: #8a6850;
    --accent: #c2552a;
    --accent-dim: #e08a55;
    --tag-bg: #ffcd9e;
    --tag-text: #8a3e15;
    --border: #f0bf95;
    --code-bg: #f5d2ad;
}

/* Sky — soft light blue */
[data-theme="sky"] {
    --bg: #e3f2fd;
    --bg-surface: #d4e9f7;
    --bg-hover: #c2dcf0;
    --text: #14334d;
    --text-muted: #5a7890;
    --accent: #1976d2;
    --accent-dim: #5a9cd8;
    --tag-bg: #b8dcf2;
    --tag-text: #0d47a1;
    --border: #b8d4e8;
    --code-bg: #d0e4f2;
}

html {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
}

a {
    color: var(--accent);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

/* ---------- Misc ---------- */
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }

.empty {
    color: var(--text-muted);
    margin-top: 1rem;
}
.error-page { text-align: center; padding-top: 4rem; }
.error-page h1 { font-size: 3rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.error-page p { color: var(--text-muted); margin-bottom: 1.5rem; }

/* Toast notifications */
.toast {
    padding: 0.5rem 0.8rem;
    border-radius: 4px;
    font-size: 0.85rem;
    margin-bottom: 0.6rem;
    animation: toast-fade 6s ease-out forwards;
}
.toast-error {
    background: #7f1d1d;
    color: #fca5a5;
    border: 1px solid #991b1b;
}
@keyframes toast-fade {
    0%, 80% { opacity: 1; }
    100% { opacity: 0; }
}

/* Pin button */
.btn-pin { border-style: dashed; }
.btn-pin.pinned {
    border-style: solid;
    background: var(--accent-dim);
    color: var(--text);
}

/* Transitions */
a, .btn, .nav-folders li a {
    transition: background 0.15s, color 0.15s;
}

/* Focus ring for accessibility */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ---------- Responsive ---------- */

/* Tablet / phone landscape */
@media (max-width: 768px) {
    /* No top bar — sidebar is layout-empty; the hamburger floats over content. */
    .sidebar {
        position: static;
        width: auto;
        height: auto;
        padding: 0;
        background: transparent;
        border: none;
        gap: 0;
    }
    .nav-top { display: contents; }
    .sidebar .logo { display: none; }
    .nav-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        top: 0.5rem;
        left: 0.5rem;
        z-index: 250;
        min-width: 40px;
        min-height: 40px;
        padding: 0.3rem 0.55rem;
        background: var(--bg-surface);
        border: 1px solid var(--border);
        border-radius: 6px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
        color: var(--text);
        font-size: 1.15rem;
        line-height: 1;
        cursor: pointer;
    }
    .nav-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

    /* Drawer header (SuperHub title + close), only shown on mobile */
    .drawer-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 0.5rem;
        margin-bottom: 0.6rem;
        padding-bottom: 0.6rem;
        border-bottom: 1px solid var(--border);
    }
    .drawer-title {
        font-size: 1.25rem;
        font-weight: 700;
        color: var(--accent);
        text-decoration: none;
        letter-spacing: -0.02em;
    }
    .drawer-title:hover { text-decoration: none; }
    .nav-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 36px;
        min-height: 36px;
        padding: 0.3rem 0.6rem;
        background: transparent;
        border: 1px solid transparent;
        border-radius: 4px;
        color: var(--text-muted);
        font-size: 1.2rem;
        line-height: 1;
        cursor: pointer;
    }
    .nav-close:hover { color: var(--text); background: var(--bg-hover); }
    .nav-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

    /* Backdrop dims content when drawer is open */
    .nav-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
        z-index: 200;
    }
    .sidebar.nav-open .nav-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    /* Drawer slides in from the left */
    .nav-drawer {
        position: fixed;
        top: 0;
        left: 0;
        width: 85%;
        max-width: 320px;
        height: 100vh;
        height: 100dvh;
        background: var(--bg-surface);
        border-right: 1px solid var(--border);
        padding: 1rem;
        z-index: 201;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
        gap: 0.3rem;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }
    .sidebar.nav-open .nav-drawer {
        transform: translateX(0);
    }
    .nav-drawer .search-form { margin-bottom: 0.5rem; }

    /* Lock background scroll while the overlay is open */
    body.nav-locked { overflow: hidden; }

    /* Folder + guide links: vertical, tap-friendly */
    .nav-folders { display: block; overflow: visible; }
    .nav-folders li a,
    .nav-guide {
        display: flex;
        align-items: center;
        min-height: 40px;
        padding: 0.5rem 0.7rem;
        font-size: 0.95rem;
        white-space: normal;
    }
    .theme-select {
        font-size: 0.9rem;
        padding: 0.5rem 0.6rem;
        margin: 0.3rem 0;
        width: 100%;
    }
    .user-menu {
        flex-direction: column;
        align-items: stretch;
        gap: 0.25rem;
        padding-top: 0.5rem;
        margin-top: 0.3rem;
        border-top: 1px solid var(--border);
    }
    .user-menu a {
        display: flex;
        align-items: center;
        min-height: 40px;
        padding: 0.4rem 0.7rem;
    }
    .user-name { padding: 0.3rem 0.7rem; color: var(--text-muted); }

    /* Main content — top padding clears the floating hamburger */
    main {
        margin-left: 0;
        padding: 3rem 1rem 1rem;
    }
    .page-header {
        flex-wrap: wrap;
        align-items: center;
        gap: 0.5rem;
    }

    /* Note view */
    .note-header-row {
        flex-wrap: wrap;
        align-items: center;
        gap: 0.5rem;
    }
    .note-header-row .btn { font-size: 0.85rem; padding: 0.4rem 0.7rem; }

    /* Edit form */
    .edit-meta { flex-direction: column; }
    .field-short { flex: 1; }
    .editor { min-height: 320px; font-size: 0.95rem; padding: 0.8rem; }
    .edit-actions { flex-wrap: wrap; gap: 0.4rem; }
    .edit-actions .btn { padding: 0.5rem 0.9rem; font-size: 0.9rem; }
    .template-picker { flex-direction: column; align-items: stretch; }

    /* Editor toolbar — bigger tap targets, wraps as needed */
    .editor-toolbar { gap: 0.35rem; padding: 0.4rem 0.5rem; }
    .toolbar-btn { font-size: 0.85rem; padding: 0.4rem 0.6rem; min-height: 36px; }

    /* Search */
    .filters { flex-direction: column; }
    .filters select { width: 100%; }

    /* History / admin tables */
    .history-table { display: block; overflow-x: auto; }
    .admin-table { display: block; overflow-x: auto; }

    /* Tasks dashboard */
    .task-group { padding: 0.6rem 0.8rem; }

    /* Tag cloud */
    .tag-cloud-sized { gap: 0.4rem; }
    .tag { padding: 0.25rem 0.55rem; font-size: 0.85rem; }

    /* Note list — comfortable row height */
    .note-list li { padding: 0.7rem 0; }

    /* Login/setup on small screens */
    .login-form { width: 90vw; max-width: 320px; }
    .setup-form { width: 90vw; max-width: 360px; }
}

/* Phone portrait */
@media (max-width: 480px) {
    main { padding: 0.8rem; }
    h1 { font-size: 1.3rem; }
    h2 { font-size: 1.1rem; }

    /* Note list: meta wraps below title */
    .note-list li {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.2rem;
    }
    .note-list .meta { flex-wrap: wrap; }

    /* Full-width primary actions */
    .edit-actions { flex-direction: column; }
    .edit-actions .btn { width: 100%; text-align: center; }
}

