/* --- Base & Theme Variables --- */
:root {
    --md-sys-color-primary: #6750A4;
    --md-sys-color-on-primary: #FFFFFF;
    --md-sys-color-primary-container: #EADDFF;
    --md-sys-color-on-primary-container: #21005D;
    --md-sys-color-secondary: #625B71;
    --md-sys-color-on-secondary: #FFFFFF;
    --md-sys-color-secondary-container: #E8DEF8;
    --md-sys-color-on-secondary-container: #1D192B;
    --md-sys-color-tertiary-container: #FFD8E4;
    --md-sys-color-on-tertiary-container: #31111D;
    --md-sys-color-background: #FFFBFE;
    --md-sys-color-on-background: #1C1B1F;
    --md-sys-color-surface: #FFFBFE;
    --md-sys-color-on-surface: #1C1B1F;
    --md-sys-color-surface-variant: #E7E0EC;
    --md-sys-color-on-surface-variant: #49454F;
    --md-sys-color-surface-bright: #FEF7FF;
    --md-sys-color-surface-container-high: #ECE6F0;
    --md-sys-color-surface-container-highest: #E6E0E9;
    --md-sys-color-surface-container-low: #F7F2FA;
    --md-sys-color-surface-container: #F3EDF7;
    --md-sys-color-outline: #79747E;
    --md-sys-color-outline-variant: #CAC4D0;
    --md-sys-color-inverse-surface: #313033;
    --md-sys-color-inverse-on-surface: '#F4EFF4';
    --md-sys-color-error: #B3261E;

    --drawer-width: 280px;
}

body {
    font-family: 'Roboto', sans-serif;
    margin: 0;
    background-color: var(--md-sys-color-background);
    color: var(--md-sys-color-on-background);
    overflow-x: hidden;
}

/* --- Common Styles --- */
.nav-header {
    display: flex;
    align-items: center;
    padding: 16px 16px 24px 16px;
}

.logo-icon {
    font-size: 24px;
    margin-right: 12px;
    color: var(--md-sys-color-primary);
}

.app-name {
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
}

.nav-menu {
    list-style: none;
    padding: 0;
    margin: 0;
    overflow-y: auto;
}

.nav-menu li {
    margin-bottom: 4px;
}

.nav-menu a {
    display: flex;
    align-items: center;
    height: 56px;
    padding: 0 24px;
    border-radius: 28px;
    text-decoration: none;
    color: var(--md-sys-color-on-surface-variant);
    font-size: 0.875rem;
    font-weight: 500;
    transition: background-color 0.2s, color 0.2s;
}

.nav-menu a:hover {
    background-color: rgba(29, 25, 43, 0.08);
    color: var(--md-sys-color-on-surface);
}

.nav-menu a.active {
    background-color: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
}

.nav-menu a .material-symbols-rounded {
    margin-right: 12px;
    font-size: 24px;
}

.divider {
    height: 1px;
    background-color: var(--md-sys-color-outline);
    margin: 12px 16px;
    opacity: 0.2;
}

.page-title {
    font-size: 1.375rem;
    font-weight: 400;
    margin: 0;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    font-weight: 500;
}

.content-wrapper {
    padding: 24px;
    background-color: var(--md-sys-color-background);
}

/* --- Form Elements --- */
.form-input-styled {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 8px;
    background-color: var(--md-sys-color-surface-bright);
    color: var(--md-sys-color-on-surface);
    font-family: inherit;
    font-size: 1rem;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input-styled:focus {
    outline: none;
    border-color: var(--md-sys-color-primary);
    box-shadow: 0 0 0 2px var(--md-sys-color-primary-container);
}

.form-input,
.form-textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: 4px;
    background-color: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    font-family: inherit;
    font-size: 1rem;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--md-sys-color-primary);
    box-shadow: 0 0 0 2px var(--md-sys-color-primary-container);
}

.form-textarea {
    resize: vertical;
}

/* --- Toast Notifications ---------------------------------------------------
 *
 * Plain CSS rather than Tailwind classes: these are built by JavaScript at
 * runtime, and Tailwind only compiles the classes it can see in a template at
 * build time -- so a class used only from JS silently does nothing.
 *
 * The container sits clear of the support launcher, which is a 56px circle at
 * bottom-right with a z-index near the maximum. Toasts used to render
 * underneath it, so a message like "Confirmation email sent" was cut off by
 * the chat bubble at exactly the moment it mattered.
 */
