/* =====================================================================
   Social AI Manager - base styles and application shell.
   Loaded after Bootstrap. Component library lives in components.css.
   ===================================================================== */

/* ---------------------------------------------------------------------
   1. Base
   --------------------------------------------------------------------- */
*,
*::before,
*::after { box-sizing: border-box; }

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100dvh;
    background: var(--app-bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: none;
}

h1, h2, h3, h4, h5, h6 {
    margin: 0;
    color: var(--text);
    font-weight: var(--weight-semibold);
    line-height: var(--leading-tight);
    letter-spacing: -0.011em;
    /* Headings carry customer content - a topic, a company name, sometimes a URL. One
       unbreakable word must wrap rather than widen the document and scroll the whole page. */
    overflow-wrap: anywhere;
}

p { margin: 0 0 var(--space-3); }
p:last-child { margin-bottom: 0; }

a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--duration-fast) var(--ease);
}
a:hover { color: var(--accent-600); text-decoration: underline; }

/* One visible focus treatment everywhere, so keyboard users are never lost. */
:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}
:focus:not(:focus-visible) { outline: none; }

.u-visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* Skip link: first thing in the tab order on every page. */
.skip-link {
    position: absolute;
    top: -200px;
    left: var(--space-4);
    z-index: var(--z-toast);
    padding: var(--space-3) var(--space-4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-button);
    box-shadow: var(--shadow-lg);
    font-weight: var(--weight-semibold);
}
.skip-link:focus { top: var(--space-4); }

/* ---------------------------------------------------------------------
   2. Application shell
   --------------------------------------------------------------------- */
.app-shell {
    display: flex;
    min-height: 100dvh;
}

/* -- Desktop sidebar -------------------------------------------------- */
.app-sidebar {
    display: none;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: var(--z-sidebar);
    width: var(--sidebar-width);
    flex-direction: column;
    padding: var(--space-4) var(--space-3);
    background: var(--surface);
    border-right: 1px solid var(--border);
}

.app-sidebar__brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3) var(--space-5);
    color: var(--text);
    font-weight: var(--weight-semibold);
    font-size: var(--text-md);
    letter-spacing: -0.015em;
}
.app-sidebar__brand:hover { color: var(--text); text-decoration: none; }

.brand-mark {
    display: grid;
    place-items: center;
    flex: 0 0 32px;
    width: 32px; height: 32px;
    background: var(--gradient-accent);
    border-radius: 9px;
    box-shadow: var(--shadow-accent);
    color: #fff;
}
.brand-mark svg { width: 18px; height: 18px; }
.brand-mark--lg { width: 44px; height: 44px; flex-basis: 44px; border-radius: 13px; }
.brand-mark--lg svg { width: 24px; height: 24px; }

.app-sidebar__scroll {
    flex: 1;
    overflow-y: auto;
    margin: 0 calc(var(--space-3) * -1);
    padding: 0 var(--space-3);
}

.app-sidebar__section-label {
    padding: var(--space-4) var(--space-3) var(--space-2);
    color: var(--text-subtle);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.app-sidebar__footer {
    padding-top: var(--space-3);
    border-top: 1px solid var(--border);
}

.nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: var(--tap-target);
    padding: var(--space-2) var(--space-3);
    margin-bottom: 2px;
    border-radius: var(--radius-button);
    color: var(--text-secondary);
    font-size: var(--text-base);
    font-weight: var(--weight-medium);
    transition: background var(--duration-fast) var(--ease),
                color var(--duration-fast) var(--ease);
}
.nav-item:hover {
    background: var(--surface-sunken);
    color: var(--text);
    text-decoration: none;
}
.nav-item__icon {
    flex: 0 0 20px;
    width: 20px; height: 20px;
    color: var(--text-muted);
    transition: color var(--duration-fast) var(--ease);
}
.nav-item:hover .nav-item__icon { color: var(--text-secondary); }

