/* =============================================================================
 * FILE: public/assets/css/theme.css
 * P3A design system v2 — loaded AFTER styles.css, so it refines rather than
 * replaces it. One brand, one type scale, one set of components:
 *   1. Typography   Inter (variable), tabular figures for numbers
 *   2. Brand colour Bootstrap's primary/link/info re-pointed at the org
 *                   palette, so every text-primary, badge, link and button
 *                   follows the brand instead of default Bootstrap blue/green
 *   3. Shell        top bar, user menu, sidebar brand + environment badge
 *   4. Components   section headings, single-line scrollable tab bars, metric
 *                   cards with icon chips, quieter table actions, empty states
 * Pure CSS: no layout animation, works in light and dark themes.
 * ========================================================================== */

/* --- 1. Typography --------------------------------------------------------- */
:root {
    --p3a-font: "Inter Variable", "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --bs-body-font-family: var(--p3a-font);
    --bs-body-font-size: .9375rem;   /* 15px — denser, more "application" than 16px */
}
body {
    font-family: var(--p3a-font);
    font-feature-settings: "cv05", "cv11";   /* Inter: single-storey l, open digits */
    line-height: 1.5;
}
h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 { font-weight: 600; letter-spacing: -.015em; }
.fw-semibold { font-weight: 600 !important; }
/* Figures line up in columns and cards. */
.metric-value, .table td, .table th, .badge, .cal-day, .stage-pill { font-variant-numeric: tabular-nums; }

/* --- 2. Brand colour -------------------------------------------------------- */
/* Primary = the brand teal (the darker, AA-contrast tone for fills and text). */
:root,
[data-bs-theme="light"] {
    --bs-primary: #1e7a78;
    --bs-primary-rgb: 30, 122, 120;
    --bs-primary-text-emphasis: #155654;
    --bs-primary-bg-subtle: #d6eeed;
    --bs-primary-border-subtle: #a6d6d4;
    --bs-link-color: #1e7a78;
    --bs-link-color-rgb: 30, 122, 120;
    --bs-link-hover-color: #155654;
    --bs-link-hover-color-rgb: 21, 86, 84;
    --bs-info: #3c6d79;
    --bs-info-rgb: 60, 109, 121;
}
[data-bs-theme="dark"] {
    --bs-primary: #32a3a1;
    --bs-primary-rgb: 50, 163, 161;
    --bs-primary-text-emphasis: #8fdcda;
    --bs-primary-bg-subtle: rgba(50, 163, 161, .16);
    --bs-primary-border-subtle: rgba(50, 163, 161, .45);
    --bs-link-color: #5ecfcd;
    --bs-link-color-rgb: 94, 207, 205;
    --bs-link-hover-color: #8fdcda;
    --bs-link-hover-color-rgb: 143, 220, 218;
    --bs-info: #4f8a98;
    --bs-info-rgb: 79, 138, 152;
}
/* Badges/backgrounds that Bootstrap pairs with black text become readable on
   the darker brand info tone. */
.text-bg-info { color: #fff !important; background-color: RGBA(var(--bs-info-rgb), var(--bs-bg-opacity, 1)) !important; }
.text-bg-primary { color: #fff !important; }

/* One accent for actions: "Add / Create / Save / Approve" no longer mix
   default Bootstrap green with brand teal. Green stays for status badges. */
.btn-success {
    --bs-btn-bg: #1e7a78;
    --bs-btn-border-color: #1e7a78;
    --bs-btn-hover-bg: #175f5d;
    --bs-btn-hover-border-color: #175f5d;
    --bs-btn-active-bg: #134f4d;
    --bs-btn-active-border-color: #134f4d;
    --bs-btn-disabled-bg: #1e7a78;
    --bs-btn-disabled-border-color: #1e7a78;
}
.btn-outline-primary,
.btn-outline-info {
    --bs-btn-color: var(--bs-primary);
    --bs-btn-border-color: var(--bs-primary-border-subtle);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--bs-primary);
    --bs-btn-hover-border-color: var(--bs-primary);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--bs-primary);
    --bs-btn-active-border-color: var(--bs-primary);
}
.btn-outline-secondary {
    --bs-btn-color: var(--bs-body-color);
    --bs-btn-border-color: var(--p3a-border);
    --bs-btn-hover-color: var(--bs-body-color);
    --bs-btn-hover-bg: var(--p3a-hover);
    --bs-btn-hover-border-color: var(--p3a-border);
    --bs-btn-active-color: var(--bs-body-color);
    --bs-btn-active-bg: var(--p3a-hover);
    --bs-btn-active-border-color: var(--p3a-border);
}
.btn { font-weight: 500; }
.btn-sm { --bs-btn-font-size: .8125rem; --bs-btn-padding-y: .3rem; --bs-btn-padding-x: .65rem; }

