/* Top Bar */
.topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-height);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 100;
}

.topbar-left, .topbar-right, .logo, .auth-buttons {
    display: flex;
    align-items: center;
}

.topbar-left { gap: 16px; }
.topbar-right { gap: 12px; }
.logo { gap: 10px; text-decoration: none; }
.auth-buttons { gap: 12px; }

.menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px; height: 40px;
    background: none; border: none;
    border-radius: var(--radius-sm);
    cursor: pointer; color: var(--color-text);
}
.menu-toggle:hover { background: var(--color-hover); }
.menu-toggle svg { width: 24px; height: 24px; }

.logo-mark {
    width: 36px; height: 36px;
    background: var(--color-primary);
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
}
.logo-mark svg { width: 20px; height: 20px; fill: #ffffff; }
.logo-text { font-size: 1.125rem; font-weight: 600; color: var(--color-text); }

/* Icon Buttons (Top Bar) - UPDATED */
.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 6px; /* or var(--radius-sm) */
    color: var(--color-text-muted, #6b7280);
    text-decoration: none; /* Removes link underline */
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    padding: 0;
}
.icon-btn:hover {
    background: var(--color-hover, #f3f4f6);
    color: var(--color-text, #111827);
}
.icon-btn svg {
    width: 20px;
    height: 20px;
}

/* User Menu */
.user-menu-container { position: relative; display: none; }
.user-avatar-btn {
    width: 36px; height: 36px;
    border-radius: 50%; border: none;
    cursor: pointer; overflow: hidden;
    background: var(--color-primary-light);
    color: var(--color-primary);
    font-weight: 600; font-size: 0.875rem;
    display: flex; align-items: center; justify-content: center;
    padding: 0; transition: box-shadow 0.15s;
}
.user-avatar-btn:hover, .user-menu-container.open .user-avatar-btn {
    box-shadow: 0 0 0 2px var(--color-border);
}
.user-avatar-btn img { width: 100%; height: 100%; object-fit: cover; }

.user-dropdown {
    display: none;
    position: absolute; right: 0; top: calc(100% + 8px);
    width: 220px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    padding: 6px; z-index: 1000;
    flex-direction: column; gap: 2px;
}
.user-menu-container.open .user-dropdown { display: flex; }

.user-dropdown-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    font-size: 0.875rem; color: var(--color-text);
    text-decoration: none; border-radius: var(--radius-sm);
    transition: background 0.15s; cursor: pointer;
    background: none; border: none; width: 100%; text-align: left;
    font-family: var(--font-family);
}
.user-dropdown-item:hover { background: var(--color-hover); }
.user-dropdown-item svg { width: 18px; height: 18px; color: var(--color-text-muted); flex-shrink: 0; }
.user-dropdown-divider { height: 1px; background: var(--color-border); margin: 4px 0; }

/* Sidebar */
.sidebar {
    position: fixed; top: var(--topbar-height); left: 0; bottom: 0;
    width: var(--sidebar-width);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    z-index: 90; display: flex; flex-direction: column;
}
.sidebar-content { padding: 12px 10px; flex: 1; overflow-y: auto; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--color-border); background: var(--color-surface); flex-shrink: 0; }
.sidebar-legal { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-bottom: 6px; }
.legal-link { font-size: 0.688rem; color: var(--color-text-muted); text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 2px; }
.legal-link:hover { color: var(--color-text); }
.sidebar-copyright { font-size: 0.625rem; color: #9ca3af; }

.sidebar-section { margin-bottom: 8px; }
.sidebar-divider { height: 1px; background: var(--color-border); margin: 12px 0; }

.sidebar-section-header {
    display: flex; align-items: center; justify-content: space-between;
    padding-right: 8px; cursor: pointer; user-select: none;
}
.sidebar-section-header:hover .sidebar-label, .sidebar-section-header:hover .collapse-icon { color: var(--color-text); }
.collapse-icon { width: 14px; height: 14px; color: var(--color-text-muted); transition: transform 0.2s ease; }
.sidebar-section.collapsed .collapse-icon { transform: rotate(-90deg); }
.sidebar-section.collapsed nav { display: none; }
.sidebar-label {
    padding: 6px 12px; font-size: 0.688rem; font-weight: 600;
    color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.05em; flex: 1;
}

/* Navigation Links */
.nav-list { list-style: none; }
.nav-item { margin-bottom: 1px; }
.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 12px; font-size: 0.875rem; color: var(--color-text);
    text-decoration: none; transition: background 0.15s;
    border-left: 3px solid transparent; margin-left: -10px; padding-left: 19px;
}
.nav-link:hover { background: var(--color-hover); }
.nav-link.active { background: transparent; color: var(--color-primary); border-left-color: var(--color-primary); }
.nav-icon { width: 18px; height: 18px; color: var(--color-text-muted); flex-shrink: 0; }
.nav-link.active .nav-icon { color: var(--color-primary); fill: var(--color-primary); stroke: var(--color-primary); }
.nav-text { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Group Items */
.group-row { display: flex; align-items: center; gap: 8px; position: relative; }
.group-row .group-item { flex: 1; }
.group-item {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 12px; font-size: 0.875rem; color: var(--color-text);
    text-decoration: none; transition: background 0.15s;
    border-left: 3px solid transparent; margin-left: -10px; padding-left: 19px;
}
.group-item:hover { background: var(--color-hover); }
.group-avatar {
    width: 28px; height: 28px; border-radius: 6px;
    background: var(--color-primary-light); color: var(--color-primary);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem; font-weight: 600; flex-shrink: 0;
}
.group-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: var(--radius-sm); }
.group-info { flex: 1; min-width: 0; }
.group-name { font-weight: 500; font-size: 0.8125rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.group-meta { font-size: 0.7rem; color: var(--color-text-muted); }

/* Group Context Menu */
.group-menu-btn {
    display: none; align-items: center; justify-content: center;
    width: 24px; height: 24px; background: none; border: none;
    border-radius: 4px; cursor: pointer; color: var(--color-text-muted);
    flex-shrink: 0; padding: 0; position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
}
.group-row:hover .group-menu-btn, .group-menu-btn:hover, .group-menu.open ~ .group-menu-btn { display: flex; }
.group-menu {
    display: none; position: absolute; right: 8px; top: 100%;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius-sm); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    min-width: 140px; z-index: 100; padding: 4px; flex-direction: column; gap: 2px;
}
.group-menu.open { display: flex; }
.group-menu-item {
    display: flex; align-items: center; gap: 8px; padding: 8px 10px;
    font-size: 0.813rem; color: var(--color-text); text-decoration: none;
    border-radius: 4px; transition: background 0.15s;
}
.group-menu-item:hover { background: var(--color-hover); }
.group-menu-item svg { width: 16px; height: 16px; color: var(--color-text-muted); }

/* External Links */
.external-link {
    display: flex; align-items: center; gap: 10px; padding: 6px 12px;
    font-size: 0.8125rem; color: var(--color-text-muted); text-decoration: none;
    transition: background 0.15s, color 0.15s; margin-left: -10px; padding-left: 22px;
}
.external-link:hover { background: var(--color-hover); color: var(--color-text); }
.external-link svg { width: 16px; height: 16px; flex-shrink: 0; }
.external-link-icon { width: 12px; height: 12px; margin-left: auto; opacity: 0.4; flex-shrink: 0; }

.no-groups { display: block; padding: 8px 12px; font-size: 0.813rem; color: var(--color-text-muted); }

/* Mobile Overlay */
.sidebar-overlay {
    display: none; position: fixed; top: var(--topbar-height);
    left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.3); z-index: 80;
}

@media (max-width: 768px) {
    .menu-toggle { display: flex; }
    .sidebar { transform: translateX(-100%); transition: transform 0.2s ease; width: 280px; }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.open { display: block; }
}
@media (max-width: 480px) {
    .topbar { padding: 0 16px; }
    .logo-text { display: none; }
    .topbar-right { gap: 8px; }
    .topbar-right .icon-btn { display: none; }
}