/* ==========================================================================
   Liberum QA — Main stylesheet
   Palette, typography, navbar, buttons, flash, footer, badges
   ========================================================================== */

:root {
    /* Brand */
    --c-liberum-red: #C41E3A;
    --c-liberum-red-dark: #9B1830;
    --c-liberum-red-light: #E8435A;
    --c-liberum-red-10: rgba(196, 30, 58, 0.10);
    --c-liberum-red-15: rgba(196, 30, 58, 0.15);

    /* Neutrals — light mode */
    --c-text: #1F2937;
    --c-text-2: #4B5563;
    --c-text-muted: #6B7280;
    --c-text-subtle: #9CA3AF;

    --c-bg: #F5F5F5;
    --c-surface: #FFFFFF;
    --c-inset: #F3F4F6;
    --c-hover: #F9FAFB;

    --c-border: #E5E7EB;
    --c-border-strong: #D1D5DB;

    --c-dark: #111827;
    --c-dark-2: #1F2937;

    /* Status / ratings */
    --c-green: #10B981;
    --c-green-bg: #D1FAE5;
    --c-green-text: #065F46;
    --c-yellow: #F59E0B;
    --c-yellow-bg: #FEF3C7;
    --c-yellow-text: #92400E;
    --c-red: #EF4444;
    --c-red-bg: #FEE2E2;
    --c-red-text: #991B1B;
    --c-gray: #9CA3AF;
    --c-gray-bg: #E5E7EB;
    --c-gray-text: #4B5563;
    --c-blue: #3B82F6;
    --c-blue-bg: #DBEAFE;
    --c-blue-text: #1E40AF;

    /* Radii */
    --radius-sm: 0.25rem;
    --radius-md: 0.375rem;
    --radius-lg: 0.5rem;
    --radius-xl: 0.75rem;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05), 0 1px 1px rgba(0,0,0,0.02);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);

    /* Motion */
    --t-fast: 150ms ease;
    --t-base: 200ms ease;

    /* Type */
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

    /* Layout */
    --nav-h: 64px;
    --max-w: 1280px;
}

/* Reset / base */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font-sans);
    font-size: 16px;
    color: var(--c-text);
    background: var(--c-bg);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body.app-body { background: var(--c-bg); }

h1, h2, h3, h4, h5 {
    margin: 0 0 0.5em;
    color: var(--c-text);
    line-height: 1.25;
    font-weight: 700;
    letter-spacing: -0.015em;
}
h1 { font-size: 1.875rem; font-weight: 700; }
h2 { font-size: 1.5rem; font-weight: 700; }
h3 { font-size: 1.125rem; font-weight: 600; }
h4 { font-size: 0.95rem; font-weight: 600; color: var(--c-text-2); }

p { margin: 0 0 1em; }
.lede { font-size: 1.125rem; color: var(--c-text-2); line-height: 1.6; }
.muted { color: var(--c-text-muted); }
.subtle { color: var(--c-text-subtle); }
.small { font-size: 0.8125rem; }
.tiny { font-size: 0.75rem; }
.center { text-align: center; }
.warn { color: var(--c-yellow-text); }
.danger { color: var(--c-red-text); }

a { color: var(--c-liberum-red); text-decoration: none; transition: color var(--t-fast); }
a:hover { color: var(--c-liberum-red-dark); text-decoration: underline; }

img { max-width: 100%; height: auto; display: block; }

/* Container */
.container {
    max-width: var(--max-w);
    margin: 0 auto;
    padding: 0 1.5rem;
}
.container.narrow { max-width: 860px; }
.container.wide { max-width: 1440px; }

/* Sections */
.section { padding: 4rem 0; }
.section.band { background: var(--c-surface); border-top: 1px solid var(--c-border); border-bottom: 1px solid var(--c-border); }
.section.dark {
    background: linear-gradient(135deg, var(--c-dark) 0%, var(--c-dark-2) 100%);
    color: #F3F4F6;
}
.section.dark h1, .section.dark h2, .section.dark h3, .section.dark .lede { color: #F3F4F6; }
.section.dark .muted { color: #9CA3AF; }

.site-main { min-height: 60vh; }

/* ===== Top navigation ===== */
.site-nav {
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
    box-shadow: var(--shadow-xs);
    position: sticky;
    top: 0;
    z-index: 50;
}
.nav-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--nav-h);
    padding: 0 1.5rem;
    max-width: var(--max-w);
    margin: 0 auto;
}
.brand {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    color: var(--c-liberum-red);
    font-weight: 700;
    font-size: 1.125rem;
    letter-spacing: -0.01em;
    text-decoration: none;
}
.brand:hover { color: var(--c-liberum-red-dark); text-decoration: none; }
.brand-logo { height: 36px; width: auto; border-radius: 4px; flex-shrink: 0; }
.brand-wordmark { display: inline-flex; flex-direction: column; line-height: 1.1; }
.brand-text { font-size: 1.125rem; font-weight: 700; letter-spacing: -0.01em; color: var(--c-liberum-red); }
.brand-tagline {
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--c-text-muted);
    margin-top: 2px;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}
