/*
 * base.css: app shell
 *
 * Sidebar, main content area, report table tiers, toggle switch, rich-text
 * editor frame, cookie banner and the auth page layout. Colours come from the
 * roles in brand.css (dark values in darkmode.css), so nothing here needs a
 * dark-mode twin. WhiteNoise (CompressedManifestStaticFilesStorage) adds a
 * content-hash suffix in production.
 */

/* ===========================================================================
   APP COLOR TOKENS
   Component-level names that templates and rules read. Each one points at a
   role in brand.css, so it flips with the theme.
   =========================================================================== */
:root {
    /* Sidebar. Dark in both themes. */
    --sidebar-bg: var(--fd-head-bg);
    --sidebar-fg: var(--fd-gray-50);
    --sidebar-divider-bg: rgba(255, 255, 255, 0.14);
    --sidebar-link-hover-bg: rgba(255, 255, 255, 0.08);
    --sidebar-link-hover-fg: #ffffff;
    --sidebar-switcher-bg: rgba(255, 255, 255, 0.08);
    --sidebar-switcher-hover-bg: rgba(255, 255, 255, 0.14);
    --sidebar-switcher-border: rgba(255, 255, 255, 0.22);
    --sidebar-switcher-hover-border: rgba(255, 255, 255, 0.35);

    /* Accounting report table row tiers */
    --report-major-bg: var(--fd-head-bg);
    --report-major-fg: var(--fd-head-fg);
    --report-section-bg: var(--fd-gray-700);
    --report-section-fg: #ffffff;
    --report-row-bg: var(--fd-bg-surface);
    --report-subtotal-bg: var(--fd-bg-alt);
    --report-subtotal-border: var(--fd-border);
    --report-section-total-bg: var(--fd-bg-alt);
    --report-grand-total-bg: var(--fd-border);

    /* Content / layout areas */
    --main-content-bg: var(--fd-bg-page);

    /* Toggle switches */
    --switch-track-disabled-on-bg: var(--fd-text-muted);

    /* Rich text editor (Quill) */
    --editor-toolbar-bg: var(--fd-bg-alt);
    --notes-view-bg: var(--fd-bg-alt);

    /* Cookie consent banner */
    --cookie-banner-bg: var(--fd-head-bg);
    --cookie-banner-fg: var(--fd-gray-50);
    --cookie-banner-shadow: rgba(0, 0, 0, 0.25);
    --cookie-banner-link-fg: var(--fd-gray-300);
    --cookie-btn-border: var(--fd-gray-500);
    --cookie-btn-hover-bg: var(--fd-gray-700);

    /* Google sign-in button */
    --google-btn-bg: #ffffff;
    --google-btn-fg: #3c4043;
    --google-btn-border: #dadce0;
    --google-btn-hover-bg: #f8f9fa;
    --google-btn-hover-border: #c4c7cc;
    --google-btn-shadow: rgba(60, 64, 67, 0.12);
    --google-btn-active-bg: #f1f3f4;

    /* Google sign-in button, dark variant */
    --google-btn-dark-bg: #1f1f1f;
    --google-btn-dark-fg: #e8eaed;
    --google-btn-dark-border: #5f6368;
    --google-btn-dark-hover-bg: #2a2a2a;
    --google-btn-dark-hover-border: #80868b;
}

/* ===========================================================================
   PAGE FRAME
   The document scrolls, not <body>. Clipping happens on #main-content only,
   with overflow-x: clip, which hides a stray wide child without turning the
   content area into a scroll container.
   =========================================================================== */
html, body {
    margin: 0;
}
body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
.wrapper {
    flex: 1 0 auto;
    display: flex;
    flex-wrap: nowrap;
    min-height: 100vh;
}
footer.footer {
    flex-shrink: 0;
    overflow-x: clip;
}

/* Muted utility classes still used by a few templates */
.gap-05 { gap: 0.5rem; }
.gap-075 { gap: 0.75rem; }

/* ==========================================================================
   TOGGLE SWITCH
   ========================================================================== */
.switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 34px;
}
.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--switch-track-bg);
    transition: .4s;
}
.slider:before {
    position: absolute;
    content: "";
    height: 26px;
    width: 26px;
    left: 4px;
    bottom: 4px;
    background-color: var(--white);
    transition: .4s;
}
.switch input:checked + .slider {
    background-color: var(--fd-success-fill);
}
.switch input:focus-visible + .slider {
    outline: 2px solid var(--fd-primary);
    outline-offset: 2px;
}
.switch input:checked + .slider:before {
    transform: translateX(26px);
}
.switch input:disabled + .slider {
    cursor: not-allowed;
    opacity: 0.5;
    background-color: var(--switch-track-disabled-bg);
}
.switch input:disabled:checked + .slider {
    background-color: var(--switch-track-disabled-on-bg);
    opacity: 0.5;
}
.slider.round {
    border-radius: 34px;
}
.slider.round:before {
    border-radius: 50%;
}

/* ==========================================================================
   SIDEBAR
   ========================================================================== */
#left-nav {
    background-color: var(--sidebar-bg);
    color: var(--sidebar-fg);
    width: 240px;              /* Expanded width */
    min-width: 240px;
    transition: width 0.3s ease;
    overflow-x: hidden;        /* No horizontal scroll */
    display: flex;
    flex-direction: column;
    /* Sidebar is a flex child of .wrapper (display:flex), so by default
       it stretches to match #main-content height. On pages with tall
       content (e.g., the unauthenticated landing page at /users/), the
       flex-grow:1 .nav-items child fills the empty space, producing a
       dark rectangle below the visible links (FRE-408). Size the sidebar
       to the viewport, opt out of flex stretch, and make it sticky so it
       runs the full height of the window and stays in view while the main
       content scrolls. A short nav list leaves the dark fill under it, and
       a long one scrolls inside the sidebar. */
    align-self: flex-start;
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
}
#left-nav.collapsed {
    width: 60px;               /* Collapsed width */
    min-width: 60px;
}

/* Sidebar Header: Logo + Hamburger */
#sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    background-color: var(--fd-primary-fill);
    color: var(--white);
}
#sidebar-header .logo-link {
    display: flex;
    align-items: center;
    color: var(--white);
    text-decoration: none;
}
#sidebar-header .logo-link img {
    height: 32px;
    width: auto;
    border-radius: var(--fd-radius-sm);
}
#sidebar-header .logo-link .logo-text {
    margin-left: 0.5rem;
    font-weight: 600;
}
#sidebarToggle {
    background: none !important;
    border: none !important;
    color: var(--white) !important;
    font-size: 1.25rem;
    padding: 0;
    margin: 0;
    cursor: pointer;
}
#sidebarToggle:focus {
    outline: none;
}

/* Adjust header layout when sidebar is collapsed */
#left-nav.collapsed #sidebar-header {
    flex-direction: column;
    align-items: center;
}
#left-nav.collapsed #sidebarToggle {
    order: -1;
}
#left-nav.collapsed #sidebar-header .logo-link {
    margin-top: 0.5rem;
}
#left-nav.collapsed #sidebar-header .logo-text {
    display: none;
}
#account-switcher {
    padding: 0.5rem 1rem;
    overflow-x: hidden;
}
#account-switcher select {
    width: 100%;
    min-height: 0;
    padding: 0.5rem 2rem 0.5rem 0.75rem;
    font-size: 0.875rem;
    border-radius: 0.375rem;
    border: 1px solid var(--sidebar-switcher-border);
    background-color: var(--sidebar-switcher-bg);
    color: var(--sidebar-fg);
    cursor: pointer;
    /* Custom dropdown arrow */
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23f8f9fa' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 12px;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
#account-switcher select:hover {
    border-color: var(--sidebar-switcher-hover-border);
    background-color: var(--sidebar-switcher-hover-bg);
}
#account-switcher select:focus {
    outline: none;
    border-color: var(--fd-primary);
    box-shadow: 0 0 0 2px var(--fd-focus-ring);
}
#account-switcher select option {
    background-color: var(--fd-head-bg);
    color: var(--sidebar-fg);
    padding: 0.5rem;
}
/* Hide account switcher when collapsed */
#left-nav.collapsed #account-switcher {
    display: none;
}

