/* ============================================================================
   Settings page (/settings) — "Mail / WhatsApp Settings"
   ----------------------------------------------------------------------------
   WHY THIS FILE IS GLOBAL AND NOT A SCOPED .razor.css
   ---------------------------------------------------
   The app shell is built for SmartGrid screens, which scroll *inside* themselves:

       .page-body-wrapper   height: calc(100vh - 2px);  overflow: hidden   (appV.css)
         .page-body         height: calc(100vh - 65px); overflow: hidden   (appV/app.css)
           .root-container  height: 100%                                   (appV.css)

   Every one of those clips. A page hosted in there can only scroll if it builds an
   unbroken chain of height:100% + flex-grow + min-height:0 down to a single
   overflow:auto pane — and if ANY link in that chain breaks, nothing scrolls and
   no scrollbar appears; the content is just silently cut off. That is exactly what
   kept happening here, because the settings markup added four more overflow:hidden
   links of its own on top of the shell's three.

   So this page opts OUT of that model: `:has(.settings-page)` turns the shell's
   clipping ancestors back into a normal scrolling document for this route only,
   and the page content below flows at its natural height. One scroller, no chain
   to break. Those ancestor rules cannot live in a scoped .razor.css — Blazor
   rewrites scoped selectors with the component's `[b-xxxxx]` attribute, which the
   shell elements do not carry — hence a plain stylesheet, loaded from App.razor.
   ============================================================================ */

/* ===========================================================================
   0. Unlock the shell — scoped to this route via :has(), nothing else changes
   ======================================================================== */
#pageWrapper .page-body-wrapper:has(.settings-page) {
    height: auto;
    min-height: calc(100vh - 2px);
    overflow: visible;
}

#pageWrapper .page-body-wrapper .page-body:has(.settings-page) {
    height: auto !important;
    min-height: calc(100vh - 65px);
    overflow: visible;
}

.root-container:has(.settings-page) {
    height: auto;
    overflow: visible;
}

/* ===========================================================================
   1. Tokens — same theme-driven approach as the rest of the app
   ======================================================================== */
.settings-page {
    --set-accent: var(--theme-default, #7366ff);
    --set-page-bg: #f4f6fb;
    --set-surface: #fff;
    --set-surface-2: #f7f9fc;
    --set-border: #e4e8f0;
    --set-text: #26324a;
    --set-text-muted: #7c879c;
    --set-tint: color-mix(in srgb, var(--set-accent) 10%, transparent);
    --set-ring: color-mix(in srgb, var(--set-accent) 20%, transparent);
    --set-radius: 16px;
}

body.dark-only .settings-page {
    --set-page-bg: transparent;
    --set-surface: #14213f;
    --set-surface-2: #1a2848;
    --set-border: #26365c;
    --set-text: #dbe4f5;
    --set-text-muted: #8ea0c4;
    --set-tint: color-mix(in srgb, var(--set-accent) 22%, transparent);
    --set-ring: color-mix(in srgb, var(--set-accent) 32%, transparent);
}

/* ===========================================================================
   2. Page + card shell
   ======================================================================== */
.settings-page {
    color: var(--set-text);
    /* Room under the last control so it clears the sticky action bar and, on
       phones, the bottom nav. */
    padding-bottom: 2rem;
}

.settings-shell {
    max-width: 1180px;
    margin-inline: auto;
    background: var(--set-surface);
    border: 1px solid var(--set-border);
    border-radius: var(--set-radius);
    box-shadow: 0 1px 2px rgba(15,23,42,.04), 0 10px 30px rgba(15,23,42,.06);
    overflow: clip; /* corner clipping only — `clip` never creates a scrollport */
}

/* ---- Hero header --------------------------------------------------------- */
.settings-hero {
    display: flex;
    align-items: center;
    gap: .9rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--set-border);
    background: linear-gradient(120deg, var(--set-tint) 0%, transparent 55%), var(--set-surface);
}