.nav-item.is-active {
    background: var(--gradient-accent-soft);
    color: var(--accent-700);
    font-weight: var(--weight-semibold);
}
.nav-item.is-active .nav-item__icon { color: var(--accent); }

.nav-item__badge {
    margin-left: auto;
    min-width: 20px;
    padding: 0 6px;
    border-radius: var(--radius-pill);
    background: var(--accent);
    color: #fff;
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    line-height: 20px;
    text-align: center;
}
.nav-item__badge--muted { background: var(--surface-sunken); color: var(--text-muted); }

.nav-user {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: var(--tap-target);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-button);
    color: var(--text);
    transition: background var(--duration-fast) var(--ease);
}
.nav-user:hover { background: var(--surface-sunken); color: var(--text); text-decoration: none; }
.nav-user__meta { min-width: 0; }
.nav-user__name {
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.nav-user__sub {
    font-size: var(--text-xs);
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.avatar {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 32px; height: 32px;
    border-radius: var(--radius-pill);
    background: var(--accent-100);
    color: var(--accent-700);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar--lg { width: 44px; height: 44px; font-size: var(--text-md); }
.avatar--sm { width: 26px; height: 26px; font-size: var(--text-xs); }

/* -- Main column ------------------------------------------------------ */
.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    position: sticky;
    top: 0;
    z-index: var(--z-topbar);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 0 var(--space-2) 0 var(--space-3);
    padding-top: env(safe-area-inset-top);
    height: calc(var(--topbar-height) + env(safe-area-inset-top));
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border);
}
.app-topbar__title {
    min-width: 0;
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.app-topbar__spacer { flex: 1; }

.icon-button {
    position: relative;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: var(--tap-target);
    height: var(--tap-target);
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: var(--radius-button);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--duration-fast) var(--ease),
                color var(--duration-fast) var(--ease),
                transform var(--duration-fast) var(--ease);
}
.icon-button:hover { background: var(--surface-sunken); color: var(--text); text-decoration: none; }
.icon-button:active { transform: scale(0.94); }
.icon-button svg { width: 20px; height: 20px; }

/* Unread marker. Paired with visually-hidden text so it is not colour-only. */
.icon-button__dot {
    position: absolute;
    top: 9px; right: 10px;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--surface);
}

.app-content {
    flex: 1;
    width: 100%;
    max-width: var(--content-max);
    margin: 0 auto;
    padding: var(--space-4) var(--space-4) var(--space-8);
    /* Room for the bottom navigation and the iOS home indicator. */
    padding-bottom: calc(var(--bottomnav-height) + env(safe-area-inset-bottom) + var(--space-8));
}
.app-content--wide { max-width: 1440px; }

/* -- Mobile bottom navigation ----------------------------------------- */
.bottom-nav {
    position: fixed;
    inset: auto 0 0 0;
    z-index: var(--z-bottomnav);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: stretch;
    height: calc(var(--bottomnav-height) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: saturate(180%) blur(14px);
    border-top: 1px solid var(--border);
}

.bottom-nav__item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: var(--tap-target);
    padding: var(--space-1);
    border: 0;
    background: transparent;
    color: var(--text-muted);
    font-size: 10.5px;
    font-weight: var(--weight-medium);
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: color var(--duration-fast) var(--ease);
}
.bottom-nav__item:hover { color: var(--text-secondary); text-decoration: none; }
.bottom-nav__item svg { width: 22px; height: 22px; }
.bottom-nav__item.is-active { color: var(--accent); font-weight: var(--weight-semibold); }

/* The active tab is marked by a rule as well as by colour. */
.bottom-nav__item.is-active::before {
    content: "";
    position: absolute;
    top: 0;
    width: 26px;
    height: 3px;
    border-radius: 0 0 3px 3px;
    background: var(--gradient-accent);
}