/* Links inside content: brand colour, underline only on hover. */
.view-root a:not(.btn):not(.nav-link):not(.badge):not(.metric-card):not(.dropdown-item):not(.list-group-item) {
    text-decoration: none;
}
.view-root a:not(.btn):not(.nav-link):not(.badge):not(.metric-card):not(.dropdown-item):not(.list-group-item):hover {
    text-decoration: underline;
    text-underline-offset: 2px;
}
.table td a:not(.btn) { font-weight: 500; }

/* --- 3. Shell --------------------------------------------------------------- */
.app-topbar {
    gap: .5rem;
    padding: 0 1.25rem;
}
.topbar-title {
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: -.01em;
}
.topbar-title .topbar-sub {
    color: var(--p3a-muted);
    font-weight: 500;
}
.topbar-title .topbar-sub::before {
    content: "/";
    margin: 0 .5rem;
    opacity: .5;
}
/* Ghost icon buttons in the top bar (sidebar toggle, theme, notifications). */
.app-topbar > .btn-outline-secondary,
.app-topbar > a.btn-outline-secondary {
    --bs-btn-border-color: transparent;
    --bs-btn-hover-border-color: transparent;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--p3a-muted);
}
.app-topbar > .btn-outline-secondary:hover,
.app-topbar > a.btn-outline-secondary:hover { color: var(--bs-body-color); }
.topbar-search .input-group-text {
    background: transparent;
    border-color: var(--p3a-border);
    border-right: 0;
    border-radius: 999px 0 0 999px;
    color: var(--p3a-muted);
}
.topbar-search .form-control { border-left: 0; background: transparent; }