.nav-links a {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 0.875rem;
    color: var(--c-text-2);
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    transition: background var(--t-fast), color var(--t-fast);
}
.nav-links a:hover {
    background: var(--c-inset);
    color: var(--c-text);
    text-decoration: none;
}
.nav-links a.active {
    background: var(--c-liberum-red);
    color: #fff;
}
.nav-links .btn { margin-left: 0.5rem; }
.nav-links a.btn-primary,
.nav-links a.btn-primary:hover {
    background: var(--c-liberum-red);
    border-color: var(--c-liberum-red);
    color: #fff;
}
.nav-links a.btn-primary:hover {
    background: var(--c-liberum-red-dark);
    border-color: var(--c-liberum-red-dark);
}

.nav-user {
    display: inline-flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.375rem 0.75rem 0.375rem 0.375rem;
    background: transparent;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-full);
    color: var(--c-text-2);
    font-size: 0.85rem;
    font-weight: 500;
    transition: background var(--t-fast), border-color var(--t-fast);
    text-decoration: none;
}
.nav-user:hover { background: var(--c-inset); text-decoration: none; border-color: var(--c-border-strong); color: var(--c-text); }
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px; height: 28px;
    border-radius: var(--radius-full);
    background: var(--c-liberum-red);
    color: #fff;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    flex-shrink: 0;
}
.avatar.lg { width: 40px; height: 40px; font-size: 1rem; }

.nav-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px; height: 40px;
    background: transparent;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--c-text-2);
    padding: 0;
}
.nav-toggle svg { width: 22px; height: 22px; }
.nav-toggle:hover { background: var(--c-inset); }

/* Dropdown menu (user, admin sections) */
.dropdown { position: relative; }
.dropdown-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 0.375rem);
    min-width: 220px;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 0.375rem;
    display: none;
    z-index: 60;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a, .dropdown-menu button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.55rem 0.75rem;
    color: var(--c-text-2);
    font-size: 0.88rem;
    border-radius: var(--radius-md);
    background: transparent;
    border: none;
    cursor: pointer;
    text-align: left;
    text-decoration: none;
}
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--c-inset); color: var(--c-text); text-decoration: none; }
.dropdown-menu .divider { height: 1px; background: var(--c-border); margin: 0.25rem 0; }
.dropdown-menu .section-label { padding: 0.5rem 0.75rem 0.25rem; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--c-text-subtle); font-weight: 700; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.25;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--c-liberum-red-15);
}

.btn-primary {
    background: var(--c-liberum-red);
    color: #fff;
    border-color: var(--c-liberum-red);
}
.btn-primary:hover { background: var(--c-liberum-red-dark); border-color: var(--c-liberum-red-dark); color: #fff; }

.btn-ghost {
    background: var(--c-surface);
    color: var(--c-text);
    border-color: var(--c-border);
}
.btn-ghost:hover { background: var(--c-inset); border-color: var(--c-border-strong); color: var(--c-text); }

.btn-danger {
    background: var(--c-red);
    color: #fff;
    border-color: var(--c-red);
}
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; color: #fff; }

.btn-link {
    background: transparent;
    color: var(--c-liberum-red);
    padding: 0.25rem 0;
    border: none;
}
.btn-link:hover { color: var(--c-liberum-red-dark); text-decoration: underline; }

.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }
.btn-sm, .btn-small { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-block { display: flex; width: 100%; }

.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ===== Flash messages ===== */
/* ===== Emulation banner (super admin "view as" mode) ===== */
.emulate-banner {
    position: sticky;
    top: var(--nav-h);
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.55rem 1.25rem;
    background: #FEF3C7;
    border-bottom: 1px solid #F59E0B;
    color: #78350F;
    font-size: 0.85rem;
}
.emulate-banner strong { color: #78350F; }
.emulate-banner-stop {
    background: #78350F;
    color: #fff;
    border: none;
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-md);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
}
.emulate-banner-stop:hover { background: #5a270c; }

/* ===== Toast notifications ===== */
.toast-stack {
    position: fixed;
    top: calc(var(--nav-h) + 1rem);
    right: 1.25rem;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    pointer-events: none;
    max-width: min(420px, calc(100vw - 2rem));
}
.toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.8rem 1rem;
    border-radius: var(--radius-md);
    border-left: 4px solid;
    background: var(--c-surface);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.06);
    font-size: 0.9rem;
    line-height: 1.45;
    animation: toast-in 220ms ease-out;
}
.toast.toast-leaving {
    animation: toast-out 220ms ease-in forwards;
}
.toast-msg { flex: 1; }
.toast-close {
    background: none;
    border: none;
    color: inherit;
    opacity: 0.6;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    margin-top: -0.1rem;
}
.toast-close:hover { opacity: 1; }
.toast-success { border-color: var(--c-green); background: var(--c-green-bg); color: var(--c-green-text); }
.toast-error   { border-color: var(--c-red); background: var(--c-red-bg); color: var(--c-red-text); }
.toast-info    { border-color: var(--c-blue); background: var(--c-blue-bg); color: var(--c-blue-text); }
.toast-warning { border-color: var(--c-yellow); background: var(--c-yellow-bg); color: var(--c-yellow-text); }

