@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800;900&display=swap');

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: rgba(37,99,235,0.1);
    --orange: #f97316;
    --orange-hover: #ea6c0a;
    --orange-light: rgba(249,115,22,0.1);
    --secondary: #64748b;
    --dark: #0f172a;
    --light: #f8fafc;
    --white: #ffffff;
    --gray-50: #f9fafb;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;

    /* Dept Colors */
    --dept-1: #6366f1;
    --dept-2: #0ea5e9;
    --dept-3: #f97316;
    --dept-4: #10b981;
    --dept-5: #8b5cf6;
    --dept-6: #ec4899;
    --dept-7: #f59e0b;

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --shadow-sm: 0 2px 8px rgba(15,23,42,0.06);
    --shadow-md: 0 8px 24px rgba(15,23,42,0.1);
    --shadow-lg: 0 16px 48px rgba(15,23,42,0.14);
    --shadow-blue: 0 8px 24px rgba(37,99,235,0.25);
    --shadow-orange: 0 8px 24px rgba(249,115,22,0.25);
    --transition: all 0.3s cubic-bezier(0.4,0,0.2,1);
    --bg-gradient: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    --header-bg: rgba(255,255,255,0.72);
    --header-border: rgba(226,232,240,0.8);
    --card-bg: rgba(255,255,255,0.8);
    --card-border: rgba(255,255,255,0.9);
}