#toast-container {
    position: fixed;
    /* Above the support launcher (56px) plus its 20px inset, plus breathing
     * room, so the two never overlap. */
    bottom: calc(96px + env(safe-area-inset-bottom, 0px));
    right: 1.25rem;
    left: 1.25rem;
    z-index: 2147483001;   /* one above the support launcher */
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
    pointer-events: none;  /* the gaps between toasts must not eat clicks */
}

.toast-message {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    width: 100%;
    max-width: 24rem;
    padding: 0.875rem 1rem;
    border-radius: 0.875rem;
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.12), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    background-color: var(--md-sys-color-inverse-surface, #313033);
    color: var(--md-sys-color-inverse-on-surface, #F4EFF4);
    font-size: 0.9375rem;
    line-height: 1.4;
    pointer-events: auto;
    opacity: 0;
    transform: translateY(0.5rem);
    transition: opacity 0.2s ease-out, transform 0.2s ease-out;
}

/* Added on the next frame, so the transition has a start state to run from. */
.toast-message.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.toast-message.is-leaving {
    opacity: 0;
    transform: translateY(0.5rem);
}

.toast-message .toast-text {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;   /* a long word must wrap, not overflow the card */
}

.toast-message .icon {
    flex: 0 0 auto;
    font-size: 1.25rem;
    line-height: 1.4;
}

.toast-message .toast-close {
    flex: 0 0 auto;
    margin: -0.25rem -0.25rem -0.25rem 0;
    padding: 0.25rem;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: inherit;
    cursor: pointer;
    opacity: 0.7;
    font-size: 1.125rem;
    line-height: 1;
}
.toast-message .toast-close:hover,
.toast-message .toast-close:focus-visible {
    opacity: 1;
    background: rgb(255 255 255 / 0.15);
}

/* Colours carry meaning, so each also gets its own icon in the markup --
 * colour alone is not available to everybody. */
.toast-message.success { background-color: #1B5E20; color: #FFFFFF; }
.toast-message.error   { background-color: #8C1D18; color: #FFFFFF; }
.toast-message.warning { background-color: #6D4C00; color: #FFFFFF; }
.toast-message.info    { background-color: #0B4A6F; color: #FFFFFF; }

@media (prefers-reduced-motion: reduce) {
    .toast-message {
        transition: opacity 0.01ms;
        transform: none;
    }
    .toast-message.is-visible,
    .toast-message.is-leaving { transform: none; }
}

@media (max-width: 767px) {
    #toast-container {
        /* Above the mobile bottom navigation bar (64px) and the launcher. */
        bottom: calc(150px + env(safe-area-inset-bottom, 0px));
        align-items: stretch;
    }
    .toast-message { max-width: none; }
}

.pb-safe {
    padding-bottom: env(safe-area-inset-bottom);
}

/* =========================================
   MOBILE FIRST STYLES (Default)
   ========================================= */
.app-container {
    display: block !important; /* Force block on mobile */
    min-height: 100vh;
}

/* Hide desktop sidebar on mobile */
.desktop-sidebar, .desktop-sidebar-nav {
    display: none !important;
}

/* Ensure old class is also hidden if cached HTML is used */
.navigation-drawer {
    display: none !important;
}

.top-app-bar {
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background-color: var(--md-sys-color-surface);
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    position: sticky;
    top: 0;
    z-index: 90;
}

.content-area {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.content-wrapper {
    padding: 16px;
    padding-bottom: 80px; /* Space for bottom nav */
}

.page-title {
    font-size: 1.25rem;
}

/* Material Symbols filled state for active icons */
.material-symbols-rounded.filled {
    font-variation-settings: 'FILL' 1;
}

/* =========================================
   DESKTOP STYLES (min-width: 768px)
   ========================================= */
@media (min-width: 768px) {
    .app-container {
        display: grid !important;
        grid-template-columns: var(--drawer-width) 1fr;
    }

    .desktop-sidebar, .desktop-sidebar-nav {
        display: flex !important; /* Visible on desktop */
        background-color: var(--md-sys-color-surface);
        border-right: 1px solid var(--md-sys-color-outline-variant);
        padding: 12px;
        position: sticky;
        top: 0;
        height: 100vh;
        box-sizing: border-box;
        flex-direction: column;
        z-index: 100;
    }

    /* Reset old class for desktop if needed */
    .navigation-drawer {
        display: flex !important;
    }

    .top-app-bar {
        padding: 0 24px;
    }

    .content-wrapper {
        padding: 24px;
        padding-bottom: 24px; /* Reset padding */
    }

    .page-title {
        font-size: 1.375rem;
    }

}

/* ---------------------------------------------------------------------------
   Tap targets
   ---------------------------------------------------------------------------
   Apple's minimum is 44x44 CSS pixels and Google's is 48x48; 48 is used here
   because it satisfies both and because a control that is exactly at the limit
   is still one people miss.

   Written by hand rather than as Tailwind classes: the arbitrary-value classes
   this needs are not in the compiled stylesheet, and a class Tailwind never
   built is inert -- no error, no warning, the attribute simply does nothing.

   `min-height` and `min-width` rather than fixed sizes, so a control that is
   already comfortable is left alone and only the small ones grow. The flex
   centring keeps the label where it was: the target gets bigger, the design
   does not move.
   --------------------------------------------------------------------------- */
.tap-target {
    min-height: 48px;
    min-width: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* For a link sitting in a row of links, where a minimum width would space
   them out oddly. Height alone is what makes these hittable. */
.tap-target-y {
    min-height: 48px;
    display: inline-flex;
    align-items: center;
}

/* ---------------------------------------------------------------------------
   allauth's own pages
   ---------------------------------------------------------------------------
   Signup, password reset, email confirmation and the rest use allauth's
   templates rather than ones written here, and allauth ships them with no
   classes at all -- browser-default buttons and inputs, small and grey, well
   under a thumb's width on a phone.

   The classes below are applied by overriding two allauth "elements"
   (templates/allauth/elements/), which is its documented extension point and
   themes every one of those pages at once, including ones a future version
   adds.
   --------------------------------------------------------------------------- */
.pt-auth-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 0 24px;
    border: 0;
    border-radius: 999px;
    background: var(--md-sys-color-primary, #6750A4);
    color: var(--md-sys-color-on-primary, #FFFFFF);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
}

.pt-auth-btn:hover { filter: brightness(1.08); }

.pt-auth-btn--quiet {
    background: transparent;
    border: 1px solid var(--md-sys-color-outline-variant, #CAC4D0);
    color: var(--md-sys-color-on-surface, #1D1B20);
}

.pt-auth-field { margin: 0 0 16px 0; }

.pt-auth-label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant, #49454F);
}

.pt-auth-label--inline {
    display: inline;
    margin: 0 0 0 8px;
    font-weight: 400;
}

.pt-auth-input {
    width: 100%;
    min-height: 48px;
    padding: 0 16px;
    border: 1px solid var(--md-sys-color-outline-variant, #CAC4D0);
    border-radius: 16px;
    background: var(--md-sys-color-surface, #FFFBFE);
    color: var(--md-sys-color-on-surface, #1D1B20);
    /* 16px or larger. Below that, iOS Safari zooms the whole page the moment
       somebody taps the field, and they have to pinch back out to find the
       button -- on the signup form, of all places. */
    font-size: 1rem;
}

textarea.pt-auth-input { padding: 12px 16px; min-height: 120px; }

.pt-auth-input:focus {
    outline: 2px solid var(--md-sys-color-primary, #6750A4);
    outline-offset: 1px;
}

/* A checkbox is a tap target too, and the browser default is 13px square. */
.pt-auth-check { width: 20px; height: 20px; }

.pt-auth-help {
    display: block;
    margin-top: 6px;
    font-size: 0.8125rem;
    color: var(--md-sys-color-on-surface-variant, #49454F);
}

.errorlist {
    margin: 0 0 8px 0;
    padding: 0;
    list-style: none;
    color: var(--md-sys-color-error, #B3261E);
    font-size: 0.875rem;
}
