/* ==========================================================================
   Design System — CSS Custom Properties
   Brand/typography/layout tokens (--primary, --bg-color, --font-heading,
   --radius, --shadow, etc.) are now defined in dynamic-theme.css.php, not
   here — they're admin-editable via the Theme Customizer (?page=admin/theme)
   and stored in the settings table, not hardcoded. dynamic-theme.css.php is
   linked in includes/header.php BEFORE this file, so every var() reference
   below already resolves by the time these rules run. This file only
   defines the small set of tokens that are NOT theme-customizable (status
   colors) — everything else here is pure component styling.
   ========================================================================== */
:root {
    /* Status — not admin-editable, intentionally separate from the
       customizable brand palette in dynamic-theme.css.php */
    --success:        #16a34a;
    --success-bg:     #dcfce7;
    --error:          #dc2626;
    --error-bg:       #fee2e2;

    /* Elevation tiers — also not admin-editable. dynamic-theme.css.php's
       --shadow (the mid tier, kept there for back-compat with existing
       sites) is a single flat depth used everywhere; these two add a real
       hierarchy on top of it for hero visuals, nav chrome, and dense admin
       cards, without adding new theme-customizer fields. */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.10), 0 24px 48px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: var(--font-body);
    color: var(--text-main);
    background: var(--bg-color);
    line-height: 1.6;
}
h1, h2, h3, h4 { font-family: var(--font-heading); margin: 0 0 0.5em; }
a { color: var(--primary); }
img { max-width: 100%; display: block; }

.container { max-width: 1100px; margin: 0 auto; padding: 0 20px; }
.hidden { display: none !important; }

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn {
    display: inline-block;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-weight: 600;
    text-decoration: none;
    border: 2px solid transparent;
    cursor: pointer;
    font-size: 0.95rem;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--secondary); }
.btn-secondary { background: var(--surface-color); color: var(--text-main); border-color: var(--border-color); }
.btn-outline { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }
.btn-danger { background: var(--error); color: #fff; }
.btn-lg { padding: 14px 32px; font-size: 1.05rem; }
.btn-sm { padding: 6px 14px; font-size: 0.85rem; }

/* ── Forms ────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 0.9rem; }
.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-size: 1rem;
    background: var(--surface-color);
}
.form-control:focus { outline: none; border-color: var(--primary); }

.form-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ── Password show/hide toggle ───────────────────────────────────────── */
.password-field-wrapper { position: relative; }
.password-field-wrapper .form-control { padding-right: 42px; }
.password-toggle-btn {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    background: none;
    border: none;
    line-height: 0;
    color: var(--text-muted);
    cursor: pointer;
}
.password-toggle-btn:hover { color: var(--text-main); }
.password-toggle-btn svg { width: 18px; height: 18px; }

/* ── Cards ────────────────────────────────────────────────────────────── */
.card-grid { display: grid; grid-template-columns: 1fr; gap: 20px; }
@media (min-width: 768px) { .card-grid { grid-template-columns: repeat(3, 1fr); } }
.card-grid--2 { display: grid; grid-template-columns: 1fr; gap: 20px; }
@media (min-width: 768px) { .card-grid--2 { grid-template-columns: repeat(2, 1fr); } }
.card {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 24px;
    /* Same CR-013 min-width:0 fix as .admin-content above, needed here too:
       a .card sitting in a 3-up .card-grid is itself a grid item, so a table
       inside it (e.g. the Fail2Ban card, with an unbreakable word like
       "roundcube-auth") forces that column wide at the expense of its
       siblings instead of scrolling inside .table-wrapper. Found on the
       trip66 ops dashboard 2026-09-05: Fail2Ban's table blew out its column,
       squeezing Firewall's text down to near-unreadable single-word wraps. */
    min-width: 0;
}
.card-title { font-size: 1.15rem; margin-bottom: 8px; }
.card-content { color: var(--text-muted); }
/* Generic de-emphasis utility - like .badge above, this exists in older
   per-product copies (olgeezer, Product BARANGAY) but not in this current
   codebase/ template, so it silently fell through to inherit the default
   dark --text-main instead of --text-muted. Found 2026-09-05. */
.text-muted { color: var(--text-muted); }
.card--bordered {
    box-shadow: none;
    border: 1px solid var(--border-color);
}

/* ── Status badges — used on the ops dashboard for backup/malware/cert/
   release-status pills. Not part of the original codebase/ template (only
   older per-product copies like olgeezer/Product BARANGAY had these) -
   added here 2026-09-05, worth backporting into codebase/ itself since
   this is a generically useful pattern, not a one-off. ── */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; text-transform: capitalize; }