.dark-theme {
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-light: rgba(59,130,246,0.15);
    --secondary: #94a3b8;
    --dark: #f8fafc;
    --light: #020617;
    --white: #0f172a;
    --gray-50: #1e293b;
    --gray-100: #0f172a;
    --gray-200: #334155;
    --gray-300: #475569;
    --gray-400: #64748b;
    --bg-gradient: linear-gradient(135deg, #020617 0%, #0f172a 40%, #171717 100%);
    --header-bg: rgba(15, 23, 42, 0.8);
    --header-border: rgba(51, 65, 85, 0.8);
    --card-bg: rgba(30, 41, 59, 0.8);
    --card-border: rgba(51, 65, 85, 0.9);
}

* { margin:0; padding:0; box-sizing:border-box; }

body {
    font-family: 'Poppins', sans-serif;
    background: var(--bg-gradient);
    color: var(--dark);
    height: 100vh;
    overflow: hidden;
    line-height: 1.5;
    font-size: 14px;
    transition: background 0.3s ease, color 0.3s ease;
}

h1,h2,h3,h4 { font-family: 'Poppins', sans-serif; font-weight: 700; }

/* ===== LAYOUT ===== */
.app-container { display:flex; height:100vh; }

/* ===== CONTENT OS BODY SCROLL MODE ===== */
/* When Content OS is active, body scrolls naturally like Notion/Google Docs */
body.cos-scroll { overflow-y:auto !important; height:auto !important; }
body.cos-scroll .app-container { height:auto !important; min-height:100vh !important; }
body.cos-scroll .sidebar {
    position:sticky !important; top:0 !important;
    height:100vh !important; align-self:flex-start !important;
}
body.cos-scroll .main-content { height:auto !important; overflow:visible !important; }
body.cos-scroll .top-header { position:sticky !important; top:0 !important; z-index:200 !important; }
body.cos-scroll .content-area { overflow:visible !important; height:auto !important; padding-top:1rem !important; }
body.cos-scroll .cos-toolbar {
    position: sticky !important;
    top: 70px !important;
    z-index: 150 !important;
    background: var(--surface) !important;
    border-bottom: 1px solid var(--gray-200) !important;
}

/* On mobile: cos-scroll should still allow normal body scroll with bottom bar */
@media (max-width: 600px) {
    body.cos-scroll { overflow-y: auto !important; padding-bottom: 80px !important; }
    body.cos-scroll .app-container { flex-direction: column !important; height: auto !important; min-height: 100vh !important; }
    body.cos-scroll .sidebar { position: fixed !important; bottom: 0 !important; top: auto !important; height: 70px !important; width: 100% !important; }
    body.cos-scroll .main-content { height: auto !important; width: 100% !important; overflow: visible !important; }
    body.cos-scroll .top-header { position: sticky !important; top: 0 !important; z-index: 200 !important; }
    body.cos-scroll .content-area { overflow: visible !important; height: auto !important; }
    body.cos-scroll .cos-toolbar { position: sticky !important; top: 56px !important; z-index: 150 !important; }
}


/* ===== SIDEBAR ===== */
.sidebar {
    width: 260px;
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
    color: var(--white);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
    flex-shrink: 0;
    z-index: 100;
    box-shadow: 4px 0 24px rgba(15,23,42,0.2);
    transition: width 0.35s cubic-bezier(0.4,0,0.2,1), padding 0.35s ease;
    overflow: hidden;
    border-right: 1px solid rgba(255,255,255,0.05);
}
.sidebar.collapsed { width: 72px; padding: 1.5rem 0.6rem; }
.sidebar-header { margin-bottom: 2rem; }

.logo {
    display:flex; align-items:center; gap:0.65rem;
    font-size:1.2rem; font-weight:800; color:var(--white);
}
.logo-icon {
    width:36px; height:36px; border-radius:10px;
    background: linear-gradient(135deg, var(--primary), var(--orange));
    display:flex; align-items:center; justify-content:center; flex-shrink:0;
}
.sidebar-nav { display:flex; flex-direction:column; gap:0.35rem; flex-grow:1; }

.nav-item {
    display:flex; align-items:center; gap:0.85rem;
    padding: 0.8rem 1rem; border-radius: var(--radius-md);
    background: transparent; border: none;
    color: var(--gray-400); cursor: pointer;
    transition: var(--transition); text-align:left;
    font-family: 'Poppins', sans-serif; font-weight:500; font-size:0.875rem;
    white-space:nowrap; overflow:hidden;
}
.nav-item .nav-icon {
    width:20px; height:20px; flex-shrink:0;
    display:flex; align-items:center; justify-content:center;
}
.nav-item:hover { background:rgba(255,255,255,0.07); color:var(--white); }
.nav-item.active {
    background: linear-gradient(135deg, var(--primary), #1d4ed8);
    color: var(--white);
    box-shadow: 0 4px 16px rgba(37,99,235,0.35);
}

.sidebar.collapsed .logo-text,
.sidebar.collapsed .nav-item span:not(.nav-icon) { display:none; }
.sidebar.collapsed .sidebar-toggle-btn { display:none; }
.sidebar.collapsed .nav-item { justify-content:center; padding:0.8rem 0; gap:0; }
.sidebar.collapsed .logo { justify-content:center; gap:0; }
.sidebar.collapsed .logo-icon { margin:0 auto; cursor:pointer; }
.sidebar.collapsed .sidebar-header { display:flex; justify-content:center; align-items:center; }
.sidebar.collapsed #sidebar-logo-toggle { justify-content:center; width:100%; }

.sidebar-toggle-btn {
    background:rgba(255,255,255,0.06); border:1px solid rgba(255,255,255,0.1);
    color:var(--gray-400); width:30px; height:30px; border-radius:8px;
    display:flex; align-items:center; justify-content:center;
    cursor:pointer; transition:var(--transition); flex-shrink:0;
}
.sidebar-toggle-btn:hover { background:var(--primary); color:var(--white); border-color:var(--primary); }
.logo-icon {
    transition: transform 0.2s ease;
}
.logo-icon:hover { transform: scale(1.08); }

.sidebar-footer { padding-top:1rem; border-top:1px solid rgba(255,255,255,0.07); margin-top:auto; }

/* Mobile logout button — hidden on desktop, shown only on mobile via media query */
@media (min-width: 601px) {
    .nav-logout-mobile { display: none !important; }
}

/* ===== MAIN CONTENT ===== */
.main-content {
    flex: 1;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-gradient);
    overflow: hidden;
}

/* ===== TOP HEADER ===== */
.top-header {
    display:flex; justify-content:space-between; align-items:center;
    gap:1rem; padding:1rem 2rem;
    background: var(--header-bg);
    backdrop-filter:blur(20px);
    border-bottom:1px solid var(--header-border);
    z-index:50; flex-wrap:wrap;
    box-shadow: 0 2px 16px rgba(15,23,42,0.05);
    flex-shrink: 0;
}
.header-left { display:flex; align-items:center; gap:1.5rem; }
.header-text h1 { font-size:1.4rem; font-weight:800; color:var(--dark); margin-bottom:0.1rem; }
.header-text p { color:var(--secondary); font-size:0.78rem; font-weight:400; }
.header-actions { display:flex; align-items:center; gap:0.75rem; }

/* Search Bar */
.search-bar {
    display:flex; align-items:center; gap:0.5rem;
    background: var(--card-bg); backdrop-filter:blur(16px);
    border:1px solid var(--card-border);
    border-radius: 50px; padding:0.45rem 1rem;
    transition:var(--transition); min-width:200px;
    box-shadow:inset 0 2px 4px rgba(255,255,255,0.1), var(--shadow-sm);
}
.search-bar:focus-within { background: var(--white); border-color:var(--primary); box-shadow:0 0 0 3px var(--primary-light); }
.search-bar input {
    border:none; background:transparent; outline:none;
    font-family:'Poppins',sans-serif; font-size:0.82rem; color:var(--dark);
    width:100%;
}
.search-bar input::placeholder { color:var(--gray-400); }
.search-bar svg { width:15px; height:15px; color:var(--gray-400); flex-shrink:0; }

/* ===== GLASSMORPHISM BUTTONS ===== */
.btn {
    display:inline-flex; align-items:center; gap:0.5rem;
    padding:0.55rem 1.25rem; border-radius:50px;
    font-weight:600; cursor:pointer; transition:var(--transition);
    border:1px solid transparent; font-family:'Poppins',sans-serif; font-size:0.82rem;
    white-space:nowrap; position:relative; overflow:hidden;
}
.btn::before {
    content:''; position:absolute; inset:0;
    background:linear-gradient(135deg,rgba(255,255,255,0.3),rgba(255,255,255,0));
    opacity:0; transition:opacity 0.3s;
}
.btn:hover::before { opacity:1; }

.btn-primary {
    background:linear-gradient(135deg, var(--primary), #1d4ed8);
    color:white; box-shadow:inset 0 2px 4px rgba(255,255,255,0.3), var(--shadow-blue);
    border: 1px solid rgba(255,255,255,0.2);
}
.btn-primary:hover { transform:translateY(-2px); box-shadow:inset 0 2px 4px rgba(255,255,255,0.4), 0 14px 30px rgba(37,99,235,0.4); }

.btn-orange {
    background:linear-gradient(135deg, var(--orange), var(--orange-hover));
    color:white; box-shadow:inset 0 2px 4px rgba(255,255,255,0.3), var(--shadow-orange);
    border: 1px solid rgba(255,255,255,0.2);
}
.btn-orange:hover { transform:translateY(-2px); box-shadow:inset 0 2px 4px rgba(255,255,255,0.4), 0 14px 30px rgba(249,115,22,0.4); }

.btn-glass {
    background: var(--card-bg); backdrop-filter:blur(16px) saturate(140%);
    border:1px solid var(--card-border); color:var(--dark);
    box-shadow:inset 0 2px 4px rgba(255,255,255,0.1), 0 8px 16px rgba(15,23,42,0.05);
}
.btn-glass:hover { background: var(--gray-50); transform:translateY(-2px); box-shadow:inset 0 2px 4px rgba(255,255,255,0.2), 0 12px 24px rgba(15,23,42,0.08); }

.btn-secondary {
    background: var(--card-bg); color:var(--secondary);
    border-color:var(--card-border); backdrop-filter:blur(8px);
}
.btn-secondary:hover { background: var(--white); border-color:var(--gray-300); }
.btn-danger { background:white; color:var(--danger); border-color:var(--danger); }
.btn-danger:hover { background:var(--danger); color:white; }

.btn svg { width:15px; height:15px; }

/* ===== USER GREETING ===== */
.user-greeting {
    display:flex; align-items:center; gap:0.6rem;
    background: var(--card-bg); backdrop-filter:blur(12px);
    padding:0.4rem 1rem 0.4rem 0.4rem; border-radius:50px;
    border:1px solid var(--header-border); cursor:pointer;
    transition:var(--transition); font-size:0.82rem; font-weight:600;
    color:var(--dark);
}
.user-greeting:hover { background: var(--white); box-shadow:var(--shadow-md); transform:translateY(-1px); }
.user-avatar {
    width:30px; height:30px; border-radius:50%; overflow:hidden;
    background:linear-gradient(135deg,var(--primary),var(--orange));
    color:white; display:flex; align-items:center; justify-content:center;
    font-size:0.75rem; font-weight:700; flex-shrink:0;
}
.user-avatar img { width:100%; height:100%; object-fit:cover; }

/* ===== CONTENT AREA ===== */
.content-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1.5rem 2rem;
    scroll-behavior: smooth;
}
.content-area::-webkit-scrollbar { width:6px; }
.content-area::-webkit-scrollbar-thumb { background:var(--gray-300); border-radius:10px; }



/* ===== VIEW TRANSITIONS ===== */
.view { display:none; }
.view.active {
    display:block;
    animation: viewIn 0.3s ease forwards;
}
@keyframes viewIn {
    from { opacity:0; }
    to { opacity:1; }
}

/* ===== NEW ADVANCED FORM CONTROLS ===== */
.select-wrapper {
    position:relative; width:100%;
}
.select-wrapper select {
    appearance:none; width:100%; padding-right:30px;
    background: var(--card-bg) url("data:image/svg+xml,%3Csvg width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") no-repeat calc(100% - 12px) center;
    backdrop-filter:blur(8px);
}
.select-wrapper select:focus {
    background-color: var(--white); border-color:var(--primary); box-shadow:var(--shadow-sm);
}

.segmented-control {
    display:flex; background: var(--gray-100); backdrop-filter:blur(8px);
    border-radius:12px; padding:4px; gap:4px;
    border:1px solid var(--gray-200);
}
.segmented-control input[type="radio"] { display:none; }
.segmented-control label {
    flex:1; text-align:center; padding:0.5rem; border-radius:10px; cursor:pointer;
    font-size:0.78rem; font-weight:600; color:var(--secondary); transition:var(--transition);
    display:flex; align-items:center; justify-content:center; gap:0.4rem;
}
.segmented-control input[type="radio"]:checked + label {
    background: var(--white); color:var(--dark); box-shadow:0 2px 8px rgba(0,0,0,0.06);
}
.segmented-control .dot {
    width:8px; height:8px; border-radius:50%; display:inline-block;
}

.input-icon-group { position:relative; }
.input-icon-group svg { color:var(--gray-400); }
.form-group label {
    display:flex; align-items:center; gap:0.4rem; font-weight:600; 
    color:var(--secondary); margin-bottom:0.4rem; font-size:0.78rem;
}
.form-group label svg { color:inherit; }

@keyframes fadeIn { from{opacity:0;} to{opacity:1;} }
@keyframes slideUp { from{opacity:0;transform:translateY(16px);} to{opacity:1;transform:translateY(0);} }
@keyframes spin { to{transform:rotate(360deg);} }
@keyframes pulse {
    0%{transform:scale(1);opacity:1;} 50%{transform:scale(1.2);opacity:0.7;} 100%{transform:scale(1);opacity:1;}
}
@keyframes cardFadeUp { from{opacity:0;transform:translateY(16px);} to{opacity:1;transform:translateY(0);} }
@keyframes modalScale { from{transform:scale(0.88);opacity:0;} to{transform:scale(1);opacity:1;} }
@keyframes slideInRight { from{transform:translateX(100%);opacity:0;} to{transform:translateX(0);opacity:1;} }
@keyframes shimmer { 0%{background-position:-200% center;} 100%{background-position:200% center;} }
@keyframes criticalPulse { 0%{box-shadow:0 0 0 0 rgba(239,68,68,0.3);} 70%{box-shadow:0 0 0 8px rgba(239,68,68,0);} 100%{box-shadow:0 0 0 0 rgba(239,68,68,0);} }

/* ===== DASHBOARD BANNER ===== */
.dashboard-banner {
    display:grid;
    grid-template-columns:repeat(auto-fit,minmax(150px,1fr));
    gap:1rem; margin-bottom:1.5rem;
}
.banner-stat {
    background: var(--card-bg); backdrop-filter:blur(12px);
    border:1px solid var(--card-border); border-radius:var(--radius-lg);
    padding:1rem 1.25rem; display:flex; align-items:center; gap:0.85rem;
    box-shadow:var(--shadow-sm); transition:var(--transition);
}
.banner-stat:hover { transform:translateY(-3px); box-shadow:var(--shadow-md); }
.banner-stat-icon {
    width:40px; height:40px; border-radius:12px;
    display:flex; align-items:center; justify-content:center; flex-shrink:0;
}
.banner-stat-icon svg { width:20px; height:20px; }
.banner-stat-label { font-size:0.65rem; color:var(--secondary); font-weight:600; text-transform:uppercase; letter-spacing:0.05em; }
.banner-stat-value { font-size:1.6rem; font-weight:800; color:var(--dark); line-height:1.1; }

/* Progress bar card */
.banner-progress { gap:0.75rem; flex-direction:column; align-items:flex-start !important; }
.progress-track-thin { height:6px; background:var(--gray-200); border-radius:10px; overflow:hidden; width:100%; }
.progress-fill-thin { height:100%; border-radius:10px; transition:width 1s cubic-bezier(0.4,0,0.2,1); }

/* ===== MODULE GRID ===== */
.module-grid {
    display:grid;
    grid-template-columns:repeat(auto-fill, minmax(min(100%,360px),1fr));
    gap:1.25rem; margin-bottom:2rem;
}

.module-card {
    background: var(--card-bg); backdrop-filter:blur(12px);
    border:1px solid var(--card-border); border-radius:var(--radius-xl);
    padding:1.5rem; display:flex; flex-direction:column; gap:1.1rem;
    transition:transform 0.25s ease, box-shadow 0.25s ease, background 0.3s ease, border 0.3s ease;
    position:relative; overflow:hidden;
    box-shadow:var(--shadow-sm);
    animation:cardFadeUp 0.4s ease backwards;
}
.module-card:nth-child(1){animation-delay:0.04s;}
.module-card:nth-child(2){animation-delay:0.08s;}
.module-card:nth-child(3){animation-delay:0.12s;}
.module-card:nth-child(4){animation-delay:0.16s;}
.module-card:nth-child(5){animation-delay:0.20s;}
.module-card:nth-child(6){animation-delay:0.24s;}
.module-card:nth-child(7){animation-delay:0.28s;}

.module-card::before {
    content:''; position:absolute; top:0; left:0;
    width:100%; height:4px; border-radius:var(--radius-xl) var(--radius-xl) 0 0;
}
.module-card:hover { transform:translateY(-4px); box-shadow:var(--shadow-md); }

.module-card-header { display:flex; justify-content:space-between; align-items:center; }
.module-title-row { display:flex; align-items:center; gap:0.75rem; }

.module-icon-wrap {
    width:42px; height:42px; border-radius:14px;
    display:flex; align-items:center; justify-content:center; flex-shrink:0;
}
.module-icon-wrap svg { width:22px; height:22px; }
.module-name { font-size:1rem; font-weight:700; color:var(--dark); }
.module-stats-pill {
    padding:0.2rem 0.7rem; background:var(--gray-100);
    border-radius:50px; font-size:0.7rem; font-weight:600; color:var(--secondary);
}

.module-progress-section { display:flex; flex-direction:column; gap:0.4rem; }
.progress-info { display:flex; justify-content:space-between; font-size:0.75rem; font-weight:600; color:var(--secondary); }
.progress-track { height:7px; background:var(--gray-100); border-radius:10px; overflow:hidden; }
.progress-fill { height:100%; border-radius:10px; transition:width 1s cubic-bezier(0.4,0,0.2,1); }

.task-list-mini {
    display:flex; flex-direction:column; gap:0.6rem;
    max-height:260px; overflow-y:auto; padding-right:0.2rem;
}
.task-list-mini::-webkit-scrollbar { width:3px; }
.task-list-mini::-webkit-scrollbar-thumb { background:var(--gray-300); border-radius:10px; }

.mini-task-item {
    padding:0.85rem 1rem; background:var(--gray-50);
    border-radius:var(--radius-md); font-size:0.825rem; font-weight:500;
    cursor:pointer; transition:var(--transition);
    border:1px solid var(--gray-100);
}
.mini-task-item:hover { background: var(--white); box-shadow:var(--shadow-sm); border-color:var(--gray-200); transform:translateX(2px); }
.mini-task-row { display:flex; justify-content:space-between; align-items:flex-start; gap:0.5rem; }
.mini-task-content { flex-grow:1; word-break:break-word; }

.mini-delete-btn {
    background:transparent; border:none; color:var(--gray-400);
    cursor:pointer; padding:3px; border-radius:6px; transition:var(--transition);
    opacity:0.2; flex-shrink:0;
}
.mini-task-item:hover .mini-delete-btn { opacity:1; }
.mini-delete-btn:hover { color:var(--danger); background:rgba(239,68,68,0.1); }
.mini-delete-btn svg { width:13px; height:13px; }

.mini-task-meta { display:flex; justify-content:space-between; margin-top:0.4rem; font-size:0.7rem; color:var(--gray-400); }

.status-badge {
    padding:0.15rem 0.55rem; border-radius:50px;
    font-size:0.62rem; font-weight:700; text-transform:uppercase;
}
.status-completed { background:#d1fae5; color:#065f46; }
.status-progress { background:#dbeafe; color:#1e40af; }
.status-notstarted { background:#fef3c7; color:#92400e; }

.priority-high { color:var(--danger); font-weight:700; }
.priority-medium { color:var(--warning); font-weight:700; }
.priority-low { color:var(--success); font-weight:700; }

.add-task-btn-small {
    width:100%; padding:0.7rem; background:transparent;
    border:2px dashed var(--gray-200); border-radius:var(--radius-md);
    color:var(--secondary); cursor:pointer; transition:var(--transition);
    font-weight:600; font-family:'Poppins',sans-serif; font-size:0.8rem;
    display:flex; align-items:center; justify-content:center; gap:0.5rem;
}
.add-task-btn-small:hover { border-color:var(--primary); color:var(--primary); background:var(--primary-light); }
.add-task-btn-small svg { width:15px; height:15px; }

/* ===== SUMMARY / ORGANIZATIONAL WORKING VIEW ===== */
.org-working-header {
    display:flex; align-items:center; gap:1rem;
    margin-bottom:1.5rem; flex-wrap:wrap;
}
.org-health-badge {
    display:flex; align-items:center; gap:0.5rem;
    padding:0.5rem 1.25rem; border-radius:50px;
    font-size:0.8rem; font-weight:700; background: var(--card-bg);
    box-shadow:var(--shadow-sm); border:1px solid var(--card-border);
}

.summary-stats {
    display:grid; grid-template-columns:repeat(4,1fr);
    gap:1rem; margin-bottom:1.5rem;
}
.stat-card {
    background: var(--card-bg); backdrop-filter:blur(12px);
    padding:1.25rem; border-radius:var(--radius-lg); box-shadow:var(--shadow-sm);
    border:1px solid var(--card-border); display:flex; flex-direction:column; gap:0.4rem;
}
.stat-header { display:flex; justify-content:space-between; color:var(--secondary); font-size:0.8rem; font-weight:600; }
.stat-value { font-size:1.9rem; font-weight:800; color:var(--dark); }
.stat-trend { font-size:0.7rem; font-weight:600; }
.trend-up { color:var(--success); } .trend-down { color:var(--danger); }

.summary-blocks {
    display:grid; grid-template-columns:repeat(auto-fill,minmax(280px,1fr)); gap:1rem;
}
.dept-summary-card {
    background: var(--card-bg); backdrop-filter:blur(12px);
    border:1px solid var(--card-border); border-radius:var(--radius-lg);
    padding:1.25rem; box-shadow:var(--shadow-sm);
    transition:transform 0.2s ease, box-shadow 0.2s ease;
    cursor:default; border-top:4px solid transparent;
    display:flex; flex-direction:column; gap:0.65rem;
    animation:cardFadeUp 0.4s ease backwards;
}
.dept-summary-card:hover { transform:translateY(-4px); box-shadow:var(--shadow-md); }

/* Pipeline Visualizer */
.pipeline-container {
    background: var(--card-bg); backdrop-filter:blur(12px);
    border:1px solid var(--card-border); border-radius:var(--radius-xl);
    padding:1.5rem; margin-bottom:1.5rem; box-shadow:var(--shadow-sm);
}
.pipeline-title { font-size:1rem; font-weight:700; color:var(--dark); margin-bottom:1.25rem; display:flex; align-items:center; gap:0.6rem; }
.pipeline-track { display:flex; align-items:center; gap:0; overflow-x:auto; padding-bottom:0.5rem; }
.pipeline-track::-webkit-scrollbar { height:3px; }
.pipeline-track::-webkit-scrollbar-thumb { background:var(--gray-300); border-radius:10px; }
.pipeline-dept {
    display:flex; flex-direction:column; align-items:center; gap:0.5rem;
    min-width:110px; position:relative;
}
.pipeline-dept:not(:last-child)::after {
    content:''; position:absolute; right:0; top:22px;
    width:100%; height:2px;
    background:linear-gradient(90deg, var(--gray-300), var(--gray-200));
    transform:translateX(50%); z-index:0; pointer-events:none;
}
.pipeline-node {
    width:44px; height:44px; border-radius:50%; border:3px solid transparent;
    display:flex; align-items:center; justify-content:center;
    background: var(--white); box-shadow:var(--shadow-sm); z-index:1; position:relative;
    transition:var(--transition);
}
.pipeline-node:hover { transform:scale(1.15); }
.pipeline-node svg { width:20px; height:20px; }
.pipeline-dept-label { font-size:0.62rem; font-weight:600; color:var(--secondary); text-align:center; max-width:90px; line-height:1.3; }
.pipeline-dept-score { font-size:0.7rem; font-weight:800; }

/* ===== AI INSIGHT VIEW ===== */
.ai-view-header {
    display:flex; justify-content:space-between; align-items:center;
    margin-bottom:1.5rem; flex-wrap:wrap; gap:1rem;
}
.ai-insight-panel {
    background: var(--card-bg); backdrop-filter:blur(16px);
    border:1px solid var(--card-border); border-radius:var(--radius-xl);
    padding:1.5rem; box-shadow:var(--shadow-sm); margin-bottom:1.25rem;
}
.ai-section-title {
    font-size:0.78rem; font-weight:700; text-transform:uppercase;
    letter-spacing:0.07em; color:var(--secondary); display:flex;
    align-items:center; gap:0.5rem; margin-bottom:1rem;
}
.vision-textarea {
    width:100%; min-height:80px; padding:0.85rem 1rem;
    border:1px solid var(--gray-200); border-radius:var(--radius-md);
    font-family:'Poppins',sans-serif; font-size:0.85rem; resize:vertical;
    transition:var(--transition); background:var(--gray-50); color:var(--dark);
}
.vision-textarea:focus { outline:none; border-color:var(--primary); box-shadow:0 0 0 3px var(--primary-light); background:white; }

.alignment-card {
    background:var(--gray-50); border-radius:var(--radius-md);
    padding:1rem; border:1px solid var(--gray-200);
    display:flex; flex-direction:column; gap:0.5rem;
    transition:var(--transition);
}
.alignment-card:hover { background:white; box-shadow:var(--shadow-sm); }
.alignment-dot { width:10px; height:10px; border-radius:50%; flex-shrink:0; margin-top:3px; }

/* ===== HR VIEW ===== */
.hr-header, .logs-header {
    display:flex; justify-content:space-between; align-items:center;
    margin-bottom:1.5rem; gap:1rem; flex-wrap:wrap;
}
.hr-header h2, .logs-header h2 { font-size:1.25rem; font-weight:700; color:var(--dark); }

.personal-grid {
    display:grid; grid-template-columns:repeat(auto-fill,minmax(min(100%,300px),1fr));
    gap:1.25rem; margin-top:1rem;
}
.person-card {
    background: var(--card-bg); backdrop-filter:blur(12px);
    border:1px solid var(--card-border); border-radius:var(--radius-xl);
    padding:1.5rem; display:flex; flex-direction:column; gap:0.85rem;
    transition:transform 0.2s ease, box-shadow 0.2s ease;
    animation:cardFadeUp 0.4s ease backwards; box-shadow:var(--shadow-sm);
}
.person-card:hover { box-shadow:var(--shadow-md); transform:translateY(-4px); }

.person-header { display:flex; align-items:center; gap:1rem; }
.person-avatar {
    width:52px; height:52px; background:linear-gradient(135deg,var(--primary),var(--orange));
    color:white; border-radius:16px; display:flex; align-items:center;
    justify-content:center; font-weight:700; font-size:1.3rem; flex-shrink:0;
    overflow:hidden; position:relative;
}
.person-avatar img { width:100%; height:100%; object-fit:cover; position:absolute; inset:0; }
.person-info h3 { font-size:1rem; margin-bottom:0.1rem; }
.person-info p { font-size:0.8rem; color:var(--secondary); }
.person-badge {
    padding:0.2rem 0.7rem; background:var(--primary-light);
    color:var(--primary); border-radius:50px; font-size:0.68rem; font-weight:700;
    display:inline-block;
}
.person-responsibility { font-size:0.8rem; color:var(--secondary); border-top:1px solid var(--gray-100); padding-top:0.75rem; }

/* Avatar upload */
.avatar-upload-wrap { position:relative; cursor:pointer; }
.avatar-upload-overlay {
    position:absolute; inset:0; border-radius:16px;
    background:rgba(0,0,0,0.45); display:flex; align-items:center;
    justify-content:center; opacity:0; transition:opacity 0.2s; color:white;
}
.avatar-upload-wrap:hover .avatar-upload-overlay { opacity:1; }
.avatar-upload-overlay svg { width:18px; height:18px; }

/* ===== LOGS VIEW ===== */
.logs-container {
    background: var(--card-bg); backdrop-filter:blur(12px);
    border-radius:var(--radius-xl); overflow-x:auto;
    box-shadow:var(--shadow-sm); border:1px solid var(--card-border);
}
.logs-table { width:100%; border-collapse:collapse; text-align:left; }
.logs-table th {
    padding:1rem 1.5rem; background: var(--gray-50);
    font-weight:700; font-size:0.7rem; text-transform:uppercase;
    color:var(--secondary); letter-spacing:0.06em;
}
.logs-table td { padding:0.9rem 1.5rem; border-bottom:1px solid var(--gray-100); font-size:0.85rem; color: var(--dark); }
.log-action-created { color:var(--success); font-weight:700; }
.log-action-updated { color:var(--info); font-weight:700; }
.log-action-deleted { color:var(--danger); font-weight:700; }

/* ===== MODAL ===== */
.modal {
    position:fixed; top:0; left:0; width:100%; height:100%;
    background:rgba(15,23,42,0.55); backdrop-filter:blur(6px);
    display:none; align-items:center; justify-content:center; z-index:1000; padding:1.5rem;
}
.modal.active { display:flex; animation:modalScale 0.3s cubic-bezier(0.34,1.56,0.64,1); }
.modal-content {
    background: #ffffff; backdrop-filter:none;
    width:100%; max-width:600px; border-radius:var(--radius-xl);
    box-shadow:var(--shadow-lg); display:flex; flex-direction:column;
    max-height:90vh; border:1px solid var(--card-border);
    color: var(--dark);
}
.dark-theme .modal-content {
    background: #1e293b;
}
.modal-header {
    padding:1.25rem 1.75rem; border-bottom:1px solid var(--gray-200);
    display:flex; justify-content:space-between; align-items:center;
}
.modal-header h2 { font-size:1.1rem; font-weight:700; }
button.close-modal:not(.btn) {
    background:var(--gray-100); border:none; width:30px; height:30px;
    border-radius:50%; font-size:1rem; color:var(--secondary); cursor:pointer;
    display:flex; align-items:center; justify-content:center; transition:var(--transition);
    line-height:1;
}
button.close-modal:not(.btn):hover { background:var(--danger); color:white; }

form { padding:1.5rem; overflow-y:auto; display:flex; flex-direction:column; gap:1rem; }
.form-group { display:flex; flex-direction:column; gap:0.4rem; }
.form-row { display:grid; grid-template-columns:1fr 1fr; gap:1rem; }
.form-row-triple { display:grid; grid-template-columns:1fr 1fr 1fr; gap:1rem; }

label { font-size:0.78rem; font-weight:600; color:var(--secondary); }
input, select, textarea {
    padding:0.7rem 1rem; border-radius:var(--radius-md);
    border:1px solid var(--gray-200); font-family:'Poppins',sans-serif;
    font-size:0.875rem; transition:var(--transition); background:var(--gray-50); color:var(--dark);
}
input:focus, select:focus, textarea:focus {
    outline:none; border-color:var(--primary);
    box-shadow:0 0 0 3px var(--primary-light); background: var(--white);
}
textarea { min-height:90px; resize:vertical; }
select { width:100%; }

.modal-footer {
    padding:1.25rem 1.75rem; border-top:1px solid var(--gray-200);
    display:flex; justify-content:flex-end; gap:0.75rem;
    position:sticky; bottom:-1.5rem; margin:1rem -1.5rem -1.5rem -1.5rem;
    background: var(--card-bg); backdrop-filter:blur(12px);
    z-index:10; border-radius:0 0 var(--radius-xl) var(--radius-xl);
}

/* Tags for persons */
.tag-list { display:flex; flex-wrap:wrap; gap:0.4rem; margin-bottom:0.4rem; }
.tag {
    background:linear-gradient(135deg,var(--primary),#1d4ed8); color:white;
    padding:0.2rem 0.65rem; border-radius:50px; font-size:0.75rem;
    display:flex; align-items:center; gap:0.4rem; font-weight:500;
}
.tag-remove { cursor:pointer; font-weight:bold; opacity:0.8; }
.tag-remove:hover { opacity:1; }

/* ===== NOTIFICATIONS ===== */
#notification-container {
    position:fixed; bottom:2rem; right:2rem; z-index:2000;
    display:flex; flex-direction:column; gap:0.6rem;
}
.notification {
    padding:0.85rem 1.25rem; background:rgba(255,255,255,0.92);
    backdrop-filter:blur(16px); border-radius:var(--radius-lg);
    box-shadow:var(--shadow-lg); display:flex; align-items:center;
    gap:0.65rem; border-left:4px solid var(--primary); min-width:280px;
    animation:slideInRight 0.3s ease-out; font-size:0.85rem; font-weight:500;
}
.notification svg { width:18px; height:18px; flex-shrink:0; }
.notification.success { border-left-color:var(--success); }
.notification.error { border-left-color:var(--danger); }
.notification.success svg { color:var(--success); }
.notification.error svg { color:var(--danger); }

/* ===== AI INSIGHTS CONTAINER ===== */
#ai-insights-container {
    background: var(--card-bg); backdrop-filter:blur(16px);
    border-radius:var(--radius-xl); border:1px solid var(--card-border);
    padding:1.5rem; box-shadow:var(--shadow-sm);
    margin-bottom:1.5rem; animation:slideUp 0.4s ease;
}

/* AI Status badge */
.ai-status-aligned { background:#d1fae5; color:#065f46; padding:0.2rem 0.65rem; border-radius:50px; font-size:0.68rem; font-weight:700; }
.ai-status-partial { background:#fef3c7; color:#92400e; padding:0.2rem 0.65rem; border-radius:50px; font-size:0.68rem; font-weight:700; }
.ai-status-misaligned { background:#fee2e2; color:#991b1b; padding:0.2rem 0.65rem; border-radius:50px; font-size:0.68rem; font-weight:700; }

/* Loading spinner */
.spinner {
    display:inline-block; width:28px; height:28px;
    border:3px solid var(--gray-200); border-top-color:var(--primary);
    border-radius:50%; animation:spin 0.8s linear infinite;
}
.spinner-small {
    display:inline-block; width:14px; height:14px;
    border:2px solid rgba(255,255,255,0.3); border-top-color:white;
    border-radius:50%; animation:spin 0.6s linear infinite;
    vertical-align: middle; margin-right: 0.4rem;
}
@keyframes spin { to { transform:rotate(360deg); } }

/* ===== STATUS INDICATOR ===== */
.dot { width:8px; height:8px; border-radius:50%; }
.dot.online { background-color:var(--success); box-shadow:0 0 8px var(--success); animation:pulse 2s infinite; }
.status-critical-pulse { animation:criticalPulse 2s infinite ease-in-out; }

.custom-scrollbar::-webkit-scrollbar { width:3px; }
.custom-scrollbar::-webkit-scrollbar-thumb { background:var(--gray-300); border-radius:10px; }

/* Empty state */
.empty-msg { color:var(--gray-400); font-size:0.8rem; text-align:center; padding:1rem 0; }

/* Section separator label */
.section-label {
    font-size:0.7rem; font-weight:700; text-transform:uppercase;
    letter-spacing:0.08em; color:var(--secondary);
    display:flex; align-items:center; gap:0.5rem; margin-bottom:0.75rem;
}
.section-label::after {
    content:''; flex:1; height:1px; background:var(--gray-200);
}

/* ===== ADMIN DASHBOARD GRID & RESPONSIVE FORMS ===== */
.admin-dept-grid {
    display: grid;
    grid-template-columns: minmax(280px, 1fr) 2fr;
    gap: 2rem;
    align-items: start;
}
.admin-bottom-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 450px), 1fr));
    gap: 2rem;
    align-items: start;
}
.admin-form-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}
.admin-form-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.75rem;
}
.admin-panel-wrapper {
    max-width: 1300px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

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

/* ── Tablet (≤ 900px) ── */
@media (max-width: 900px) {
    .module-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
    .summary-stats { grid-template-columns: 1fr 1fr; }
    .form-row-triple { grid-template-columns: 1fr 1fr; }
    .top-header { padding: 0.75rem 1.25rem; }
}

/* ── Small Tablet / Large Phone (≤ 768px) ── */
@media (max-width: 768px) {
    .admin-dept-grid {
        grid-template-columns: 1fr !important;
        gap: 1.5rem !important;
    }
    .admin-bottom-grid {
        grid-template-columns: 1fr !important;
        gap: 1.5rem !important;
    }
    .admin-form-row-2 {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }
    .admin-form-row-3 {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }
    .summary-stats { grid-template-columns: 1fr 1fr; }
    .form-row { grid-template-columns: 1fr !important; }
    .form-row-triple { grid-template-columns: 1fr !important; }
    .ai-view-header { flex-direction: column; align-items: flex-start; }
    .hr-header, .logs-header { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
    .hr-header > div:last-child, .logs-header > div:last-child { width: 100%; display: flex; justify-content: flex-end; }
    .logs-table th, .logs-table td { padding: 0.7rem 0.85rem; font-size: 0.78rem; }
    .modal-content { max-height: 95vh; }

    /* User greeting — hide name text, show avatar only */
    .user-greeting span:not(:first-child) { display: none; }
    .user-greeting { padding: 0.3rem; border-radius: 50%; width: 38px; height: 38px; justify-content: center; }
}

/* ── Mobile (≤ 600px) ── */
@media (max-width: 600px) {
    /* Layout: bottom tab bar */
    .app-container { flex-direction: column; padding-bottom: 70px; }

    .sidebar {
        width: 100% !important;
        height: 70px;
        flex-direction: row !important;
        position: fixed; bottom: 0; left: 0; top: auto;
        padding: 0 !important;
        border-radius: 20px 20px 0 0;
        border-right: none;
        border-top: none;
        box-shadow: 0 -4px 20px rgba(15,23,42,0.15);
        z-index: 1500;
        overflow: hidden;
    }

    /* Scrollable horizontal tab bar for 8+ items */
    .sidebar-nav {
        flex-direction: row !important;
        width: 100%;
        height: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        justify-content: flex-start !important;
        gap: 0 !important;
        align-items: center;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        padding: 0 0.5rem;
        scrollbar-width: none;
        margin: 0;
    }
    .sidebar-nav::-webkit-scrollbar { display: none; }

    .sidebar-header,
    .sidebar-footer,
    .sidebar-toggle-btn,
    .logo-text { display: none !important; }

    /* Each nav item in tab bar — remove any inline styles that cause overlap */
    .nav-item {
        flex: 0 0 auto !important;
        flex-direction: column !important;
        gap: 0.15rem !important;
        padding: 0.35rem 0.75rem !important;
        background: none !important;
        box-shadow: none !important;
        color: var(--gray-400) !important;
        align-items: center;
        justify-content: center;
        min-width: 64px;
        max-width: 80px;
        scroll-snap-align: start;
        border-radius: 12px;
        /* Override any inline border/margin from admin nav-item */
        border-top: none !important;
        margin-top: 0 !important;
        padding-top: 0.35rem !important;
    }
    .nav-item .nav-icon { width: 22px; height: 22px; flex-shrink: 0; }
    .nav-item .nav-icon svg { width: 20px; height: 20px; }
    .nav-item span:not(.nav-icon) {
        display: block !important;
        font-size: 0.55rem !important;
        font-weight: 600;
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 64px;
    }
    .nav-item.active {
        color: var(--primary) !important;
        background: var(--primary-light) !important;
    }

    /* Show logout in the mobile tab bar */
    .nav-logout-mobile {
        display: flex !important;
        flex: 0 0 auto !important;
        flex-direction: column !important;
        gap: 0.15rem !important;
        padding: 0.35rem 0.75rem !important;
        background: none !important;
        box-shadow: none !important;
        color: #f87171 !important;
        align-items: center;
        justify-content: center;
        min-width: 64px;
        max-width: 80px;
        scroll-snap-align: start;
        border-radius: 12px;
        border-top: none !important;
        margin-top: 0 !important;
        padding-top: 0.35rem !important;
        cursor: pointer;
    }

    /* Main content */
    .main-content { height: calc(100vh - 70px); width: 100%; overflow: hidden; }
    .content-area { padding: 0.85rem !important; padding-bottom: 1rem !important; }

    /* Top header — prevent overlap of buttons */
    .top-header {
        padding: 0.6rem 0.75rem !important;
        flex-direction: column !important;
        gap: 0.5rem;
        align-items: stretch !important;
    }
    .header-left { display: none; } /* Hide title on mobile — saves space */
    .header-actions {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 0.35rem;
        flex-wrap: nowrap;
        overflow: hidden;
    }
    /* Search bar takes remaining space but won't push buttons off-screen */
    .search-bar { flex: 1 1 auto; min-width: 0; max-width: none; }
    .search-bar input { min-width: 0; }

    /* Hide text labels on all header buttons — icon only */
    #upload-doc-global span { display: none; }
    #upload-doc-global { padding: 0.5rem; width: 36px; height: 36px; min-width: 36px; justify-content: center; border-radius: 10px; flex-shrink: 0; margin-right: 0 !important; }
    #add-task-global span { display: none; }
    #add-task-global { padding: 0.5rem; width: 36px; height: 36px; min-width: 36px; justify-content: center; border-radius: 10px; flex-shrink: 0; }

    /* Theme toggle — compact */
    #theme-toggle { width: 36px !important; height: 36px !important; min-width: 36px; padding: 0.4rem !important; flex-shrink: 0; }

    /* User greeting — icon only */
    .user-greeting { padding: 0.25rem; border-radius: 50%; width: 36px; height: 36px; min-width: 36px; justify-content: center; flex-shrink: 0; }
    .user-greeting span:not(:first-child) { display: none; }
    #header-user-name { display: none !important; }

    /* Grids → single column */
    .module-grid,
    .personal-grid { grid-template-columns: 1fr !important; }
    .summary-stats { grid-template-columns: 1fr 1fr !important; }
    .dashboard-banner { grid-template-columns: 1fr 1fr !important; }

    /* Form layout */
    .form-row,
    .form-row-triple { grid-template-columns: 1fr !important; }

    /* Logs & Documents tables — horizontal scroll */
    .logs-container { border-radius: var(--radius-lg); overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .logs-table { min-width: 540px; }
    .logs-table th, .logs-table td { padding: 0.65rem 0.85rem; font-size: 0.75rem; white-space: nowrap; }

    /* Modals — bottom sheet style, no overlap */
    .modal { padding: 0; align-items: flex-end; }
    .modal-content {
        max-width: 100% !important;
        width: 100% !important;
        max-height: 90vh;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0 !important;
        margin: 0;
    }
    /* Fix modal footer negative margin causing overflow on mobile */
    .modal-footer {
        margin: 0 !important;
        padding: 1rem 1.25rem !important;
        position: sticky;
        bottom: 0;
        border-radius: 0 !important;
    }
    /* Modal form — ensure scrollable within bounds */
    .modal-content form {
        padding: 1rem 1.25rem;
        overflow-y: auto;
        max-height: calc(90vh - 130px);
        -webkit-overflow-scrolling: touch;
    }

    /* HR header / Logs header stacking */
    .hr-header, .logs-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
        margin-bottom: 1rem;
    }
    .hr-header > div:last-child,
    .logs-header > div:last-child { width: 100%; display: flex; gap: 0.5rem; justify-content: flex-start; flex-wrap: wrap; }

    /* AI view */
    .ai-view-header { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
    .ai-view-header > div:last-child { width: 100%; display: flex; gap: 0.5rem; justify-content: flex-start; }

    /* Admin Panel — full width on mobile */
    #admin-view .ai-insight-panel { max-width: 100% !important; }
    #admin-view .hr-header { margin-bottom: 1rem; }
    /* Admin wrapper — full width, reduced gap */
    .admin-panel-wrapper { max-width: 100% !important; gap: 1.25rem !important; }
    /* Dept list — shorter on mobile so it doesn't fill whole screen */
    #dept-admin-list { max-height: 220px !important; }
    #division-admin-list { max-height: 130px !important; }

    /* Document center — stack search and filter */
    #documents-view .ai-insight-panel > div { flex-direction: column !important; gap: 0.75rem !important; }
    #documents-view .form-group { flex: unset !important; width: 100% !important; }

    /* Notifications — above bottom bar */
    #notification-container { bottom: 80px; right: 0.75rem; left: 0.75rem; }
    .notification { min-width: unset; width: 100%; font-size: 0.8rem; padding: 0.7rem 1rem; }

    /* Banner cards — tighter on mobile */
    .banner-stat { padding: 0.75rem 0.85rem; gap: 0.6rem; }
    .banner-stat-icon { width: 36px; height: 36px; }
    .banner-stat-value { font-size: 1.3rem; }
    .banner-stat-label { font-size: 0.6rem; }

    /* Person card */
    .person-card { padding: 1.1rem; }

    /* Pipeline — scrollable horizontally, no overflow */
    .pipeline-container { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-lg); }
    .pipeline-viz-wrap { padding: 1rem; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .pipeline-track-wrap { min-width: 700px; }
    .pipeline-viz-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
    .pipeline-org-health { text-align: left; }

    /* Segmented controls — smaller on mobile */
    .segmented-control { gap: 2px; padding: 3px; }
    .segmented-control label { font-size: 0.68rem; padding: 0.35rem 0.15rem; }
    .segmented-control .dot { width: 6px; height: 6px; }

    /* AI insight panels — prevent horizontal overflow */
    .ai-insight-panel { padding: 1rem; overflow: hidden; word-wrap: break-word; overflow-wrap: break-word; }

    /* Invoicing iframe — account for bottom bar */
    #invoicing-view { height: calc(100vh - 140px) !important; }

    /* Vision/mission textareas — proper sizing on mobile */
    .vision-textarea { min-height: 60px; font-size: 0.8rem; }

    /* Tag list — prevent overflow */
    .tag-list { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: wrap; }

    /* Module card — prevent content overflow */
    .module-card { padding: 1.1rem; }
    .module-card-header { flex-wrap: wrap; gap: 0.5rem; }
    .module-name { font-size: 0.9rem; word-break: break-word; }

    /* Stat card on summary page — prevent overlap */
    .stat-card { padding: 1rem; }
    .stat-value { font-size: 1.5rem; }

    /* ── Content OS Mobile Fixes ── */
    /* Toolbar: stack vertically on mobile */
    .cos-toolbar {
        flex-direction: column !important;
        align-items: stretch !important;
        padding: 0.75rem !important;
        gap: 0.65rem !important;
        border-radius: 12px !important;
        margin-bottom: 1rem !important;
    }
    .cos-toolbar > div { flex: unset !important; width: 100% !important; min-width: unset !important; }
    .cos-toolbar select { width: 100% !important; }
    .cos-toolbar > div:last-child {
        display: grid !important;
        grid-template-columns: 1fr 1fr 1fr !important;
        gap: 0.4rem !important;
    }
    .cos-toolbar > div:last-child input {
        grid-column: 1 / -1 !important;
        width: 100% !important;
    }
    .cos-toolbar > div:last-child button {
        width: 100% !important;
        justify-content: center !important;
        font-size: 0.78rem !important;
        padding: 0.5rem 0.25rem !important;
    }

    /* Analytics grids — single column on mobile */
    .cos-grid-2 {
        grid-template-columns: 1fr !important;
    }
    /* Checkbox grid stays 2-col since labels are short */
    .cos-checkbox-grid {
        grid-template-columns: 1fr 1fr !important;
    }

    /* Content OS cards — reduce padding */
    #content-os-view .module-card {
        padding: 1rem !important;
        border-radius: 12px !important;
    }
    #content-os-view h2 {
        font-size: 1rem !important;
        margin-bottom: 1rem !important;
    }
    #content-os-view input,
    #content-os-view select,
    #content-os-view textarea {
        font-size: 0.85rem !important;
    }

    /* KPI summary box — readable on small screen */
    #cos-ig-kpis {
        font-size: 0.78rem !important;
        padding: 0.75rem !important;
    }
}

