/* Layout Styles */

/* Top Navigation */
.topnav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background-color: white;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    z-index: 100;
}

.topnav-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.sidebar-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
}

.sidebar-toggle:hover {
    color: var(--primary-color);
}

.topnav-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 600;
    font-size: 1.125rem;
    color: var(--primary-color);
}

.topnav-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.topnav-item {
    position: relative;
}

.topnav-icon {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    position: relative;
}

.topnav-icon:hover {
    color: var(--primary-color);
}

.badge-dot {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    background-color: var(--danger-color);
    border-radius: 50%;
    border: 2px solid white;
}

.notif-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    background-color: var(--danger-color);
    color: white;
    border-radius: 9999px;
    border: 2px solid white;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.notif-mark-all-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
}
.notif-mark-all-btn:hover { text-decoration: underline; }

.notification-item { cursor: pointer; }
.notification-item.unread { background-color: #eff6ff; }
.notification-item.unread:hover { background-color: #dbeafe; }

.notif-empty-state {
    padding: 1.5rem 1rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.8125rem;
}

.topnav-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-md);
    transition: background-color 0.2s;
}

.topnav-user:hover {
    background-color: var(--bg-secondary);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}

.user-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

/* Dropdown */
.dropdown {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    background-color: white;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    display: none;
    z-index: 1000;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-menu-right {
    right: 0;
    left: auto;
}

.dropdown-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.dropdown-body {
    padding: 0.5rem 0;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    color: var(--text-primary);
    transition: background-color 0.2s;
}

.dropdown-item:hover {
    background-color: var(--bg-secondary);
}

.dropdown-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 0.5rem 0;
}

/* Notification Item */
.notification-item {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s;
}

.notification-item:hover {
    background-color: var(--bg-secondary);
}

.notification-item:last-child {
    border-bottom: none;
}

.notification-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.notification-content {
    flex: 1;
}

.notification-content p {
    margin: 0;
    font-size: 0.8125rem;
}