/* The emphasised Create action. */
.bottom-nav__create {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border: 0;
    background: transparent;
    color: var(--accent);
    font-size: 10.5px;
    font-weight: var(--weight-semibold);
    cursor: pointer;
}
.bottom-nav__create:hover { text-decoration: none; color: var(--accent); }
.bottom-nav__create-disc {
    display: grid;
    place-items: center;
    width: 38px; height: 38px;
    margin-top: -14px;
    border-radius: 13px;
    background: var(--gradient-accent);
    box-shadow: var(--shadow-accent);
    color: #fff;
    transition: transform var(--duration-fast) var(--ease);
}
.bottom-nav__create:active .bottom-nav__create-disc { transform: scale(0.92); }
.bottom-nav__create-disc svg { width: 20px; height: 20px; }

/* -- Floating AI action ------------------------------------------------ */
/* Sits clear of the bottom navigation rather than over it. */
.ai-fab {
    position: fixed;
    right: var(--space-4);
    bottom: calc(var(--bottomnav-height) + env(safe-area-inset-bottom) + var(--space-4));
    z-index: var(--z-fab);
    display: grid;
    place-items: center;
    width: 52px; height: 52px;
    border: 0;
    border-radius: 17px;
    background: var(--gradient-ai);
    box-shadow: var(--shadow-lg);
    color: #fff;
    cursor: pointer;
    transition: transform var(--duration-base) var(--ease-out);
}
.ai-fab:active { transform: scale(0.92); }
.ai-fab svg { width: 24px; height: 24px; }

/* -- Responsive shell -------------------------------------------------- */
@media (min-width: 768px) {
    .app-content { padding: var(--space-6) var(--space-6) var(--space-10); }
    .app-topbar { padding-left: var(--space-5); padding-right: var(--space-4); }
}

/* Tablet: a compact icon rail instead of the full sidebar. */
@media (min-width: 1024px) {
    .app-sidebar {
        display: flex;
        width: var(--sidebar-width-compact);
        padding-left: var(--space-2);
        padding-right: var(--space-2);
    }
    .app-sidebar .nav-item__label,
    .app-sidebar__section-label,
    .app-sidebar__brand span,
    .nav-user__meta { display: none; }
    .app-sidebar .nav-item,
    .app-sidebar .nav-user { justify-content: center; padding-left: 0; padding-right: 0; }
    .app-sidebar .nav-item__badge { position: absolute; top: 4px; right: 12px; margin-left: 0; }
    .app-sidebar__brand { justify-content: center; padding-left: 0; padding-right: 0; }

    .app-main { margin-left: var(--sidebar-width-compact); }
    .bottom-nav, .ai-fab { display: none; }
    .app-content { padding-bottom: var(--space-10); }
    .u-mobile-only { display: none !important; }
}

@media (min-width: 1280px) {
    .app-sidebar {
        width: var(--sidebar-width);
        padding-left: var(--space-3);
        padding-right: var(--space-3);
    }
    .app-sidebar .nav-item__label,
    .app-sidebar__section-label,
    .app-sidebar__brand span,
    .nav-user__meta { display: block; }
    .app-sidebar .nav-item,
    .app-sidebar .nav-user {
        justify-content: flex-start;
        padding-left: var(--space-3);
        padding-right: var(--space-3);
    }
    .app-sidebar .nav-item__badge { position: static; margin-left: auto; }
    .app-sidebar__brand { justify-content: flex-start; padding-left: var(--space-3); }
    .app-main { margin-left: var(--sidebar-width); }
}

@media (max-width: 1023.98px) {
    .u-desktop-only { display: none !important; }
}

/* ---------------------------------------------------------------------
   3. Auth shell (login / register - no navigation)
   --------------------------------------------------------------------- */
.auth-shell {
    display: grid;
    grid-template-columns: 1fr;
    min-height: 100dvh;
    background: var(--surface);
}