/* ── Extra Small (≤ 480px) ── */
@media (max-width: 480px) {
    .summary-stats { grid-template-columns: 1fr !important; }
    .dashboard-banner { grid-template-columns: 1fr !important; }
    .nav-item { min-width: 54px; max-width: 68px; padding: 0.25rem 0.4rem !important; }
    .nav-item span:not(.nav-icon) { font-size: 0.5rem !important; max-width: 54px; }
    .content-area { padding: 0.5rem !important; }
    .modal-content { max-height: 95vh; }
    .banner-stat-value { font-size: 1.1rem; }
    .banner-stat { padding: 0.65rem 0.75rem; }
    .banner-stat-icon { width: 32px; height: 32px; }

    /* Header actions — even more compact */
    .header-actions { gap: 0.25rem; }
    .search-bar { padding: 0.35rem 0.75rem; }
    #upload-doc-global, #add-task-global, #theme-toggle { width: 34px !important; height: 34px !important; min-width: 34px; }
    .user-greeting { width: 34px; height: 34px; min-width: 34px; }

    /* Person card actions — stack buttons */
    .person-card > div:last-child { flex-direction: column; gap: 0.35rem; }
    .person-card > div:last-child .btn { width: 100%; justify-content: center; }

    /* AI results — tighter layout */
    .ai-insight-panel { padding: 0.85rem; }
}