/* Container for nav items */
.nav-items {
    flex-grow: 1;
    overflow-x: hidden;
    padding-top: 0;
}
#left-nav .nav-items {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 0;
    gap: 0;
}

/* Divider between sections */
.sidebar-divider {
    height: 1px;
    background-color: var(--sidebar-divider-bg);
    margin: 0.5rem 0;
    width: 100%;
}

/* NAV LINK Styling */
#left-nav .nav-item {
    width: 100%;
    overflow-x: hidden;
    display: block;
    padding: 0;
}
#left-nav .nav-link {
    color: var(--sidebar-fg) !important;
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem;
    text-decoration: none;
    font-size: 0.95rem;
    background: none !important;
    border: none !important;
    border-radius: 0;
    overflow: hidden;
}
#left-nav.collapsed .nav-link {
    justify-content: center;
    padding: 0.5rem;
}
#left-nav .nav-link:hover {
    background-color: var(--sidebar-link-hover-bg) !important;
    text-decoration: none !important;
    color: var(--sidebar-link-hover-fg) !important;
}
#left-nav .nav-link i {
    width: 1.25rem;
    text-align: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}
#left-nav.collapsed .nav-link i {
    margin: 0;
}
#left-nav .nav-text {
    margin-left: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity 0.3s ease;
}
/* Hide text when collapsed */
#left-nav.collapsed .nav-text {
    opacity: 0;
    display: none;
}

/* Indented "child" links (superuser) */
.indent-link {
    padding-left: 2.5rem; /* Indent under parent */
    font-size: 0.85rem;   /* Slightly smaller */
}
#left-nav.collapsed .indent-link {
    padding-left: 0.5rem; /* Show icons without extra indent */
    display: flex !important; /* Ensure links remain visible when collapsed */
    justify-content: center;
}

/* -----------------------
   MAIN CONTENT (desktop)
   ----------------------- */
#main-content {
    flex-grow: 1;
    min-width: 0;
    padding: 0;
    background-color: var(--main-content-bg);
    overflow-x: clip;  /* Clip a stray wide child. Does not create a scroll container. */
    display: flex;
    flex-direction: column;
}

/* =======================
   COLLAPSED LAYOUT (< 992px)
   Phones and tablets in portrait. The sidebar stacks above the content as a
   header bar, because a 240px sidebar leaves a tablet only about 530px.
   Keep the breakpoint in sync with MOBILE_BREAKPOINT in base.html.
   ======================= */
@media (max-width: 991.98px) {
    /* Stack sidebar and main content vertically */
    .wrapper {
        display: flex;
        flex-direction: column;
        min-height: auto; /* no fixed height */
    }

    /* Sidebar becomes a full-width header bar. Collapsed, it is one line:
       the brand on the left, the menu button on the right. Open, the nav
       list drops below it. */
    #left-nav {
        width: 100%;
        min-width: 100%;
        position: relative;
        height: auto;
        overflow: hidden;
    }
    #left-nav:not(.collapsed) {
        max-height: 100vh;
        max-height: 100dvh;
        overflow-y: auto;
    }
    #left-nav.collapsed {
        width: 100%;
        min-width: 100%;
    }

    /* Nav-items: ensure no inner scroll and no extra space */
    .nav-items {
        overflow-y: visible;
        flex-grow: 0;
    }
    #left-nav.collapsed .nav-items {
        display: none;
    }

    /* Tighter spacing & smaller elements */
    #sidebar-header {
        padding: 0.5rem 0.75rem;
    }
    #sidebar-header .logo-link img {
        height: 28px;
    }
    #sidebar-header .logo-link .logo-text {
        font-size: 1rem;
    }
    #left-nav .nav-link {
        padding: 0.4rem 0.75rem;
        font-size: 0.9rem;
    }
    #left-nav .nav-link i {
        font-size: 1rem;
    }
    .sidebar-divider {
        margin: 0.25rem 0;
    }

    /* Maintain header layout when collapsed */
    #left-nav.collapsed #sidebar-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
    #left-nav.collapsed #sidebarToggle {
        order: 0;
    }
    #left-nav.collapsed #sidebar-header .logo-link {
        margin-top: 0;
    }
    #left-nav.collapsed #sidebar-header .logo-text {
        display: inline;
    }

    /* Main content full width */
    #left-nav + #main-content,
    #left-nav.collapsed + #main-content {
        width: 100%;
        padding: 0;
    }

    /* One bar on a phone: the menu button sits in the brand bar, with a
       44px tap target. */
    #sidebarToggle {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: flex-end;
    }
    #sidebar-header {
        min-height: 52px;
    }

    /* Account switcher on mobile - full width when expanded */
    #account-switcher {
        padding: 0.5rem 0.75rem;
    }
    #account-switcher select {
        font-size: 0.9rem;
    }
}