@keyframes toast-in {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes toast-out {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(20px); }
}
@media (max-width: 640px) {
    .toast-stack { left: 0.75rem; right: 0.75rem; max-width: none; }
}

/* ===== Footer ===== */
.site-footer {
    background: var(--c-dark);
    color: #9CA3AF;
    padding: 3rem 0 2rem;
    margin-top: 4rem;
    font-size: 0.88rem;
}
.site-footer strong { color: #fff; display: block; margin-bottom: 0.25rem; font-size: 1rem; }
.site-footer a {
    color: #D1D5DB;
    display: block;
    margin-bottom: 0.5rem;
}
.site-footer a:hover { color: var(--c-liberum-red-light); text-decoration: none; }
.footer-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 2fr;
    gap: 2.5rem;
    align-items: start;
}
.footer-grid .muted { color: #6B7280; }

/* ===== Status badges ===== */
.status-badge, .badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.45rem;
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-radius: 3px;
    border: 1px solid transparent;
    white-space: nowrap;
    line-height: 1.5;
}
/* Colors mirror the PDF Badge flowable palette in app/services/report_pdf.py */
.status-green, .status-active, .status-completed,
.status-ready, .status-go, .status-low, .status-mitigated,
.status-finalized, .status-closed, .status-champion, .status-supportive {
    background: #10B981; color: #fff; border-color: #10B981;
}
.status-yellow, .status-in_progress, .status-intake, .status-on_hold,
.status-mitigating, .status-conditional, .status-acknowledged,
.status-at_risk, .status-in_review, .status-revision_requested,
.status-medium, .status-open, .status-resistant {
    background: #F59E0B; color: #fff; border-color: #F59E0B;
}
.status-red, .status-not_ready, .status-no_go,
.status-high, .status-delayed, .status-no_action, .status-blocking {
    background: #C41E3A; color: #fff; border-color: #C41E3A;
}
.status-critical, .status-cancelled, .status-escalated {
    background: #8A1226; color: #fff; border-color: #8A1226;
}
.status-gray, .status-not_started, .status-pending, .status-deferred,
.status-paused, .status-accepted, .status-informational, .status-neutral,
.status-na {
    background: #6B7280; color: #fff; border-color: #6B7280;
}
.status-blue, .status-draft, .status-approved, .status-published,
.status-action, .status-draft_in_progress, .status-draft_delivered {
    background: #1D4ED8; color: #fff; border-color: #1D4ED8;
}

/* Utility */
.hidden { display: none !important; }
.flex { display: flex; }
.gap-2 { gap: 0.5rem; }
.gap-4 { gap: 1rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mt-8 { margin-top: 2rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-8 { margin-bottom: 2rem; }

/* ===== Responsive ===== */
@media (max-width: 960px) {
    h1 { font-size: 1.625rem; }
    h2 { font-size: 1.3rem; }
    .section { padding: 2.75rem 0; }

    .nav-toggle { display: inline-flex; }
    .nav-links {
        display: none;
        position: absolute;
        top: var(--nav-h);
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        background: var(--c-surface);
        border-bottom: 1px solid var(--c-border);
        padding: 0.75rem 1rem 1rem;
        gap: 0.125rem;
        box-shadow: var(--shadow-md);
    }
    .nav-links.open { display: flex; }
    .nav-links a {
        width: 100%;
        padding: 0.75rem 0.875rem;
        font-size: 0.95rem;
        border-radius: var(--radius-md);
    }
    .nav-links .btn { margin: 0.375rem 0 0; width: 100%; }
    .nav-user { width: 100%; justify-content: flex-start; margin-top: 0.375rem; }
    .dropdown-menu { position: static; box-shadow: none; border: none; padding: 0; width: 100%; }
    .dropdown-menu .section-label { padding-top: 0.75rem; }

    .footer-grid { grid-template-columns: 1fr; gap: 1.5rem; }
}

@media (max-width: 520px) {
    .container { padding: 0 1rem; }
    .btn-lg { padding: 0.625rem 1.125rem; font-size: 0.95rem; }
    .nav-inner { padding: 0 1rem; }
}