/* Sidebar Navigation */
.sidebar {
    position: fixed;
    top: 60px;
    left: 0;
    bottom: 0;
    width: 260px;
    background-color: #1e40af;
    border-right: 1px solid var(--border-color);
    z-index: 90;
    transition: transform 0.3s ease, width 0.25s cubic-bezier(.4,0,.2,1);
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar.hidden {
    transform: translateX(-100%);
}

/* ── Mini (icon-only) collapsed mode ─────────────────────────────────────
   Replaces a full sidebar hide with a slim icon rail — nav stays reachable
   with a single click, matching the collapse pattern used by VS Code /
   Notion / Microsoft 365 rather than hiding navigation entirely. */
.sidebar.mini {
    width: 72px;
    overflow: visible;
}
.sidebar.mini .sidebar-link span,
.sidebar.mini .sidebar-group-toggle span,
.sidebar.mini .sidebar-group-chevron {
    display: none;
}
.sidebar.mini .sidebar-link,
.sidebar.mini .sidebar-group-toggle {
    justify-content: center;
    padding: 0.75rem;
    position: relative;
}
.sidebar.mini .sidebar-submenu {
    display: none;
}
/* Expanded group inside mini mode becomes a flyout panel to the right of the icon rail */
.sidebar.mini .sidebar-group.open .sidebar-submenu {
    display: block;
    position: absolute;
    left: 72px;
    width: 220px;
    max-height: none;
    background-color: #1e3a8a;
    border-radius: 0 0.5rem 0.5rem 0;
    box-shadow: var(--shadow-lg, 0 10px 25px rgba(0,0,0,.2));
    z-index: 95;
}
.sidebar.mini .sidebar-group.open .sidebar-submenu .sidebar-sublink span {
    display: inline;
}
.sidebar.mini .sidebar-group.open .sidebar-submenu .sidebar-sublink {
    padding: 0.6rem 1rem;
}

/* Custom tooltip shown on hover while collapsed — content supplied via
   data-tooltip, populated once at runtime from each link's existing label
   (see includes/header.php), no per-link markup changes needed. */
.sidebar.mini .sidebar-link[data-tooltip]:hover::after,
.sidebar.mini .sidebar-group-toggle[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 100%;
    top: 50%;
    margin-left: 0.5rem;
    transform: translateY(-50%);
    background: #1e293b;
    color: #fff;
    padding: 0.4rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    z-index: 200;
    pointer-events: none;
    box-shadow: var(--shadow-lg, 0 10px 25px rgba(0,0,0,.2));
    animation: sidebarTooltipIn 0.15s ease forwards;
}
@keyframes sidebarTooltipIn {
    from { opacity: 0; transform: translateY(-50%) translateX(-4px); }
    to   { opacity: 1; transform: translateY(-50%) translateX(0); }
}

/* Mobile overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 89;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0 !important;
    }
    
    .topnav-user .user-name {
        display: none;
    }
}

.sidebar-content {
    padding: 1rem 0;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    font-size: 0.875rem;
    color: #ffffff;
    background-color: #1e40af;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.sidebar-link:hover {
    background-color: #1e3a8a;
    color: #ffffff;
}

.sidebar-link.active {
    background-color: #1d4ed8;
    color: #ffffff;
    border-left-color: #93c5fd;
    font-weight: 500;
}

/* ── Collapsible sidebar groups (e.g. Secretariat) ───────────────────────── */
.sidebar-group-toggle {
    width: 100%;
    border: none;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
}

.sidebar-group-chevron {
    margin-left: auto;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.sidebar-group.open .sidebar-group-chevron {
    transform: rotate(90deg);
}

.sidebar-submenu {
    max-height: 0;
    overflow: hidden;
    background-color: #1e3a8a;
    transition: max-height 0.25s ease;
}

.sidebar-group.open .sidebar-submenu {
    max-height: 600px;
}

.sidebar-sublink {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 1.5rem 0.6rem 2.75rem;
    font-size: 0.8125rem;
    color: #dbeafe;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.sidebar-sublink:hover {
    background-color: #1e2f6e;
    color: #ffffff;
}

.sidebar-sublink.active {
    background-color: #1d4ed8;
    color: #ffffff;
    border-left-color: #93c5fd;
    font-weight: 500;
}

/* Main Content */
.main-content {
    margin-top: 60px;
    margin-left: 260px;
    padding: 2rem;
    min-height: calc(100vh - 60px);
    transition: margin-left 0.3s ease;
}

/* Matches .sidebar.mini's 72px width — content shifts to fill the space
   freed by the collapsed rail rather than the old full-hide behavior. */
.main-content.expanded {
    margin-left: 72px;
}

/* Page Header */
.page-header {
    margin-bottom: 2rem;
}

.page-header h1 {
    font-size: 1.875rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.page-header-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 80px;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.toast {
    background-color: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 1rem 1.25rem;
    min-width: 300px;
    max-width: 400px;
    border-left: 4px solid;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    animation: slideIn 0.3s cubic-bezier(.34,1.56,.64,1);
    /* JS (app.js Toast.show) sets opacity/transform inline right before
       removing the element — this transition is what makes that fade+slide
       out smoothly instead of snapping instantly. */
    transition: opacity 0.3s ease, transform 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast.success {
    border-left-color: var(--success-color);
}

.toast.error {
    border-left-color: var(--danger-color);
}

.toast.warning {
    border-left-color: var(--warning-color);
}

.toast.info {
    border-left-color: var(--info-color);
}

.toast-icon {
    flex-shrink: 0;
}

.toast-content {
    flex: 1;
}

.toast-title {
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
}

.toast-message {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.toast-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    line-height: 1;
}

.toast-close:hover {
    color: var(--text-primary);
}

/* Responsive */
@media (max-width: 1024px) {
    /* Below desktop width, use the same overlay-drawer pattern as mobile
       (.active) instead of the mini icon-rail — matches includes/header.php's
       toggleSidebar(), which only applies .mini above 1024px. */
    .sidebar {
        transform: translateX(-100%);
        width: 260px;
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .main-content.expanded {
        margin-left: 0;
    }

    .user-name {
        display: none;
    }
}

@media (max-width: 640px) {
    .topnav {
        padding: 0 1rem;
    }
    
    .topnav-brand span {
        display: none;
    }
    
    .page-header h1 {
        font-size: 1.5rem;
    }
    
    .main-content {
        padding: 1rem;
    }
}