/* =======================
   LARGE DESKTOP (≥ 1400px)
   ======================= */
@media (min-width: 1400px) {
    #left-nav {
        width: 260px;
        min-width: 260px;
    }
    #left-nav.collapsed {
        width: 60px;
        min-width: 60px;
    }
}

/* ===========================================================================
   Rich Text Editor (Quill) container styles
   =========================================================================== */
.rich-text-container {
    border: 1px solid var(--control-border);
    border-radius: var(--fd-radius-md);
    overflow: hidden;
}
.rich-text-container .ql-toolbar {
    border: none;
    border-bottom: 1px solid var(--control-border);
    background: var(--editor-toolbar-bg);
}
.rich-text-container .ql-container {
    border: none;
    font-size: 1rem;
}
.rich-text-container .ql-editor {
    min-height: 100px;
}
.rich-text-container .ql-editor.ql-blank::before {
    font-style: normal;
    color: var(--muted-fg);
}
.markdown-editor {
    border: none !important;
    border-radius: 0 !important;
}

/* ===========================================================================
   COOKIE CONSENT BANNER (GDPR/CCPA, FRE-142)
   Fixed bottom bar. Hidden by default; shown by the server when no valid
   cookie_consent cookie exists, or re-shown by the Privacy Preferences link.
   =========================================================================== */
#cookie-consent-banner {
    display: none; /* JS/server controls visibility */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background-color: var(--cookie-banner-bg);
    color: var(--cookie-banner-fg);
    padding: 1rem 1.5rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -2px 8px var(--cookie-banner-shadow);
}

.cookie-banner-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    max-width: 1200px;
    margin: 0 auto;
}

.cookie-banner-text {
    flex: 1 1 300px;
    font-size: 0.875rem;
    line-height: 1.5;
}

.cookie-banner-text strong {
    display: block;
    margin-bottom: 0.25rem;
    font-size: 0.9375rem;
}

.cookie-banner-text a {
    color: var(--cookie-banner-link-fg);
    text-decoration: underline;
}

.cookie-banner-text a:hover {
    color: var(--cookie-banner-fg);
}

.cookie-banner-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.cookie-banner-actions .btn-cookie-essential {
    background-color: transparent;
    border: 1px solid var(--cookie-btn-border);
    color: var(--cookie-banner-link-fg);
    padding: 0.375rem 0.875rem;
    font-size: 0.875rem;
    border-radius: var(--fd-radius-md);
    cursor: pointer;
    white-space: nowrap;
}

.cookie-banner-actions .btn-cookie-essential:hover {
    background-color: var(--cookie-btn-hover-bg);
    border-color: var(--cookie-btn-hover-bg);
    color: var(--cookie-banner-fg);
}

.cookie-banner-actions .btn-cookie-all {
    background-color: var(--fd-primary-fill);
    border: 1px solid var(--fd-primary-fill);
    color: var(--white);
    padding: 0.375rem 0.875rem;
    font-size: 0.875rem;
    border-radius: var(--fd-radius-md);
    cursor: pointer;
    font-weight: 600;
    white-space: nowrap;
}

