/*
Theme Name: CoP Hub Theme
Theme URI: https://aphrc.org
Author: Gideon Kiprotich
Author URI: https://aphrc.org
Description: A purpose-built theme for the Community of Practice Hub plugin. Features a sticky navigation bar with notification bell, user dropdown, search, and CoP page links. Clean, modern design aligned with the #75b83d brand palette.
Version: 2.1.5
Requires at least: 6.0
Requires PHP: 7.4
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: cop-hub-theme
*/

/* ========================================================================
   CSS VARIABLES
   ======================================================================== */
:root {
    --copt-primary: #572A24;
    --copt-primary-dark: #5a9a2b;
    --copt-primary-light: #a8d47a;
    --copt-accent: #e8f5d8;
    --copt-bg: #f5f7fa;
    --copt-bg-card: #ffffff;
    --copt-text: #1e293b;
    --copt-text-light: #64748b;
    --copt-text-muted: #94a3b8;
    --copt-border: #e2e8f0;
    --copt-border-light: #f1f5f9;
    --copt-shadow-sm: 0 1px 2px rgba(0,0,0,.04);
    --copt-shadow-md: 0 4px 12px rgba(0,0,0,.06);
    --copt-shadow-lg: 0 8px 24px rgba(0,0,0,.08);
    --copt-nav-height: 64px;
    --copt-sidebar-width: 300px;
    --copt-radius: 8px;
    --copt-radius-lg: 12px;
    --copt-font: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --copt-font-display: 'Sora', 'DM Sans', sans-serif;
    --copt-transition: .2s ease;
}

/* ========================================================================
   RESET & BASE
   ======================================================================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--copt-font);
    font-size: 15px;
    line-height: 1.6;
    color: var(--copt-text);
    background: var(--copt-bg);
    padding-top: var(--copt-nav-height);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}
html { overflow-x: hidden; }
a { color: var(--copt-primary-dark); text-decoration: none; transition: color var(--copt-transition); }
a:hover { color: var(--copt-primary); }
img { max-width: 100%; height: auto; }
h1, h2, h3, h4 { font-family: var(--copt-font-display); font-weight: 700; line-height: 1.3; }

/* ========================================================================
   TOP NAVIGATION BAR
   ======================================================================== */
.copt-navbar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
    height: var(--copt-nav-height);
    background: var(--copt-bg-card);
    border-bottom: 1px solid var(--copt-border);
    box-shadow: var(--copt-shadow-sm);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 20px;
    gap: 8px;
}

/* WP Admin bar offset */
.admin-bar .copt-navbar { top: 32px; }
.admin-bar body { padding-top: calc(var(--copt-nav-height) + 32px); }

/* Logo area */
.copt-nav-brand {
    display: flex; align-items: center; gap: 6px;
    text-decoration: none; flex-shrink: 0;
}
.copt-nav-brand img {
    height: 44px; width: auto; object-fit: contain;
}
.copt-nav-brand-text {
    font-family: var(--copt-font-display);
    font-size: 17px; font-weight: 800;
    color: var(--copt-text);
    white-space: nowrap;
}
.copt-nav-brand:hover .copt-nav-brand-text { color: var(--copt-primary); }

/* Nav links (CoP pages) — centered between logo and right controls */
.copt-nav-links {
    display: flex; align-items: center; gap: 2px;
    justify-content: center;
    flex: 1;
}
.copt-nav-link {
    padding: 7px 14px;
    font-size: 15px; font-weight: 600;
    color: var(--copt-text-light);
    border-radius: var(--copt-radius);
    transition: all var(--copt-transition);
    white-space: nowrap;
    text-decoration: none;
}
.copt-nav-link:hover { color: var(--copt-text); background: var(--copt-border-light); }
.copt-nav-link.active { color: var(--copt-primary-dark); background: var(--copt-accent); }
.copt-nav-link-icon { display: inline-block; margin-right: 4px; font-size: 13px; }