.badge-draft, .badge-pending { background: #fef3c7; color: #92400e; }
.badge-published, .badge-approved { background: var(--success-bg); color: var(--success); }
.badge-rejected { background: var(--error-bg); color: var(--error); }

/* ── Section tint — alternating band utility ─────────────────────────────
   Add to a <section> to break up an all-white/all-bg-color page (e.g. every
   other section on a home page) without a new admin-customizable token.
   color-mix() keeps it tied to the site's actual brand colour. */
.section--tint {
    background: color-mix(in srgb, var(--surface-color) 96%, var(--primary) 4%);
}

/* ── Headings / labels ────────────────────────────────────────────────── */
.page-title { font-size: 2rem; margin-bottom: 24px; }
.section-title { font-size: 1.6rem; margin-bottom: 12px; }
.section-label { text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.8rem; color: var(--accent); font-weight: 700; }

/* ── Hero — three named patterns ─────────────────────────────────────────
   Pick ONE per site during the New-Build Visual Identity step (see
   website-frontend-designer SKILL.md), not by default. Each is scoped to
   .hero-section so page headings elsewhere (.page-title on admin/list
   pages) are unaffected by the larger hero sizing below.

   1. .hero-section (default) — centered stack. Safe, works for any site.
   2. .hero-section--split — text left, visual panel right. Product/SaaS feel.
   3. .hero-section--banner — full-bleed brand band, overlaid light text.
      Punchier first impression, best for agency/consultancy-style brands. */
.hero-section {
    padding: 56px 0;
    text-align: center;
}
.hero-section .page-title {
    font-size: clamp(2.25rem, 1.7rem + 2vw, 3.5rem);
    line-height: 1.1;
    letter-spacing: -0.02em;
}
.hero-subhead {
    max-width: 640px;
    margin: 0 auto 28px;
    font-size: 1.15rem;
    color: var(--text-muted);
}
.hero-section--split {
    display: grid;
    grid-template-columns: 1fr;
    gap: 32px;
    text-align: left;
    align-items: center;
}
.hero-section--split .hero-subhead { margin: 0 0 28px; }
.hero-section--split .hero-visual {
    background: linear-gradient(135deg, var(--primary), var(--accent, var(--primary)));
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    min-height: 240px;
}
@media (min-width: 768px) {
    .hero-section--split { grid-template-columns: 1fr 1fr; }
}
.hero-section--banner {
    background: var(--primary);
    color: #fff;
    padding: 72px 0;
    border-radius: var(--radius-lg);
}
.hero-section--banner .page-title,
.hero-section--banner .hero-subhead { color: #fff; }
.hero-section--banner .section-label { color: rgba(255,255,255,0.85); }

/* ── Alerts ───────────────────────────────────────────────────────────── */
.success-msg, .error-msg {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 18px;
    font-size: 0.95rem;
}
.success-msg { background: var(--success-bg); color: var(--success); }
.error-msg { background: var(--error-bg); color: var(--error); }

/* ── Header / nav ─────────────────────────────────────────────────────── */
.main-header { background: var(--surface-color); border-bottom: 1px solid var(--border-color); position: sticky; top: 0; z-index: 200; }
.header-container { display: flex; align-items: center; justify-content: space-between; height: 64px; }
.logo { display: flex; align-items: center; gap: 8px; text-decoration: none; }
.logo-img { height: 36px; }
.logo-text { font-family: var(--font-heading); font-weight: 700; font-size: 1.2rem; color: var(--text-main); }
.main-nav { display: flex; align-items: center; gap: 24px; }
.nav-links { display: flex; list-style: none; gap: 20px; margin: 0; padding: 0; }
.nav-links a { text-decoration: none; color: var(--text-main); font-weight: 500; }
.auth-links { display: flex; gap: 10px; align-items: center; }

.hamburger { display: none; flex-direction: column; gap: 5px; background: none; border: none; cursor: pointer; padding: 4px; }
.hamburger span { display: block; width: 24px; height: 2px; background: var(--text-main); transition: transform .25s, opacity .25s; }
.hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

@media (max-width: 767px) {
    .hamburger { display: flex; }
    .main-nav { display: none; flex-direction: column; position: absolute; top: 64px; left: 0; right: 0; background: var(--surface-color); border-bottom: 1px solid var(--border-color); padding: 16px; z-index: 100; }
    .main-nav.open { display: flex; }
    .nav-links { flex-direction: column; gap: 0; }
    .auth-links { flex-direction: column; gap: 8px; margin-top: 16px; }
}

/* ── Content / footer ─────────────────────────────────────────────────── */
.main-content { min-height: 60vh; padding: 32px 0; }
.main-footer { background: var(--text-main); color: #fff; padding: 32px 0; margin-top: 40px; }
.footer-container { display: flex; flex-direction: column; gap: 12px; align-items: center; text-align: center; }
.footer-links { display: flex; gap: 20px; }
.footer-links a { color: #fff; opacity: 0.85; text-decoration: none; }
.footer-copy { opacity: 0.7; font-size: 0.85rem; }

/* ── Tables ───────────────────────────────────────────────────────────── */
code { overflow-wrap: anywhere; }

.table-wrapper {
    overflow-x: auto;
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    /* Generalized from Product BARANGAY CR-013 (2026-08-22): a table that
       needs to scroll is visually indistinguishable from one that's just
       cut off — the OS hides an overlay scrollbar until hovered/touched, so
       a wide table just stops dead at the card edge with no cue that more
       columns exist. An always-visible, styled scrollbar makes "there's
       more, scroll to see it" obvious instead of reading as broken. */
    scrollbar-width: thin;
    scrollbar-color: var(--text-muted, #94a3b8) transparent;
    padding-bottom: 6px;
    /* A long table's scrollbar otherwise sits at the bottom of a
       potentially very tall element, off-screen below a normal viewport
       unless the whole page is scrolled down first. Capping the height and
       adding vertical scroll keeps the scrollbar within the first viewport
       a user lands on, regardless of row count — a short table never
       reaches this height, so no internal scroll appears. */
    max-height: 60vh;
    overflow-y: auto;
}

.table-wrapper::-webkit-scrollbar { height: 8px; }
.table-wrapper::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.04); border-radius: 4px; }
.table-wrapper::-webkit-scrollbar-thumb { background-color: rgba(0, 0, 0, 0.25); border-radius: 4px; }
.table-wrapper::-webkit-scrollbar-thumb:hover { background-color: rgba(0, 0, 0, 0.4); }

table { width: 100%; border-collapse: collapse; }
thead { background: var(--bg-color); }
th, td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border-color); }
th { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }

.table-wrapper thead th {
    /* Keeps column headers visible while scrolling vertically inside the
       now-bounded box above. Needs its own opaque background — thead's own
       background is set on the <thead> element, but a sticky child needs
       the fill on itself or scrolling body rows show through underneath
       the header text (a real bug this exact pattern shipped with once). */
    position: sticky;
    top: 0;
    z-index: 1;
    background-color: var(--surface-color);
}

/* ── Auth pages ───────────────────────────────────────────────────────── */
.auth-container {
    max-width: 420px;
    margin: 60px auto;
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 36px;
}

/* ── Admin shell ──────────────────────────────────────────────────────── *
 * Sectioned sidebar layout adopted from Product CRM's build (2026-07)
 * after comparing it against Product CMS's flat single-list nav — the
 * section split scales better once a site has more than one authenticated
 * tier. See includes/admin-nav.php. */
.admin-layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 30px;
}