.cookie-banner-actions .btn-cookie-all:hover {
    background-color: var(--fd-primary-fill-hover);
    border-color: var(--fd-primary-fill-hover);
    color: var(--white);
}

@media (max-width: 575.98px) {
    #cookie-consent-banner {
        padding: 0.75rem 1rem;
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
    }
    .cookie-banner-inner {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
    /* flex-basis 300px is a width in a row and a 300px height in a column. */
    .cookie-banner-text {
        flex: 0 0 auto;
        font-size: 0.8125rem;
        line-height: 1.4;
    }
    .cookie-banner-text strong {
        display: inline;
        margin: 0 0.25rem 0 0;
    }
    .cookie-banner-actions {
        width: 100%;
    }
    .cookie-banner-actions > button {
        flex: 1 1 0;
        min-height: 44px;
    }
}

/* ==========================================================================
   AUTH PAGES (login, register, password reset)
   Full-width centered layout, no sidebar, sticky footer.
   ========================================================================== */
body.auth-page #left-nav,
body.auth-page #mobile-toggle-bar {
    display: none;
}

body.auth-page .wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

body.auth-page #main-content {
    margin-left: 0;
    width: 100%;
    flex: 1 0 auto;
}

/* Auth card sizing: logo small, headings flat */
body.auth-page .auth-card,
body.auth-page .register-card {
    max-width: 28rem;
    margin-left: auto;
    margin-right: auto;
}

body.auth-page .auth-logo {
    max-height: 64px;
    width: auto;
    margin: 0 auto;
    display: block;
}

body.auth-page .auth-heading {
    font-family: var(--fd-font-display, inherit);
    font-size: 1.75rem;
    font-weight: 700;
    text-align: center;
    margin: 0 0 0.5rem 0;
    padding: 0;
    background: transparent;
    border: 0;
    color: inherit;
}

body.auth-page .auth-subhead {
    text-align: center;
    color: var(--fd-text-muted);
    margin-bottom: 1.25rem;
}

/* Google OAuth button: official Google branding (white bg, dark text,
   light border, Google logo). Used on both login and register pages. */
.btn-google {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.625rem;
    width: 100%;
    padding: 10px 14px;
    background-color: var(--google-btn-bg);
    color: var(--google-btn-fg);
    border: 1px solid var(--google-btn-border);
    border-radius: var(--fd-radius-md);
    font-family: 'Roboto', var(--fd-font-sans, inherit);
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1.4;
    text-decoration: none;
    transition: background-color 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
    cursor: pointer;
}

.btn-google:hover,
.btn-google:focus {
    background-color: var(--google-btn-hover-bg);
    color: var(--google-btn-fg);
    border-color: var(--google-btn-hover-border);
    text-decoration: none;
    box-shadow: 0 1px 3px var(--google-btn-shadow);
}

.btn-google:active {
    background-color: var(--google-btn-active-bg);
}

.btn-google .google-logo {
    flex: 0 0 18px;
    width: 18px;
    height: 18px;
}

/* Dark mode: Google guidelines allow a dark variant */
html[data-theme="dark"] .btn-google {
    background-color: var(--google-btn-dark-bg);
    color: var(--google-btn-dark-fg);
    border-color: var(--google-btn-dark-border);
}
html[data-theme="dark"] .btn-google:hover,
html[data-theme="dark"] .btn-google:focus {
    background-color: var(--google-btn-dark-hover-bg);
    color: var(--google-btn-dark-fg);
    border-color: var(--google-btn-dark-hover-border);
}

/* "use password instead" link: plain inline link, no flanking dividers */
.auth-text-link {
    display: inline-block;
    color: var(--fd-link);
    text-decoration: underline;
    background: transparent;
    border: 0;
    padding: 0;
    font-size: 0.95rem;
    cursor: pointer;
}
.auth-text-link:hover,
.auth-text-link:focus {
    color: var(--fd-link-hover);
    text-decoration: underline;
}