.settings-hero__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    border-radius: 12px;
    background: var(--set-accent);
    color: #fff;
    font-size: 1.15rem;
    box-shadow: 0 6px 16px color-mix(in srgb, var(--set-accent) 35%, transparent);
}

.settings-hero__title {
    margin: 0;
    font-size: 1.02rem;
    font-weight: 700;
    line-height: 1.25;
    color: var(--set-text);
}

.settings-hero__sub {
    margin: .1rem 0 0;
    font-size: .78rem;
    color: var(--set-text-muted);
}

/* ---- Two-column body ----------------------------------------------------- */
.settings-layout {
    display: flex;
    flex-direction: column;
}

@media (min-width: 768px) {
    .settings-layout {
        flex-direction: row;
        align-items: flex-start;
    }
}

/* ===========================================================================
   3. Tab rail
   ======================================================================== */
.settings-sidebar {
    background: var(--set-surface-2);
    border-bottom: 1px solid var(--set-border);
    flex-shrink: 0;
}

@media (min-width: 768px) {
    .settings-sidebar {
        width: 248px;
        border-bottom: 0;
        border-right: 1px solid var(--set-border);
        /* Sticks alongside the form while the document scrolls — no inner
           scrollport, so nothing here can clip. */
        position: sticky;
        top: 0;
        align-self: stretch;
    }
}

.settings-tabs {
    display: flex;
    flex-direction: row;
    gap: .4rem;
    padding: .6rem;
    overflow-x: auto;
    scrollbar-width: none;
}

.settings-tabs::-webkit-scrollbar {
    display: none;
}

@media (min-width: 768px) {
    .settings-tabs {
        flex-direction: column;
        overflow-x: visible;
        padding: .75rem;
    }
}

.settings-tab {
    display: flex;
    align-items: center;
    gap: .6rem;
    flex: 0 0 auto;
    width: auto;
    padding: .6rem .85rem;
    border: 1px solid transparent;
    border-radius: 11px;
    background: transparent;
    color: var(--set-text);
    font-size: .84rem;
    font-weight: 500;
    text-align: left;
    white-space: nowrap;
    transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}

@media (min-width: 768px) {
    .settings-tab {
        width: 100%;
        white-space: normal;
    }
}

.settings-tab i {
    font-size: 1rem;
    opacity: .75;
}

.settings-tab:hover:not(.is-active) {
    background: var(--set-surface);
    border-color: var(--set-border);
}

.settings-tab.is-active {
    background: var(--set-accent);
    border-color: var(--set-accent);
    color: #fff;
    font-weight: 600;
    box-shadow: 0 4px 12px color-mix(in srgb, var(--set-accent) 32%, transparent);
}

.settings-tab.is-active i {
    opacity: 1;
}

.settings-tab:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--set-ring);
}

/* ===========================================================================
   4. Content panes
   ======================================================================== */
.settings-content {
    flex: 1 1 auto;
    min-width: 0;
    background: var(--set-surface);
}

.settings-pane {
    padding: 1.25rem;
}

@media (min-width: 768px) {
    .settings-pane {
        padding: 1.75rem 2rem;
    }
}

/* Grouped block of related fields */
.settings-section + .settings-section {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--set-border);
}

.settings-section__title {
    margin: 0 0 .9rem;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--set-text-muted);
}

.settings-page .form-label {
    font-size: .74rem;
    font-weight: 600;
    color: var(--set-text-muted);
    margin-bottom: .3rem;
}

/* A soft panel used for the provider-specific block on the WhatsApp tab */
.settings-subcard {
    padding: 1.1rem;
    border: 1px solid var(--set-border);
    border-radius: 12px;
    background: var(--set-surface-2);
}

/* ===========================================================================
   5. Inputs
   ======================================================================== */