/* Discover dropdown */
.copt-nav-discover { position: relative; }
.copt-nav-discover-toggle { display: inline-flex; align-items: center; gap: 4px; background: transparent; border: 0; cursor: pointer; font-family: inherit; position: relative; }
/* Red attention dot when an unseen NEW badge is hidden inside the dropdown */
.copt-nav-discover-toggle.has-new::after { content: ''; position: absolute; top: 6px; right: 14px; width: 8px; height: 8px; border-radius: 50%; background: #dc2626; box-shadow: 0 0 0 2px var(--copt-bg, #fff); animation: cop-new-pulse 2.6s ease-in-out infinite; }
.copt-nav-caret { font-size: 9px; transition: transform .15s ease; }
.copt-nav-discover[data-open="true"] .copt-nav-caret { transform: rotate(180deg); }
.copt-nav-discover-menu {
    position: absolute; top: calc(100% + 6px); left: 0; min-width: 220px;
    background: var(--copt-bg-card, #fff);
    border: 1px solid var(--copt-border, #e2e8f0); border-radius: 12px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, .12);
    padding: 8px; z-index: 200; opacity: 0; transform: translateY(-4px); pointer-events: none;
    transition: opacity .15s ease, transform .15s ease;
}
.copt-nav-discover[data-open="true"] .copt-nav-discover-menu { opacity: 1; transform: translateY(0); pointer-events: auto; }
.copt-nav-discover-item {
    display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 8px;
    text-decoration: none; color: var(--copt-text, #1a1a2e); font-size: 14px; font-weight: 600;
    transition: background .15s ease;
}
.copt-nav-discover-item:hover { background: var(--copt-border-light, #f1f5f9); color: var(--copt-primary-dark, #4a7f23); }
.copt-nav-discover-item.active { background: var(--copt-accent, #e8f5d8); color: var(--copt-primary-dark, #4a7f23); }
.copt-nav-discover-icon { font-size: 16px; line-height: 1; flex-shrink: 0; }
.copt-nav-discover-label { flex: 1; }
/* Inside the mobile hamburger drawer, the Discover dropdown becomes an inline
   accordion. Breakpoint MUST match the one that switches the nav to hamburger
   mode below (1024px) — otherwise the menu floats absolutely inside a vertical
   drawer and looks broken on tablets. */
@media (max-width: 1024px) {
    .copt-nav-discover { width: 100%; }
    .copt-nav-discover-menu {
        position: static;
        box-shadow: none;
        border: 0;
        padding: 4px 0 4px 12px;
        margin-left: 4px;
        border-left: 2px solid var(--copt-border, #e2e8f0);
        opacity: 1;
        transform: none;
        pointer-events: auto;
        min-width: 0;
        background: transparent;
    }
    .copt-nav-discover-toggle {
        width: 100%;
        justify-content: center; /* keep "Discover ▾" centered like its peers */
    }
    .copt-nav-discover[data-open="false"] .copt-nav-discover-menu { display: none; }
    .copt-nav-discover-item {
        padding: 12px 12px;
        font-size: 14px;
        justify-content: center;     /* center the icon + label inside the row */
        text-align: center;
    }
    /* Label has flex:1 on desktop to stretch and left-align; in the mobile
       accordion we want the icon + label to sit centered together, so let
       the label shrink to its content. */
    .copt-nav-discover-item .copt-nav-discover-label { flex: 0 0 auto; }
}

/* Nav search */
.copt-nav-search {
    position: relative; flex-shrink: 0;
}
.copt-nav-search input {
    width: 200px; padding: 7px 12px 7px 34px;
    border: 1px solid var(--copt-border); border-radius: 20px;
    font-size: 13px; font-family: var(--copt-font);
    background: var(--copt-bg); color: var(--copt-text);
    transition: all var(--copt-transition); outline: none;
}
.copt-nav-search input:focus {
    width: 260px; border-color: var(--copt-primary);
    box-shadow: 0 0 0 3px rgba(123,193,72,.15);
}
.copt-nav-search-icon {
    position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
    font-size: 14px; color: var(--copt-text-muted); pointer-events: none;
}

/* Nav right: notif bell + user */
.copt-nav-right {
    display: flex; align-items: center; gap: 4px; flex-shrink: 0;
}

/* Notification bell in nav */
.copt-nav-notif {
    position: relative; width: 38px; height: 38px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%; cursor: pointer;
    transition: background var(--copt-transition);
    border: none; background: transparent; font-size: 18px;
}
.copt-nav-notif:hover { background: var(--copt-border-light); }
.copt-nav-notif-badge {
    position: absolute; top: 2px; right: 2px;
    background: #ef4444; color: #fff;
    font-size: 10px; font-weight: 800;
    min-width: 16px; height: 16px;
    border-radius: 8px; padding: 0 4px;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid var(--copt-bg-card);
    line-height: 1;
}

/* User dropdown in nav */
.copt-nav-user {
    position: relative; display: flex; align-items: center;
    gap: 8px; cursor: pointer; padding: 4px 10px 4px 4px;
    border-radius: 24px; transition: background var(--copt-transition);
    border: none; background: transparent;
    font-family: var(--copt-font);
}
.copt-nav-user:hover { background: var(--copt-border-light); }
.copt-nav-user-avatar {
    width: 32px; height: 32px; border-radius: 50%; object-fit: cover;
    border: 2px solid var(--copt-border);
}
.copt-nav-user-name {
    font-size: 13px; font-weight: 600; color: var(--copt-text);
    max-width: 160px; line-height: 1.25; word-break: break-word; overflow-wrap: anywhere;
    display: inline-flex; align-items: center; gap: 3px; flex-wrap: wrap;
}
.copt-nav-user-arrow {
    font-size: 10px; color: var(--copt-text-muted);
    transition: transform var(--copt-transition);
}
.copt-nav-user.open .copt-nav-user-arrow { transform: rotate(180deg); }

/* User dropdown menu */
.copt-user-dropdown {
    position: absolute; top: calc(100% + 8px); right: 0;
    width: 220px; background: var(--copt-bg-card);
    border: 1px solid var(--copt-border); border-radius: var(--copt-radius-lg);
    box-shadow: var(--copt-shadow-lg); overflow: hidden;
    display: none; z-index: 100;
}
.copt-user-dropdown.open { display: block; }
.copt-user-dropdown-header {
    padding: 14px 16px; border-bottom: 1px solid var(--copt-border-light);
    display: flex; align-items: center; gap: 10px;
}
.copt-user-dropdown-header img { width: 40px; height: 40px; border-radius: 50%; }
.copt-user-dropdown-header-info { min-width: 0; }
.copt-user-dropdown-header-name { font-size: 14px; font-weight: 700; color: var(--copt-text); }
.copt-user-dropdown-header-email { font-size: 11px; color: var(--copt-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.copt-user-dropdown a {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 16px; font-size: 13px; font-weight: 500;
    color: var(--copt-text-light); transition: all var(--copt-transition);
    text-decoration: none;
}
.copt-user-dropdown a:hover { background: var(--copt-bg); color: var(--copt-text); }
.copt-user-dropdown a.copt-logout { color: #ef4444; border-top: 1px solid var(--copt-border-light); }
.copt-user-dropdown a.copt-logout:hover { background: #fef2f2; }

/* Mobile menu toggle */
.copt-nav-toggle {
    display: none; width: 38px; height: 38px;
    align-items: center; justify-content: center;
    border: none; background: transparent; font-size: 22px;
    cursor: pointer; border-radius: 50%;
    transition: background var(--copt-transition);
}
.copt-nav-toggle:hover { background: var(--copt-border-light); }

/* ========================================================================
   LAYOUT: CONTENT + SIDEBAR
   ======================================================================== */
.copt-layout {
    max-width: 1360px; margin: 0 auto;
    padding: 24px 40px 48px;
    display: grid;
    grid-template-columns: 1fr var(--copt-sidebar-width);
    gap: 28px;
    min-height: calc(100vh - var(--copt-nav-height) - 60px);
}
.copt-content { min-width: 0; }

/* Page content typography */
.copt-page-header { margin-bottom: 28px; }
.copt-page-title { font-family: 'Sora', sans-serif; font-size: 28px; font-weight: 800; color: var(--copt-text); margin: 0 0 8px; letter-spacing: -.3px; }
.copt-page-content {
    background: var(--copt-bg-card); border: 1px solid var(--copt-border-light);
    border-radius: var(--copt-radius-lg); padding: 32px 36px;
    box-shadow: var(--copt-shadow-sm); line-height: 1.7; color: #334155;
}
.copt-page-content h1 { font-size: 24px; font-weight: 800; color: var(--copt-text); margin: 32px 0 12px; }
.copt-page-content h1:first-child { margin-top: 0; }
.copt-page-content h2 { font-size: 20px; font-weight: 700; color: var(--copt-text); margin: 28px 0 10px; }
.copt-page-content h2:first-child { margin-top: 0; }
.copt-page-content h3 { font-size: 17px; font-weight: 700; color: var(--copt-text); margin: 24px 0 8px; }
.copt-page-content p { margin: 0 0 16px; font-size: 14px; }
.copt-page-content ul, .copt-page-content ol { margin: 0 0 16px; padding-left: 24px; }
.copt-page-content li { margin-bottom: 6px; font-size: 14px; }
.copt-page-content a { color: var(--copt-primary-dark); text-decoration: underline; text-underline-offset: 2px; }
.copt-page-content a:hover { color: var(--copt-primary); }
.copt-page-content strong { color: var(--copt-text); }
.copt-page-content blockquote { border-left: 3px solid var(--copt-primary); margin: 16px 0; padding: 12px 20px; background: #f8faf5; border-radius: 0 8px 8px 0; }
.copt-page-content hr { border: none; border-top: 1px solid var(--copt-border-light); margin: 24px 0; }
.copt-page-content img { max-width: 100%; height: auto; border-radius: 8px; }
.copt-page-content table { width: 100%; border-collapse: collapse; margin: 16px 0; }
.copt-page-content th, .copt-page-content td { padding: 10px 14px; border: 1px solid var(--copt-border-light); font-size: 13px; text-align: left; }
.copt-page-content th { background: #f8fafc; font-weight: 700; color: var(--copt-text); }

/* Sidebar */
.copt-sidebar {
    display: flex; flex-direction: column; gap: 20px;
}
.copt-sidebar-widget {
    background: var(--copt-bg-card);
    border: 1px solid var(--copt-border-light);
    border-radius: var(--copt-radius-lg);
    padding: 20px;
    box-shadow: var(--copt-shadow-sm);
}
.copt-sidebar-widget-title {
    font-family: var(--copt-font-display);
    font-size: 14px; font-weight: 700;
    color: var(--copt-text); margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--copt-accent);
}

/* Full-width pages (no sidebar) */
.copt-layout-full {
    max-width: 1360px; margin: 0 auto;
    padding: 24px 40px 48px;
}

/* ========================================================================
   FOOTER — styles are in footer.php (inline) for full self-containment
   ======================================================================== */

/* ========================================================================
   WIDGET: ACTIVE MEMBERS
   ======================================================================== */
.copt-active-member {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 0; font-size: 13px;
}
.copt-active-member img { width: 32px; height: 32px; border-radius: 50%; }
.copt-active-member-name { font-weight: 600; color: var(--copt-text); }
.copt-active-member-meta { font-size: 11px; color: var(--copt-text-muted); }

/* ========================================================================
   WIDGET: GROUPS LIST
   ======================================================================== */
.copt-sidebar-group {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 0; text-decoration: none;
}
.copt-sidebar-group img { width: 32px; height: 32px; border-radius: 50%; }
.copt-sidebar-group-name { font-size: 13px; font-weight: 600; color: var(--copt-text); }
.copt-sidebar-group-count { font-size: 11px; color: var(--copt-text-muted); }

/* ========================================================================
   RESPONSIVE
   ======================================================================== */

/* 14" laptops (1200-1400px) — condense nav links */
@media (max-width: 1400px) {
    .copt-nav-link { padding: 6px 10px; font-size: 13px; }
    .copt-nav-search input { width: 160px; }
    .copt-nav-search input:focus { width: 200px; }
    .copt-nav-user-name { max-width: 120px; font-size: 12px; }
}

/* Tablets & small laptops (≤1024px) — hamburger menu, hide sidebar */
@media (max-width: 1024px) {
    .copt-layout { grid-template-columns: 1fr; }
    .copt-sidebar { display: none; }
    :root { --copt-sidebar-width: 0px; }

    /* Switch to hamburger navigation */
    .copt-nav-links {
        display: flex; flex-direction: column;
        position: fixed; top: var(--copt-nav-height); left: 0; right: 0;
        background: var(--copt-bg-card);
        border: 1px solid var(--copt-border);
        border-top: 0; /* top edge butts directly against the navbar */
        box-shadow: var(--copt-shadow-lg);
        padding: 8px; gap: 2px; z-index: 999;
        max-height: calc(100vh - var(--copt-nav-height) - 20px);
        overflow-y: auto;
        /* Slide-in from above + fade. Hidden by default; .open reveals it. */
        transform: translateY(-8px);
        opacity: 0;
        pointer-events: none;
        visibility: hidden;
        transition: transform .18s ease, opacity .18s ease, visibility 0s linear .18s;
        -webkit-overflow-scrolling: touch;
    }
    .copt-nav-links.open {
        transform: translateY(0);
        opacity: 1;
        pointer-events: auto;
        visibility: visible;
        transition: transform .18s ease, opacity .18s ease, visibility 0s linear 0s;
    }
    .admin-bar .copt-nav-links.open { top: calc(var(--copt-nav-height) + 32px); }

    /* Tap-to-dismiss backdrop behind the open drawer. Pure CSS — JS already
       handles outside-click; this just gives a visual cue + dims content. */
    .copt-nav-links.open::before {
        content: '';
        position: fixed;
        top: var(--copt-nav-height); left: 0; right: 0; bottom: 0;
        z-index: -1;
        animation: coptFadeIn .18s ease;
    }
    .admin-bar .copt-nav-links.open::before { top: calc(var(--copt-nav-height) + 32px); }
    @keyframes coptFadeIn { from { opacity: 0; } to { opacity: 1; } }

    /* Lock body scroll while the drawer is open so the page behind doesn't
       move when the user scrolls a long submenu. JS toggles this class. */
    body.copt-nav-body-lock { overflow: hidden; touch-action: none; }

    .copt-nav-link {
        padding: 14px 16px;
        border-radius: var(--copt-radius);
        font-size: 15px;
        min-height: 44px;            /* iOS recommended tap-target */
        display: flex; align-items: center;
        justify-content: center;     /* match the rest of the drawer items */
        text-align: center;
    }
    .copt-nav-toggle { display: flex; }
    .copt-nav-search { display: none; }
    .copt-nav-user-name { display: none; }
}

/* Mobile phones */
@media (max-width: 768px) {
    :root { --copt-nav-height: 56px; }
    .copt-navbar { padding: 0 14px; gap: 8px; }
    .copt-layout, .copt-layout-full { padding: 16px 14px 32px; }
    .copt-nav-brand-text { font-size: 15px; }
}

@media (max-width: 480px) {
    .copt-navbar { padding: 0 10px; }
    .copt-nav-brand-text { display: none; }
    .copt-layout, .copt-layout-full { padding: 12px 10px 24px; }
}

/* Admin bar responsive override */
@media (max-width: 782px) {
    .admin-bar .copt-navbar { top: 46px; }
    .admin-bar body { padding-top: calc(var(--copt-nav-height) + 46px); }
}