/* ── Tiny screens (≤ 360px) ── */
@media (max-width: 360px) {
    .nav-item { min-width: 48px; max-width: 60px; }
    .nav-item span:not(.nav-icon) { font-size: 0.48rem !important; }
    .content-area { padding: 0.4rem !important; }
    .module-card { padding: 0.85rem; border-radius: var(--radius-lg); }
    .banner-stat { padding: 0.5rem 0.6rem; border-radius: var(--radius-md); }
    .stat-value { font-size: 1.3rem; }
}


/* ===== PIPELINE VISUALIZER ===== */
.pipeline-viz-wrap {
    background: var(--card-bg);
    border-radius: var(--radius-xl);
    border: 1px solid var(--card-border);
    box-shadow: var(--shadow-md);
    padding: 1.5rem 1.5rem 2rem;
    overflow-x: auto;
    position: relative;
    color: var(--dark);
}
.pipeline-viz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}
.pipeline-legend {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.legend-dot {
    width: 10px; height: 10px; border-radius: 50%;
    display: inline-block; margin-right: 0.35rem;
}
.legend-item { display: flex; align-items: center; }
.pipeline-org-health {
    text-align: right;
    line-height: 1.2;
}
.pipeline-org-health .label {
    font-size: 0.6rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.1em; color: var(--secondary);
}
.pipeline-org-health .value {
    font-size: 1.35rem; font-weight: 900; color: var(--danger);
}
.pipeline-org-health .health-bar-wrap {
    width: 120px; height: 5px; background: var(--gray-100);
    border-radius: 10px; overflow: hidden; margin-top: 0.25rem;
}
.pipeline-org-health .health-bar-fill {
    height: 100%; border-radius: 10px;
    transition: width 1s ease;
}

/* Main rope track */
.pipeline-track-wrap {
    min-width: 900px;
    position: relative;
    padding-bottom: 2rem;
}
.pipeline-rope-row {
    display: flex;
    align-items: center;
    position: relative;
    padding: 0 2rem;
    margin-bottom: 0;
}
/* Horizontal rope line */
.pipeline-rope-line {
    position: absolute;
    top: 50%;
    left: 2rem;
    right: 2rem;
    height: 6px;
    transform: translateY(-50%);
    border-radius: 3px;
    z-index: 0;
}
/* Each department column */
.pipeline-dept-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 1;
}
/* Big circle node */
.pipeline-node-circle {
    width: 80px; height: 80px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    flex-direction: column;
    font-size: 0.65rem; font-weight: 800;
    color: #fff;
    text-align: center;
    line-height: 1.25;
    box-shadow: 0 6px 20px rgba(0,0,0,0.2);
    cursor: default;
    position: relative;
    z-index: 2;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    padding: 0.4rem;
    word-break: break-word;
}
.pipeline-node-circle:hover {
    transform: scale(1.07);
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
.pipeline-node-circle svg {
    width: 20px; height: 20px; margin-bottom: 0.2rem;
    flex-shrink: 0;
}
.pipeline-node-circle .circle-label {
    font-size: 0.6rem; font-weight: 800; line-height: 1.2;
    max-width: 64px; text-align: center;
}
.pipeline-node-circle .circle-pct {
    font-size: 0.75rem; font-weight: 900; margin-top: 0.1rem;
    opacity: 0.9;
}

/* Vertical rope drop */
.pipeline-drop {
    width: 3px;
    background: linear-gradient(to bottom, rgba(150,150,150,0.5), rgba(150,150,150,0.1));
    border-radius: 2px;
    position: relative;
    z-index: 1;
}
/* Task pill cards */
.pipeline-tasks-col {
    display: flex; flex-direction: column;
    align-items: center; gap: 0.5rem;
    position: relative;
    z-index: 2;
    width: 100%;
    padding: 0 0.4rem;
}
.pipeline-task-pill {
    width: 100%;
    background: var(--card-bg);
    border: 1.5px solid var(--gray-200);
    border-radius: 14px;
    padding: 0.5rem 0.65rem;
    font-size: 0.7rem;
    box-shadow: 0 2px 8px rgba(15,23,42,0.06);
    display: flex; flex-direction: column; gap: 0.25rem;
    cursor: pointer;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
    position: relative;
}
.pipeline-task-pill:hover {
    box-shadow: 0 6px 18px rgba(15,23,42,0.12);
    transform: translateY(-2px);
}
.pipeline-task-pill .pill-name {
    font-weight: 700; color: var(--dark);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    max-width: 100%;
}
.pipeline-task-pill .pill-meta {
    display: flex; justify-content: space-between; align-items: center;
    font-size: 0.63rem; color: var(--secondary);
    gap: 0.3rem;
}
.pill-status-dot {
    width: 7px; height: 7px; border-radius: 50%;
    display: inline-block; flex-shrink: 0;
}
.pipeline-empty {
    font-size: 0.68rem; color: var(--gray-400);
    text-align: center; padding: 0.5rem;
    font-style: italic;
}

/* Print button */
.btn-print {
    display: inline-flex; align-items: center; gap: 0.4rem;
    background: var(--gray-100); border: 1px solid var(--gray-200);
    border-radius: var(--radius-md); padding: 0.5rem 1rem;
    font-size: 0.78rem; font-weight: 700; color: var(--dark);
    cursor: pointer; transition: var(--transition);
    font-family: 'Poppins', sans-serif;
}
.btn-print:hover { background: var(--gray-200); }

/* ===== PRINT STYLES ===== */
@media print {
    body {
        background: #fff !important;
        overflow: visible !important;
        height: auto !important;
    }
    /* Hide layout and UI controls */
    .sidebar, .top-header, .btn-print, .pipeline-viz-header .btn-print,
    .modal, #notification-container, .header-actions, .nav-item,
    .add-task-btn-small, .add-task-btn, .mini-delete-btn,
    .ai-view-header button, .hr-header button, .modal-footer { display: none !important; }

    .app-container { display: block !important; }
    .main-content { height: auto !important; overflow: visible !important; width: 100% !important; margin: 0 !important; padding: 0 !important; }
    .content-area { padding: 0 !important; height: auto !important; overflow: visible !important; }
    
    /* Ensure the active view is visible */
    .view { display: none !important; opacity: 1 !important; transform: none !important; }
    .view.active { display: block !important; }

    /* Specific overrides for pipeline/summary */
    #summary-view { display: block !important; page-break-inside: avoid; }
    .pipeline-viz-wrap { box-shadow: none !important; border: 1px solid #eee !important; overflow: visible !important; }
    .pipeline-track-wrap { min-width: unset !important; overflow: visible !important; }
    .pipeline-rope-row { display: flex !important; flex-wrap: nowrap !important; }
    .pipeline-task-pill { box-shadow: none !important; border: 1px solid #ddd !important; page-break-inside: avoid; }
    
    /* Ensure cards are visible */
    .module-card, .person-card {
        break-inside: avoid;
        box-shadow: none !important;
        border: 1px solid #eee !important;
        background: #fff !important;
    }

    #hr-view.active { display: block !important; }
    .personal-grid { 
        display: grid !important; 
        grid-template-columns: 1fr 1fr !important;
        gap: 1rem !important;
    }

    @page {
        size: A4 landscape;
        margin: 10mm;
    }
}

/* Company Switcher Dropdown Styles */
.company-dropdown-panel {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 200px;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    z-index: 2000;
    overflow: hidden;
}
.dark-theme .company-dropdown-panel {
    background: #1e293b;
    border-color: #334155;
}

.company-dropdown-item {
    padding: 0.6rem 0.85rem;
    font-size: 0.82rem;
    cursor: pointer;
    color: var(--dark);
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: transparent;
    transition: var(--transition);
}
.company-dropdown-item:hover {
    background: var(--gray-50);
}
.company-dropdown-item.active {
    background: rgba(99,102,241,0.1);
    font-weight: 700;
}
.dark-theme .company-dropdown-item {
    border-bottom-color: #334155;
}
.dark-theme .company-dropdown-item:hover {
    background: rgba(255,255,255,0.05);
}
.dark-theme .company-dropdown-item.active {
    background: rgba(99,102,241,0.25);
}