.settings-input,
.settings-page .form-select {
    padding: .5rem .75rem;
    color: var(--set-text);
    background-color: var(--set-surface-2);
    border: 1px solid var(--set-border);
    border-radius: 10px;
    box-shadow: none;
    font-size: .86rem;
}

.settings-input:focus,
.settings-page .form-select:focus {
    color: var(--set-text);
    background-color: var(--set-surface);
    border-color: var(--set-accent);
    box-shadow: 0 0 0 3px var(--set-ring);
}

/* Explicit, and !important, so it outranks the app-wide input::placeholder rule
   in CustomUI.css rather than depending on stylesheet order. */
.settings-input::placeholder {
    color: #9aa7bd !important;
    opacity: 1 !important;
}

body.dark-only .settings-input::placeholder {
    color: #74839e !important;
}

.settings-page .input-group > .settings-input:not(:first-child),
.settings-page .input-group > .form-select:not(:first-child) {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.settings-page .input-group-text {
    background: var(--set-surface-2);
    border: 1px solid var(--set-border);
    border-right: 0;
    border-radius: 10px 0 0 10px;
    color: var(--set-text-muted);
}

.settings-page .form-check-input:checked {
    background-color: var(--set-accent);
    border-color: var(--set-accent);
}

.settings-page .form-check-input:focus {
    border-color: var(--set-accent);
    box-shadow: 0 0 0 3px var(--set-ring);
}

.settings-page .form-check-label {
    font-size: .82rem;
    color: var(--set-text);
}

.cursor-pointer {
    cursor: pointer;
}

/* ===========================================================================
   6. Action bar — sticks to the bottom of the viewport while the page scrolls
   ======================================================================== */
.settings-actions {
    position: sticky;
    bottom: 0;
    z-index: 3;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: .5rem;
    padding: .75rem 1.25rem;
    border-top: 1px solid var(--set-border);
    background: color-mix(in srgb, var(--set-surface) 88%, transparent);
    backdrop-filter: blur(8px);
}

@media (min-width: 768px) {
    .settings-actions {
        padding: .8rem 2rem;
    }
}

.settings-actions .btn {
    min-height: 38px;
    padding-inline: 1.35rem;
    border-radius: 999px;
    font-size: .84rem;
    font-weight: 600;
    transition: transform .12s ease, box-shadow .15s ease, background-color .15s ease;
}

.settings-actions .btn:active:not(:disabled) {
    transform: translateY(1px);
}

.settings-actions .btn-primary {
    background: var(--set-accent);
    border-color: var(--set-accent);
    box-shadow: 0 4px 14px color-mix(in srgb, var(--set-accent) 32%, transparent);
}

.settings-actions .btn-primary:hover:not(:disabled) {
    background: color-mix(in srgb, var(--set-accent) 88%, #000);
    border-color: color-mix(in srgb, var(--set-accent) 88%, #000);
}

/* ===========================================================================
   7. Misc
   ======================================================================== */
.animate-fade-in {
    animation: settings-fade-in .18s ease both;
}

@keyframes settings-fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
}

.settings-page .alert {
    border-radius: 12px;
    font-size: .84rem;
}

/* ===========================================================================
   8. Phone
   ======================================================================== */
@media (max-width: 767.98px) {
    .settings-page {
        padding-left: .5rem !important;
        padding-right: .5rem !important;
    }

    .settings-shell {
        border-radius: 12px;
    }

    .settings-hero {
        padding: .85rem 1rem;
    }

    /* Native-app tap targets */
    .settings-tab {
        min-height: 44px;
    }

    .settings-input,
    .settings-page .form-select {
        min-height: 44px;
        font-size: .95rem;
    }

    .settings-actions {
        padding: .7rem 1rem;
    }

    .settings-actions .btn {
        flex: 1 1 100%;
        min-height: 44px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .animate-fade-in {
        animation: none;
    }

    .settings-tab,
    .settings-actions .btn {
        transition: none;
    }
}