.admin-sidebar {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px 16px;
    align-self: start;
    box-shadow: var(--shadow);
}

/* Element+class specificity (not just .admin-nav-toggle-btn) is deliberate:
   .btn sets its own display and is defined earlier in this file, so a
   same-specificity .admin-nav-toggle-btn rule would lose the cascade to it
   at every viewport, silently breaking this button's hide/show behaviour
   entirely. Confirmed as a real regression on KittyDynCollection (2026-08-28)
   before this was generalized into the shared boilerplate — keep both this
   rule and its @media counterpart below at the same button.-prefixed
   specificity, or the bug recurs. */
button.admin-nav-toggle-btn {
    display: none;
}

.sidebar-title {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 12px;
    padding-left: 8px;
}

.admin-menu {
    list-style: none;
    margin: 0;
    padding: 0;
}

.admin-menu-item {
    margin-bottom: 4px;
}

.admin-menu-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    font-size: 0.92rem;
    font-weight: 500;
    color: var(--text-main);
    text-decoration: none;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.admin-menu-link:hover, .admin-menu-link.active {
    background-color: rgba(37, 99, 235, 0.08);
    color: var(--primary);
    font-weight: 600;
}

/* ── Collapsible sidebar sections (accordion) — OPT-IN ────────────────────
   Only activates on a .sidebar-title carrying data-nav-section (paired with
   an .admin-menu[data-nav-section] and assets/js/admin-nav-collapse.js) —
   a .sidebar-title with no data-nav-section attribute renders exactly like
   the plain rule above, unaffected. See php-website-guidelines.md's "Admin
   Sidebar Accordion (optional)" section for when/how to wire this in. */