.auth-aside {
    display: none;
    position: relative;
    flex-direction: column;
    justify-content: space-between;
    padding: var(--space-12);
    background: var(--gradient-ai);
    color: #fff;
    overflow: hidden;
}
/* One soft light source, not a glow effect. */
.auth-aside::after {
    content: "";
    position: absolute;
    inset: -40% -30% auto auto;
    width: 620px; height: 620px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255,255,255,0.16) 0%, rgba(255,255,255,0) 68%);
    pointer-events: none;
}
.auth-aside > * { position: relative; z-index: 1; }
.auth-aside__brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    color: #fff;
    font-weight: var(--weight-semibold);
}
.auth-aside__brand:hover { color: #fff; text-decoration: none; }
.auth-aside__brand .brand-mark {
    background: rgba(255, 255, 255, 0.18);
    box-shadow: none;
    backdrop-filter: blur(4px);
}
.auth-aside__headline {
    font-size: var(--text-3xl);
    font-weight: var(--weight-bold);
    letter-spacing: -0.025em;
    color: #fff;
}
.auth-aside__verbs {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-5);
    padding: 0;
    list-style: none;
}
.auth-aside__verbs li {
    padding: var(--space-1) var(--space-3);
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: var(--radius-pill);
    background: rgba(255, 255, 255, 0.10);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
}
.auth-aside__foot {
    font-size: var(--text-sm);
    color: rgba(255, 255, 255, 0.72);
}

.auth-panel {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: var(--space-6) var(--space-5) var(--space-10);
    padding-top: calc(var(--space-6) + env(safe-area-inset-top));
}
.auth-panel__inner {
    width: 100%;
    max-width: 380px;
    margin: 0 auto;
}
/* Mobile keeps a compact brand lockup instead of half a screen of illustration. */
.auth-panel__mobile-brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-8);
}

@media (min-width: 1024px) {
    .auth-shell { grid-template-columns: 1.05fr 1fr; }
    .auth-aside { display: flex; }
    .auth-panel { padding: var(--space-12); }
    .auth-panel__mobile-brand { display: none; }
}

/* ---------------------------------------------------------------------
   4. Shell refinements
   --------------------------------------------------------------------- */
/* On desktop the sidebar carries identity and alerts, and each page carries
   its own PageHeader, so the top bar would only repeat them. */
@media (min-width: 1024px) {
    .app-topbar { display: none; }
    .flash-stack { top: var(--space-4); }
}

/* Install banner. Hidden until the browser tells us an install is possible. */
.install-banner {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
    padding: var(--space-3) var(--space-4);
    background: var(--surface);
    border: 1px solid var(--accent-200);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-sm);
}
.install-banner__text { flex: 1; min-width: 0; font-size: var(--text-sm); }
.install-banner__title { font-weight: var(--weight-semibold); font-size: var(--text-base); }
.is-standalone .install-banner { display: none !important; }

/* Full-screen AI progress. Covers a real server round trip, not a fake wait. */
.ai-overlay {
    position: fixed;
    inset: 0;
    z-index: var(--z-toast);
    display: grid;
    place-items: center;
    padding: var(--space-6);
    background: rgba(245, 246, 250, 0.94);
    backdrop-filter: blur(6px);
}
.ai-overlay[hidden] { display: none; }
.ai-overlay__card {
    width: 100%;
    max-width: 380px;
    padding: var(--space-6);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}
.ai-overlay__spark {
    display: grid;
    place-items: center;
    width: 44px; height: 44px;
    margin-bottom: var(--space-4);
    border-radius: 14px;
    background: var(--gradient-ai);
    color: #fff;
    animation: breathe 2.4s var(--ease) infinite;
}
.ai-overlay__spark svg { width: 22px; height: 22px; }
.ai-overlay__title {
    margin-bottom: var(--space-1);
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
}
.ai-overlay__sub { margin-bottom: var(--space-5); color: var(--text-muted); font-size: var(--text-sm); }

@keyframes breathe {
    0%, 100% { transform: scale(1); box-shadow: var(--shadow-accent); }
    50% { transform: scale(1.06); box-shadow: 0 6px 22px rgba(79, 70, 229, 0.34); }
}