/* User menu: avatar + name instead of a bordered button. */
.topbar-user .btn {
    --bs-btn-border-color: transparent;
    --bs-btn-hover-border-color: transparent;
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .2rem .5rem .2rem .25rem;
    border-radius: 999px;
}
.topbar-user .btn > .fa-user { display: none; }
.topbar-user .user-avatar {
    width: 1.9rem;
    height: 1.9rem;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .75rem;
    font-weight: 700;
    color: #fff;
    background: var(--p3a-brand-slate);
}
.topbar-user #user-menu-name { max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .875rem; }
@media (max-width: 991.98px) { .topbar-user #user-menu-name { display: none; } }
.dropdown-menu { border-color: var(--p3a-border); border-radius: var(--p3a-radius-sm); box-shadow: var(--p3a-shadow); font-size: .9rem; }
.dropdown-item { border-radius: .35rem; margin: 0 .25rem; width: auto; }

/* Sidebar brand: long organisation names wrap to two tidy lines, never three. */
.sidebar-brand {
    font-size: 1rem;
    line-height: 1.25;
    min-height: var(--p3a-topbar-h);
    padding: .65rem 1.15rem;
}
.sidebar-brand .brand-text {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.sidebar-section { font-size: .66rem; letter-spacing: .09em; }
.sidebar-nav a { font-size: .875rem; }
/* The environment badge is a warning for test copies; production shows none. */
.sidebar-footer { padding: .5rem 1rem 1rem; }
.sidebar-footer .badge.env-production { display: none; }

/* Login screen: the timeline accent follows the brand teal (was indigo). */
.pm-login {
    --pm-accent: #32a3a1;
    --pm-accent-hover: #1e7a78;
    --pm-accent-glow: rgba(50, 163, 161, .5);
}
.pm-login-formwrap .btn-primary { color: #fff; }
/* Signed-out screens (login, reset, 2FA) run edge to edge — no page padding. */
body.unauthed .view-root { padding: 0 !important; }

/* --- 4. Components ---------------------------------------------------------- */
/* Section headings inside a page ("My work", "Leave calendar", …). */
.view-root h2.h6.text-secondary,
.view-root h3.h6.text-secondary,
.view-root .h6.text-secondary {
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--p3a-muted) !important;
    margin-bottom: .6rem;
}

/* Tab bars stay on ONE line and scroll sideways instead of wrapping. */
.nav-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;      /* visible, so a cut-off last tab reads as "scroll" */
    padding-bottom: 1px;
}
.nav-tabs::-webkit-scrollbar { height: 4px; }
.nav-tabs .nav-item { flex: 0 0 auto; }
.nav-tabs .nav-link { white-space: nowrap; font-size: .9rem; }

/* Cards and metric cards. */
.card, .metric-card { background: var(--p3a-surface); }
.metric-card .metric-label {
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .06em;
}
.metric-card .metric-value {
    font-size: 1.5rem;
    font-weight: 650;
    letter-spacing: -.02em;
    line-height: 1.2;
}
/* The leading icon of a metric card sits in a tinted brand chip. */
.metric-card > i.fa-solid:first-child {
    flex: 0 0 2.6rem;
    width: 2.6rem;
    height: 2.6rem;
    border-radius: .65rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    color: var(--bs-primary) !important;
    background: var(--p3a-accent-soft);
}

/* Table row actions: quiet until hovered, then take their own colour. */
.table .btn[class*="btn-outline-"]:has(> i:only-child):not(:hover):not(:focus-visible) {
    color: var(--p3a-muted);
    border-color: var(--p3a-border);
    background: transparent;
}
.table > tbody > tr > td { padding-top: .6rem; padding-bottom: .6rem; vertical-align: middle; }

/* Badges: softer, consistent pills. */
.badge { font-weight: 600; font-size: .75rem; line-height: 1.1; }

/* Empty / placeholder rows in list groups look like messages, not inputs. */
.list-group-item.bg-transparent.text-secondary:only-child {
    border-style: dashed;
    text-align: center;
    font-size: .875rem;
    padding: 1.25rem 1rem;
}
.empty-state { padding: 2rem 1rem; }
.empty-state i { font-size: 1.6rem; opacity: .7; }

/* Form labels a touch smaller and quieter; inputs slightly taller. */
.form-label { font-size: .825rem; color: var(--p3a-soft-fg); margin-bottom: .3rem; }
.form-control-sm, .form-select-sm { min-height: 2rem; }

/* In-page titles (detail pages, BD Snapshot, review forms) share one style. */
.view-root h2.h4, .view-root h2.h5 { font-size: 1.3rem; font-weight: 650; letter-spacing: -.02em; }
.view-root .card-header { background: transparent; border-bottom-color: var(--p3a-border); font-weight: 600; }

/* Page intro strip (P3A.pageIntro): what the screen is for + its main buttons. */
.page-intro { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; margin-bottom: 1rem; }
.page-intro .pi-text { flex: 1 1 16rem; color: var(--p3a-soft-fg); font-size: .9rem; }
.page-intro .pi-actions { display: flex; flex-wrap: wrap; gap: .5rem; }

/* Detail pages: a key/value side panel, comment threads, initials avatars. */
.detail-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .5rem 0; border-bottom: 1px solid var(--p3a-border); font-size: .9rem; }
.detail-row:last-child { border-bottom: 0; }
.detail-row > span:first-child { color: var(--p3a-muted); font-size: .8rem; font-weight: 600; }
.detail-row > span:last-child { text-align: right; min-width: 0; overflow-wrap: anywhere; }
.avatar-chip { flex: 0 0 2rem; width: 2rem; height: 2rem; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
    font-size: .72rem; font-weight: 700; color: #fff; background: var(--bs-primary); }
.comment-body { background: var(--bs-tertiary-bg); border-radius: .2rem .75rem .75rem .75rem; padding: .5rem .75rem; margin-top: .2rem; white-space: pre-wrap; }

/* Calendar: subscription renewals (Subscriptions module). */
.cal-renewal-tag { background: var(--p3a-brand-orange, #e8772e); color: #fff; }
.min-w-0 { min-width: 0; }

/* Required fields: an asterisk after the label (signed-in screens only). */
body:not(.unauthed) .form-label:has(+ [required])::after,
body:not(.unauthed) .form-label:has(+ .input-group > [required])::after {
    content: " *";
    color: var(--bs-danger);
    font-weight: 600;
}
.form-text { font-size: .775rem; margin-top: .2rem; }

/* --- 5. Print: clean pages for reports, reviews, project pages ------------- */
@media print {
    @page { margin: 14mm; }
    html, body { background: #fff !important; color: #111 !important; font-size: 11pt; }
    .app-sidebar, .app-topbar, .toast-container, .sidebar-toggle, .nav-tabs,
    .btn, .form-control, .form-select, input[type="file"], .dropdown-menu { display: none !important; }
    .app-shell, .app-content { display: block !important; }
    .view-root { padding: 0 !important; overflow: visible !important; }
    .card, .metric-card, .proj-hero { box-shadow: none !important; border-color: #ccc !important; background: #fff !important; break-inside: avoid; }
    .table { font-size: 10pt; }
    .table > thead > tr > th { color: #444 !important; }
    a { color: #111 !important; text-decoration: none !important; }
    .badge { border: 1px solid #999; color: #111 !important; background: transparent !important; }
}

/* --- 6. Phones: tighter padding, compact top bar so titles stay readable ---- */
@media (max-width: 575.98px) {
    .view-root { padding: .75rem; }
    .view-root > .p-2 { padding: .25rem !important; }
    .app-topbar { padding: 0 .5rem; gap: .15rem; }
    .app-topbar > .btn-outline-secondary,
    .app-topbar > a.btn-outline-secondary { width: 2rem; height: 2rem; }
    .app-topbar > .ms-2, .app-topbar > .ms-3, .topbar-user.ms-3 { margin-left: .15rem !important; }
    .topbar-user .btn { padding: .1rem; }
    .topbar-user .dropdown-toggle::after { display: none; }
    .metric-card .metric-value { font-size: 1.3rem; }
    /* Number tiles two-up on phones so lists aren't pushed off screen. */
    .row > .col-sm-6:has(> .metric-card) { flex: 0 0 50%; max-width: 50%; }
    .row > .col-sm-6 > .metric-card { padding: .75rem !important; gap: .5rem; }
    .row > .col-sm-6 > .metric-card > i.fa-solid:first-child { display: none; }
    .row > .col-sm-6 > .metric-card .metric-value { font-size: 1.1rem; overflow-wrap: anywhere; }
    .page-intro .pi-actions { width: 100%; }
    .page-intro .pi-actions > .btn { flex: 1 1 auto; }

    /* Card tables (table.table-stack): each row becomes a small card; the
       first cell is the card's heading, the rest show "Column   value". */
    .table-stack thead { display: none; }
    .table-stack, .table-stack > tbody, .table-stack > tbody > tr, .table-stack > tbody > tr > td { display: block; width: 100%; }
    .table-stack > tbody > tr {
        border: 1px solid var(--p3a-border);
        border-radius: .65rem;
        margin-bottom: .6rem;
        padding: .35rem .8rem;
        background: var(--bs-body-bg);
    }
    .table-stack > tbody > tr > td {
        border: 0;
        padding: .3rem 0 !important;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        text-align: right !important;
        background: transparent !important;
    }
    .table-stack > tbody > tr > td::before {
        content: attr(data-label);
        flex-shrink: 0;
        font-size: .75rem;
        font-weight: 600;
        color: var(--p3a-muted);
        text-align: left;
    }
    .table-stack > tbody > tr > td:first-child,
    .table-stack > tbody > tr > td[colspan] { display: block; text-align: left !important; }
    .table-stack > tbody > tr > td:first-child::before,
    .table-stack > tbody > tr > td[colspan]::before,
    .table-stack > tbody > tr > td[data-label=""]::before { display: none; }
    .table-stack > tbody > tr > td[data-label=""] { justify-content: flex-end; }
    .table-stack > tbody > tr:has(> td[colspan]) { border-style: dashed; }
}

/* Page content breathing room on large screens. */
@media (min-width: 1200px) {
    .view-root { padding: 1.5rem 2rem; }
}