.sidebar-title[data-nav-section] {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    border-radius: 6px;
}

.sidebar-title[data-nav-section]:hover {
    background-color: rgba(37, 99, 235, 0.06);
}

.sidebar-chevron {
    font-size: 0.65rem;
    line-height: 1;
    flex-shrink: 0;
    transition: transform 0.15s ease;
}

.sidebar-title[aria-expanded="false"] .sidebar-chevron {
    transform: rotate(-90deg);
}

.admin-menu[hidden] {
    display: none;
}

.admin-content {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 30px;
    box-shadow: var(--shadow);
    /* Generalized from Product BARANGAY CR-013 (2026-08-22): a CSS grid
       item defaults to min-width:auto, meaning it refuses to shrink below
       its content's intrinsic width — a wide table inside .table-wrapper
       was stretching this whole grid column instead of being contained and
       scrolling internally, silently defeating the wrapper above. */
    min-width: 0;
}

@media (max-width: 767px) {
    .admin-layout {
        grid-template-columns: 1fr;
    }

    .admin-content {
        padding: 16px;
    }

    button.admin-nav-toggle-btn {
        display: block;
        margin-bottom: 16px;
    }

    .admin-sidebar {
        display: none;
    }

    .admin-sidebar.open {
        display: block;
    }

    /* Generalized from Product BARANGAY CR-013 (2026-08-22): admin forms
       commonly use an inline style="display:grid; grid-template-columns:.."
       with a hardcoded column count rather than a shared class, so there's
       no single class selector to target per-page. A fixed column count
       squeezes each input into an unusable sliver on a phone; this
       attribute-selector override collapses every one to a single column
       below this breakpoint. !important is required since it overrides an
       inline style. */
    [style*="display:grid"] {
        grid-template-columns: 1fr !important;
    }

    /* Same reasoning, applied to inline flex rows — an unwrapped
       "space-between" header row or action-button row forces its siblings
       onto one line regardless of viewport width. wrap only engages when
       content genuinely doesn't fit, so a row that already fits is
       unaffected. */
    [style*="display:flex"] {
        flex-wrap: wrap !important;
    }
}

/* ── Cookie Consent Banner ────────────────────────────────────────────── */
.consent-banner {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    background: var(--surface-color);
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.12);
    padding: 16px 20px;
}
.consent-banner[hidden] { display: none; }
.consent-banner-body {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    max-width: 1100px;
    margin: 0 auto;
}
.consent-banner-text { margin: 0; flex: 1 1 320px; font-size: 0.9rem; color: var(--text-main); }
.consent-banner-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.consent-banner-categories {
    max-width: 1100px;
    margin: 12px auto 0;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
}
.consent-banner-categories[hidden] { display: none; }
.consent-category { display: flex; align-items: center; gap: 6px; font-size: 0.88rem; color: var(--text-main); }
